UNPKG

@ycmd/creds

Version:

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

118 lines (113 loc) 3 kB
'use strict'; var chunkEVPQ7GSQ_js = require('./chunk-EVPQ7GSQ.js'); var chunkU2DZE3DI_js = require('./chunk-U2DZE3DI.js'); var err = require('@lsk4/err'); var log = require('@lsk4/log'); var axios = require('axios'); var fishbird = require('fishbird'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var axios__default = /*#__PURE__*/_interopDefault(axios); var GitlabService = class extends chunkEVPQ7GSQ_js.Service { static { chunkU2DZE3DI_js.__name(this, "GitlabService"); } log = log.createLogger(this.constructor.name); checkConfig() { super.checkConfig(); if (!this.projectId) throw new err.Err("!projectId"); if (!this.server) throw new err.Err("!server"); if (!this.token) throw new err.Err("!token"); } createClient(options) { return axios__default.default.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.Err("NOT_IMPLEMENTED"); } async uploadEnv() { this.log.warn("GitLab uploading env doesn't supported"); throw new err.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 fishbird.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 }); } }; exports.GitlabService = GitlabService; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-FIS3MTUV.js.map