Skip to content

Commit

Permalink
adding config file to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ooemperor committed Nov 21, 2024
1 parent db6015c commit c00478d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Sample Environment Variables File
REACT_APP_PROXMOX_API=<URL>
REACT_APP_PROXMOX_API_KEY=<STRING>
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
.env.development.local
.env.test.local
.env.production.local
.sec.json
*.sec.json

npm-debug.log*
yarn-debug.log*
Expand Down
25 changes: 25 additions & 0 deletions src/Config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Config file for the Dashboard project
* Reads the config out of the .env file
* @author ooemperor
*/
import configData from "./config.sec.json"

/**
* Class for the config object used in total
*/
export class Config{
proxmoxApi: string;
proxmoxApiKey: string;

/**
* Constructor of the config
*/
constructor() {

this.proxmoxApi = configData.proxmox.api;
this.proxmoxApiKey = configData.proxmox.apiKey;
}
}

export const config = new Config();
6 changes: 6 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"proxmox":{
"api": "",
"apiKey": ""
}
}
5 changes: 3 additions & 2 deletions src/services/ProxmoxService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author ooemperor
*/
import {NodesResponse} from "../models/proxmox/Node";
import {config} from "../Config";

class ProxmoxService {
apiToken: string;
Expand All @@ -30,7 +31,7 @@ class ProxmoxService {
try {
const response: Response = await fetch(`${this.baseUrl}/api2/json/nodes`, {
method: 'GET',
headers: {'Content-Type': 'application/json', 'Authorization': this.apiToken},
headers: {'Content-Type': 'application/json', 'Authorization': this.apiToken || ""},
});

if (!response.ok) {
Expand All @@ -47,4 +48,4 @@ class ProxmoxService {
}
}

export const proxmoxService = new ProxmoxService("", ""); //TODO: Change to correct config params
export const proxmoxService = new ProxmoxService(config.proxmoxApiKey, config.proxmoxApi);

0 comments on commit c00478d

Please sign in to comment.