UNPKG

@ycmd/creds

Version:

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

12 lines (10 loc) 2.28 kB
import { a } from './chunk-ZST2R6WT.js'; import { a as a$1 } from './chunk-CSGQ5YH5.js'; import { Err } from '@lsk4/err'; import { createLogger } from '@lsk4/log'; import d from 'axios'; import { map } from 'fishbird'; var s=!0,h=class extends a{static{a$1(this,"GitlabService");}projectId;projectName;projectPath;projectCredsUrl;projectCredsOwner;token;server;force=!0;log=createLogger(this.constructor.name);constructor(t){super(t),this.assign(t),this.checkConfig(),this.client=this.createClient(t.clientOptions);}checkConfig(){if(!this.projectId)throw new Err("!projectId");if(!this.server)throw new Err("!server");if(!this.projectName)throw new Err("!projectName");if(!this.projectPath)throw new Err("!projectPath");if(!this.projectCredsUrl)throw new Err("!projectCredsUrl");if(!this.projectCredsOwner)throw new Err("!projectCredsOwner");if(!this.token)throw new Err("!token")}createClient(t={}){return d.create({baseURL:`https://${this.server}/api/v4/projects/${this.projectId}`,headers:{"PRIVATE-TOKEN":this.token},...t})}getServiceHostname(){return this.server}getProjectUrl(){return `https://${this.getServiceHostname()}/${this.projectPath}`}getProjectCICDSettingURL(){return `${this.getProjectUrl()}/-/settings/ci_cd`}async uploadSecret(t,r,o={}){let{data:a}=await this.client({method:"get",url:`/variables/${t}`}).catch(n=>{return {data:{value:"@lskjs/creds"}}});if(a.value&&a.value.indexOf("@lskjs/creds")===-1&&!s){this.log.warn(`[IGNORE] Project ${this.projectId} ${t}`);return}await this.client({method:"delete",url:`/variables/${t}`}).catch(()=>{}),await this.client({method:"post",url:"/variables",data:{key:t,variable_type:"file",value:r,protected:!0,...o}});}async uploadVariable(t,r,o={}){this.uploadSecret(t,r,{variable_type:"env_var",protected:!!o.protected});}async uploadEnv(){throw this.log.warn("GitLab uploading env doesn't supported"),new Err("NOT_IMPLEMENTED")}async removeOldHooks(){let{data:t}=await this.client({method:"get",url:"/hooks"}).catch(r=>{return {data:{value:"@lskjs/creds"}}});await map(t,async({id:r})=>{await this.client({method:"delete",url:`/hooks/${r}`});});}async uploadHook(t){await this.client({method:"post",url:"/hooks",data:t});}}; export { h as a }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-BOQRWMR4.js.map