diff --git a/NodeApp/src/commander/CommanderApp.ts b/NodeApp/src/commander/CommanderApp.ts index 8fad32ae891aaca66f2bf1471671110bf9e7078a..d7558e995e4c24844807ba90342a22d4b8f21183 100644 --- a/NodeApp/src/commander/CommanderApp.ts +++ b/NodeApp/src/commander/CommanderApp.ts @@ -1,8 +1,8 @@ -import { Command } from 'commander'; -import Config from '../config/Config'; -import EnonceCommand from './enonce/EnonceCommand'; -import SessionCommand from './session/SessionCommand'; -import ExerciceCommand from './exercice/ExerciceCommand'; +import { Command } from 'commander'; +import EnonceCommand from './enonce/EnonceCommand'; +import SessionCommand from './session/SessionCommand'; +import ExerciceCommand from './exercice/ExerciceCommand'; +import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; class CommanderApp { @@ -19,10 +19,10 @@ class CommanderApp { sortOptions : true, sortSubcommands : true }) - .option('-H, --host <string>', 'override the Dojo API endpoint', Config.apiURL); + .option('-H, --host <string>', 'override the Dojo API endpoint', ClientsSharedConfig.apiURL); this.program.on('option:host', () => { - Config.apiURL = this.program.opts().host; + ClientsSharedConfig.apiURL = this.program.opts().host; }); this.registerCommands(); diff --git a/NodeApp/src/config/Config.ts b/NodeApp/src/config/Config.ts index f65322a3daaa6470daad131de071d326f8a17ca9..f19ec8d135dbfbadcb1a8455fe01413bb0bd4206 100644 --- a/NodeApp/src/config/Config.ts +++ b/NodeApp/src/config/Config.ts @@ -2,28 +2,11 @@ import getAppDataPath from 'appdata-path'; class Config { - public apiURL: string; - - public gitlab: { - apiURL: string - dojoAccount: { id: number; username: string; }; - }; - public readonly localConfig: { folder: string; file: string; }; constructor() { - this.apiURL = process.env.API_URL || ''; - - this.gitlab = { - apiURL : process.env.GITLAB_API_URL || '', - dojoAccount: { - id : Number(process.env.GITLAB_DOJO_ACCOUNT_ID) || -1, - username: process.env.GITLAB_DOJO_ACCOUNT_USERNAME || '' - } - }; - this.localConfig = { folder: getAppDataPath('DojoCLI'), file : process.env.LOCAL_CONFIG_FILE || '' diff --git a/NodeApp/src/managers/DojoBackendManager.ts b/NodeApp/src/managers/DojoBackendManager.ts index ce05f433df84c43c071a3ecf4fe93d355a5588d0..4a538e1a04dc6ce28e4cec3614cdd744c5004fdd 100644 --- a/NodeApp/src/managers/DojoBackendManager.ts +++ b/NodeApp/src/managers/DojoBackendManager.ts @@ -1,5 +1,4 @@ import axios, { AxiosError } from 'axios'; -import Config from '../config/Config'; import ora from 'ora'; import ApiRoutes from '../sharedByClients/types/ApiRoutes'; import { StatusCodes } from 'http-status-codes'; @@ -7,11 +6,12 @@ import Enonce from '../sharedByClients/models/Enonce'; import GitlabUser from '../shared/types/Gitlab/GitlabUser'; import Exercice from '../sharedByClients/models/Exercice'; import DojoResponse from '../shared/types/DojoResponse'; +import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; class DojoBackendManager { public getApiUrl(route: ApiRoutes): string { - return `${ Config.apiURL }${ route }`; + return `${ ClientsSharedConfig.apiURL }${ route }`; } public async getEnonce(nameOrUrl: string): Promise<Enonce | undefined> { @@ -43,9 +43,9 @@ class DojoBackendManager { if ( error instanceof AxiosError ) { if ( error.response ) { if ( error.response.status === StatusCodes.NOT_FOUND ) { - spinner.fail(`Template not found or access denied. Please check the template ID or url. Also, please check that the template have public/internal visibility or that your and Dojo account (${ Config.gitlab.dojoAccount.username }) have at least reporter role to the template (if private).`); + spinner.fail(`Template not found or access denied. Please check the template ID or url. Also, please check that the template have public/internal visibility or that your and Dojo account (${ ClientsSharedConfig.gitlab.dojoAccount.username }) have at least reporter role to the template (if private).`); } else if ( error.response.status === StatusCodes.UNAUTHORIZED ) { - spinner.fail(`Please check that the template have public/internal visibility or that your and Dojo account (${ Config.gitlab.dojoAccount.username }) have at least reporter role to the template (if private).`); + spinner.fail(`Please check that the template have public/internal visibility or that your and Dojo account (${ ClientsSharedConfig.gitlab.dojoAccount.username }) have at least reporter role to the template (if private).`); } else { spinner.fail(`Template error: ${ error.response.statusText }`); } diff --git a/NodeApp/src/managers/GitlabManager.ts b/NodeApp/src/managers/GitlabManager.ts index b2d71c728d2a93e05288da70cd295949ff15677b..9f00a2e8ad5ee65e947f2232147e158f3a2a5af9 100644 --- a/NodeApp/src/managers/GitlabManager.ts +++ b/NodeApp/src/managers/GitlabManager.ts @@ -1,17 +1,17 @@ -import LocalConfig from '../config/LocalConfig'; -import LocalConfigKeys from '../types/LocalConfigKeys'; -import axios from 'axios'; -import Config from '../config/Config'; -import ora from 'ora'; -import GitlabUser from '../shared/types/Gitlab/GitlabUser'; -import GitlabRoutes from '../shared/types/Gitlab/GitlabRoutes'; +import LocalConfig from '../config/LocalConfig'; +import LocalConfigKeys from '../types/LocalConfigKeys'; +import axios from 'axios'; +import ora from 'ora'; +import GitlabUser from '../shared/types/Gitlab/GitlabUser'; +import GitlabRoutes from '../shared/types/Gitlab/GitlabRoutes'; +import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; class GitlabManager { private _token: string | null = null; private getApiUrl(route: GitlabRoutes): string { - return `${ Config.gitlab.apiURL }${ route }`; + return `${ ClientsSharedConfig.gitlab.apiURL }${ route }`; } get isLogged(): boolean { diff --git a/NodeApp/src/managers/HttpManager.ts b/NodeApp/src/managers/HttpManager.ts index a8e0de677a397ae5570d689ae4c9300a0ba19362..10c8bfebafd99aae9f2cc5bac1b54762883f9465 100644 --- a/NodeApp/src/managers/HttpManager.ts +++ b/NodeApp/src/managers/HttpManager.ts @@ -1,10 +1,10 @@ import axios, { AxiosRequestHeaders } from 'axios'; -import Config from '../config/Config'; import SessionManager from './SessionManager'; import FormData from 'form-data'; import logger from '../shared/logging/WinstonLogger'; import GitlabManager from './GitlabManager'; import { StatusCodes } from 'http-status-codes'; +import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig'; class HttpManager { @@ -21,7 +21,7 @@ class HttpManager { config.headers = { ...config.headers, ...(config.data as FormData).getHeaders() } as AxiosRequestHeaders; } - if ( config.url && (config.url.indexOf(Config.apiURL) !== -1) ) { + if ( config.url && (config.url.indexOf(ClientsSharedConfig.apiURL) !== -1) ) { if ( config.data && Object.keys(config.data).length > 0 ) { config.headers['Content-Type'] = 'multipart/form-data'; } @@ -31,7 +31,7 @@ class HttpManager { } } - if ( GitlabManager.isLogged && config.url && config.url.indexOf(Config.gitlab.apiURL) !== -1 ) { + if ( GitlabManager.isLogged && config.url && config.url.indexOf(ClientsSharedConfig.gitlab.apiURL) !== -1 ) { config.headers['PRIVATE-TOKEN'] = GitlabManager.token; } @@ -49,7 +49,7 @@ class HttpManager { }, (error) => { if ( error.response ) { if ( this.handleCommandErrors ) { - if ( error.response.url && error.response.url.indexOf(Config.apiURL) !== -1 ) { + if ( error.response.url && error.response.url.indexOf(ClientsSharedConfig.apiURL) !== -1 ) { switch ( error.response.status ) { case StatusCodes.UNAUTHORIZED: // Unauthorized logger.error('Session expired or inexistent. Please login again.'); diff --git a/NodeApp/src/sharedByClients b/NodeApp/src/sharedByClients index 3cd4b0c0e18fb8e8f52062cf4b171c8c67d4baea..8fe8e9417a527cf2182a9acc440e68b99024487e 160000 --- a/NodeApp/src/sharedByClients +++ b/NodeApp/src/sharedByClients @@ -1 +1 @@ -Subproject commit 3cd4b0c0e18fb8e8f52062cf4b171c8c67d4baea +Subproject commit 8fe8e9417a527cf2182a9acc440e68b99024487e