Skip to content
Snippets Groups Projects
Commit f582a479 authored by michael.minelli's avatar michael.minelli
Browse files

Merge branch 'store_token_for_different_env' into v2.2.0

parents b98af2b8 902475e1
No related branches found
No related tags found
No related merge requests found
Pipeline #26545 passed
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
### 🎨 Interface ### 🎨 Interface
- The gitlab token can be passed as secret user input in addition to the command line. - The gitlab token can be passed as secret user input in addition to the command line.
### 🔨 Internal / Developers
- Environment support added to CLI config file
### 📚 Documentation ### 📚 Documentation
- Wiki update for this new version - Wiki update for this new version
......
import * as fs from 'fs'; import * as fs from 'fs';
import logger from '../shared/logging/WinstonLogger';
import SessionManager from '../managers/SessionManager'; import SessionManager from '../managers/SessionManager';
import Config from './Config'; import Config from './Config';
import LocalConfigKeys from '../types/LocalConfigKeys'; import LocalConfigKeys from '../types/LocalConfigKeys';
import GitlabManager from '../managers/GitlabManager'; import GitlabManager from '../managers/GitlabManager';
import JSON5 from 'json5'; import JSON5 from 'json5';
import ClientsSharedConfig from '../sharedByClients/config/ClientsSharedConfig';
class LocalConfig { class LocalConfig {
...@@ -24,23 +24,43 @@ class LocalConfig { ...@@ -24,23 +24,43 @@ class LocalConfig {
try { try {
this._config = JSON5.parse(fs.readFileSync(this.configPath).toString()); this._config = JSON5.parse(fs.readFileSync(this.configPath).toString());
SessionManager.token = this._config.apiToken; if ( LocalConfigKeys.API_TOKEN_ENV in this._config && ClientsSharedConfig.apiURL in this._config[LocalConfigKeys.API_TOKEN_ENV] ) {
GitlabManager.token = this._config.gitlabPersonalToken; SessionManager.token = this._config[LocalConfigKeys.API_TOKEN_ENV][ClientsSharedConfig.apiURL];
} catch ( error ) { } } else {
SessionManager.token = this._config[LocalConfigKeys.API_TOKEN];
}
GitlabManager.token = this._config[LocalConfigKeys.GITLAB_PERSONAL_TOKEN];
} catch ( error ) {
console.log(error);
}
} }
updateConfig(key: LocalConfigKeys, value: any) { updateConfig(key: LocalConfigKeys, value: any) {
if ( (this._config as any)[key] === value ) { let previousValue = (this._config as any)[key];
if ( key === LocalConfigKeys.API_TOKEN && (!(LocalConfigKeys.API_TOKEN_ENV in this._config) || !(ClientsSharedConfig.apiURL in this._config[LocalConfigKeys.API_TOKEN_ENV])) ) {
previousValue = null;
}
if ( previousValue === value ) {
return; return;
} }
if ( key === LocalConfigKeys.API_TOKEN ) {
delete (this._config as any)[LocalConfigKeys.API_TOKEN];
if ( !(LocalConfigKeys.API_TOKEN_ENV in this._config) ) {
(this._config as any)[LocalConfigKeys.API_TOKEN_ENV] = {};
}
(this._config as any)[LocalConfigKeys.API_TOKEN_ENV][ClientsSharedConfig.apiURL] = value;
} else {
(this._config as any)[key] = value; (this._config as any)[key] = value;
}
try { try {
fs.writeFileSync(this.configPath, JSON5.stringify(this._config, null, 4)); fs.writeFileSync(this.configPath, JSON5.stringify(this._config, null, 4));
} catch ( error ) { } catch ( error ) { }
logger.error(error);
}
} }
} }
......
enum LocalConfigKeys { enum LocalConfigKeys {
API_TOKEN = 'apiToken', API_TOKEN = 'apiToken',
API_TOKEN_ENV = 'apiTokenEnv',
GITLAB_PERSONAL_TOKEN = 'gitlabPersonalToken', GITLAB_PERSONAL_TOKEN = 'gitlabPersonalToken',
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment