move source files to src folder,
move localdb to config folder, consolidate vars.js with localdb, move service scripts to service folder
This commit is contained in:
parent
0043e3e783
commit
a807e5cb03
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
**/package-lock.json
|
||||
**/node_modules
|
||||
**/vars.js
|
||||
**/localdb.json
|
@ -22,13 +22,14 @@ In Proxmox VE, follow the following steps:
|
||||
## Installation - API
|
||||
1. Clone this repo onto `Client Host`
|
||||
2. Run `npm install` to initiaze the package requirements
|
||||
3. Copy `vars.js.template` as `vars.js` and modify the following values:
|
||||
3. Copy `localdb.json.template` as `localdb.json` and modify the following values:
|
||||
- pveAPI - the URI to the Proxmox API, ie `<proxmoxhost>:8006/api2/json` or `<proxmox URL>/api2/json` if Proxmox VE is behind a reverse proxy.
|
||||
- hostname - the ProxmoxAAS-Client URL, ie `host.domain.tld`
|
||||
- domain - the base domain for the client and proxmox, ie `domain.tld`
|
||||
- listenPort - the port you want the API to listen on, ie `8080`
|
||||
- pveAPIToken - the user(name), authentication realm, token id, and token secrey key (uuid)
|
||||
4. Start the service using `node .`, or call the provided shell script, or use the provided systemctl service script
|
||||
4. You may also wish to confuigure users at this point as well. An example user config is shown in the template.
|
||||
5. Start the service using `node .`, or call the provided shell script, or use the provided systemctl service script
|
||||
|
||||
## Installation - Reverse Proxy
|
||||
1. Configure nginx or preferred reverse proxy to reverse proxy the client. The configuration should include at least the following:
|
||||
@ -47,4 +48,4 @@ server {
|
||||
2. Start nginx with the new configurations by running `systemctl reload nginx`
|
||||
|
||||
## Result
|
||||
After these steps, the ProxmoxAAS Client should be avaliable and fully functional at `client.<FQDN>`.
|
||||
After these steps, the ProxmoxAAS Client should be avaliable and fully functional at `client.<FQDN>`.
|
@ -1,4 +1,16 @@
|
||||
{
|
||||
"application": {
|
||||
"pveAPI": "https://pve.mydomain/api2/json",
|
||||
"pveAPIToken": {
|
||||
"user": "proxmoxaas-api",
|
||||
"realm": "pve",
|
||||
"id": "token",
|
||||
"uuid": "secret-key"
|
||||
},
|
||||
"listenPort": 80,
|
||||
"hostname": "client.mydomain",
|
||||
"domain": "mydomain"
|
||||
},
|
||||
"resources": {
|
||||
"cores": {
|
||||
"type": "numeric",
|
35
db.js
35
db.js
@ -1,35 +0,0 @@
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
|
||||
class localdb {
|
||||
#template = "localdb.json.template";
|
||||
#filename = "localdb.json";
|
||||
#data = null;
|
||||
constructor() {
|
||||
try {
|
||||
this.load(this.#filename);
|
||||
}
|
||||
catch {
|
||||
this.load(this.#template);
|
||||
this.save(this.#filename);
|
||||
}
|
||||
}
|
||||
load(path) {
|
||||
this.#data = JSON.parse(readFileSync(path));
|
||||
}
|
||||
save(path) {
|
||||
writeFileSync(path, JSON.stringify(this.#data));
|
||||
}
|
||||
getResourceConfig() {
|
||||
return this.#data.resources;
|
||||
}
|
||||
getUserConfig(username) {
|
||||
if (this.#data.users[username]) {
|
||||
return this.#data.users[username];
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const db = new localdb();
|
@ -2,7 +2,7 @@
|
||||
"name": "proxmoxaas-api",
|
||||
"version": "0.0.1",
|
||||
"description": "REST API for ProxmoxAAS",
|
||||
"main": "main.js",
|
||||
"main": "src/main.js",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"axios": "^1.3.2",
|
||||
|
43
src/db.js
Normal file
43
src/db.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { exit } from "process";
|
||||
|
||||
class localdb {
|
||||
#filename = "config/localdb.json";
|
||||
#data = null;
|
||||
constructor() {
|
||||
try {
|
||||
this.load(this.#filename);
|
||||
}
|
||||
catch {
|
||||
console.log("Error: localdb.json was not found. Please follow the directions in the README to initialize localdb.json.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
load(path) {
|
||||
this.#data = JSON.parse(readFileSync(path));
|
||||
}
|
||||
save(path) {
|
||||
writeFileSync(path, JSON.stringify(this.#data));
|
||||
}
|
||||
getApplicationConfig() {
|
||||
return this.#data.application;
|
||||
}
|
||||
getResourceConfig() {
|
||||
return this.#data.resources;
|
||||
}
|
||||
getUserConfig(username) {
|
||||
if (this.#data.users[username]) {
|
||||
return this.#data.users[username];
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const db = new localdb();
|
||||
export const pveAPI = db.getApplicationConfig().pveAPI;
|
||||
export const pveAPIToken = db.getApplicationConfig().pveAPIToken;
|
||||
export const listenPort = db.getApplicationConfig().listenPort;
|
||||
export const hostname = db.getApplicationConfig().hostname;
|
||||
export const domain = db.getApplicationConfig().domain;
|
@ -3,12 +3,11 @@ import bodyParser from "body-parser";
|
||||
import cookieParser from "cookie-parser";
|
||||
import cors from "cors";
|
||||
import morgan from "morgan";
|
||||
import api from "./package.json" assert {type: "json"};
|
||||
import api from "../package.json" assert {type: "json"};
|
||||
|
||||
import { pveAPIToken, listenPort, hostname, domain } from "./vars.js";
|
||||
import { requestPVE, handleResponse, getDiskInfo } from "./pve.js";
|
||||
import { checkAuth, approveResources, getUserResources } from "./utils.js";
|
||||
import { db } from "./db.js";
|
||||
import { db, pveAPIToken, listenPort, hostname, domain } from "./db.js";
|
||||
|
||||
const app = express();
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
@ -1,5 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import { pveAPI, pveAPIToken } from "./vars.js";
|
||||
import { pveAPI, pveAPIToken } from "./db.js";
|
||||
|
||||
export async function requestPVE(path, method, cookies, body = null, token = null) {
|
||||
let url = `${pveAPI}${path}`;
|
@ -1,10 +0,0 @@
|
||||
export const pveAPI = "";
|
||||
export const pveAPIToken = {
|
||||
user: "",
|
||||
realm: "",
|
||||
id: "",
|
||||
uuid: ""
|
||||
};
|
||||
export const listenPort = 80;
|
||||
export const hostname = "";
|
||||
export const domain = "";
|
Loading…
Reference in New Issue
Block a user