UNPKG

@ycmd/creds

Version:

LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials

139 lines (137 loc) 4.3 kB
import { __name } from './chunk-U2DZE3DI.js'; import { Err } from '@lsk4/err'; import { createLogger } from '@lsk4/log'; import axios from 'axios'; import { map } from 'fishbird'; var Service = class { static { __name(this, "Service"); } client; log = createLogger(this.constructor.name); constructor(options) { this.assign(options); this.checkConfig(); this.client = this.createClient(options.clientOptions); } createClient(clientOptions = {}) { return axios.create(clientOptions); } assign(options) { Object.assign(this, options); } checkConfig() { throw new Err("NOT_IMPLEMENTED", "checkConfig method not implemented"); } getServiceHostname() { throw new Err("NOT_IMPLEMENTED", "getServiceHostname method not implemented"); } getProjectUrl() { throw new Err("NOT_IMPLEMENTED", "getProjectUrl method not implemented"); } getProjectCICDSettingURL() { throw new Err("NOT_IMPLEMENTED", "getProjectCICDSettingURL method not implemented"); } getProjectPath() { const value = this.projectPath; if (!value) throw new Err("!projectPath"); return value; } getProjectId() { const value = this.projectId; return value; } getProjectCredsUrl() { const value = this.projectCredsUrl; if (!value) throw new Err("!projectCredsUrl"); return value; } getProjectCredsOwner() { const value = this.projectCredsOwner; if (!value) throw new Err("!projectCredsOwner"); return value; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async uploadSecret(key, content) { throw new Err("NOT_IMPLEMENTED", "uploadSecret method not implemented"); } // eslint-disable-next-line @typescript-eslint/no-unused-vars async uploadVariable(key, content) { throw new Err("NOT_IMPLEMENTED", "uploadVariable method not implemented"); } async removeOldHooks() { } // eslint-disable-next-line @typescript-eslint/no-unused-vars async uploadHook(dataHook) { } async uploadHooks(env) { if (!env) throw new Err("!env"); const { hooks = [] } = env; try { await this.removeOldHooks(); } catch (err) { this.log.error(`[ERR] Old hooks removing failed:`, Err.getMessage(err)); } await map(hooks, async (dataHook, index) => { try { await this.uploadHook(dataHook); this.log.info(`[OK] Hook ${index} uploaded`); } catch (err) { this.log.error(`[ERR] Hook ${index} not uploaded:`, Err.getMessage(err)); } }); } async uploadAll(env) { if (!env) throw new Err("!env"); const { CredsCiConfig = {}, variables = {}, files = [] } = env; await this.uploadHooks(env); await map(Object.entries(CredsCiConfig), async ([key, value]) => { try { await this.uploadSecret(key, value); this.log.info(`[OK] Secret ${key} uploaded`); } catch (err) { this.log.error(`[ERR] Secret ${key} not uploaded as secret, because`, Err.getMessage(err)); this.log.trace(err); } }); await map(Object.entries(variables), async ([key, value]) => { try { await this.uploadVariable(key, value); this.log.info(`[OK] Variable ${key} uploaded`); } catch (err) { this.log.error(`[ERR] Variable ${key} not uploaded as variable, because`, Err.getMessage(err)); this.log.trace(err); } }); await map(files, async ({ name, credType, content }) => { const key = name; const value = content; try { if (credType === "variable") { await this.uploadVariable(key, value); } else if (credType === "secret") { await this.uploadSecret(key, value); } else if (credType === "skip") { this.log.debug(`[SKIP] File ${key} uploaded as ${credType}`); return; } else { throw new Err("unknown credType", { credType }); } this.log.info(`[OK] File ${key} uploaded as ${credType}`); } catch (err) { this.log.error(`[ERR] File ${key} not uploaded as ${credType}, because`, Err.getMessage(err)); this.log.trace(err); } }); } }; export { Service }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-SWCVOLVG.js.map