UNPKG

@ycmd/creds

Version:

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

112 lines (110 loc) 2.73 kB
import { Service } from './chunk-SDMJ4Z2K.js'; import { __name } from './chunk-POLJ2ZZ2.js'; import { Err } from '@lsk4/err'; import { createLogger } from '@lsk4/log'; import axios from 'axios'; import { map } from 'fishbird'; var GitlabService = class extends Service { static { __name(this, "GitlabService"); } log = createLogger(this.constructor.name); checkConfig() { super.checkConfig(); if (!this.projectId) throw new Err("!projectId"); if (!this.server) throw new Err("!server"); if (!this.token) throw new Err("!token"); } createClient(options) { return axios.create({ baseURL: `https://${this.server}/api/v4/projects/${this.getProjectId()}`, headers: { "PRIVATE-TOKEN": this.token }, ...options }); } getServiceLink() { return this.server; } getProjectUrl() { return `https://${this.getServiceLink()}/${this.getProjectPath()}`; } getProjectCICDSettingURL() { return `${this.getProjectUrl()}/-/settings/ci_cd`; } async uploadSecret(key, content) { const { data: varData } = await this.client({ method: "get", url: `/variables/${key}` }).catch((err) => { if (!this.force) throw err; return { data: { value: "@lskjs/creds" } }; }); if (varData.value && varData.value.indexOf("@lskjs/creds") === -1 && !this.force) { this.log.warn(`[IGNORE] Project ${this.projectId} ${key}`); return; } await this.client({ method: "delete", url: `/variables/${key}` }).catch(() => { }); await this.client({ method: "post", url: "/variables", data: { key, variable_type: "file", value: content, protected: true } }); } async uploadVariable() { this.log.warn("GitLab uploading variable doesn't supported"); throw new Err("NOT_IMPLEMENTED"); } async uploadEnv() { this.log.warn("GitLab uploading env doesn't supported"); throw new Err("NOT_IMPLEMENTED"); } async removeOldHooks() { const { data: hooksList } = await this.client({ method: "get", url: `/hooks` }).catch((err) => { if (!this.force) throw err; return { data: { value: "@lskjs/creds" } }; }); await map(hooksList, async ({ id: hookId }) => { await this.client({ method: "delete", url: `/hooks/${hookId}` }); }); } async uploadHook(hook) { await this.client({ method: "post", url: "/hooks", data: hook }); } }; export { GitlabService }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-OOLDTK3O.js.map