UNPKG

@ycmd/creds

Version:

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

12 lines (10 loc) 1.96 kB
import { a } from './chunk-B4XXL2LI.js'; import { a as a$1 } from './chunk-CSGQ5YH5.js'; import { Err } from '@lsk4/err'; import { createLogger } from '@lsk4/log'; import w from 'axios'; import h from 'libsodium-wrappers'; var p=class extends a{static{a$1(this,"GithubService");}log=createLogger(this.constructor.name);checkConfig(){if(super.checkConfig(),!this.projectId)throw new Err("!projectId");if(!this.server)throw new Err("!server");if(!this.token)throw new Err("!token")}createClient(t){let a=`https://${this.server||"api.github.com"}/repos/${this.getProjectPath()}`;return w.create({baseURL:a,headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${this.token}`,"X-GitHub-Api-Version":"2022-11-28"},...t})}getServiceLink(){return "github.com"}getProjectUrl(){return `https://${this.getServiceLink()}/${this.projectName}`}getProjectCICDSettingURL(){return `${this.getProjectUrl()}/settings/secrets/actions`}async uploadSecret(t,o){let{data:a}=await this.client({method:"get",url:"/actions/secrets/public-key"}).catch(i=>{throw new Err(i.message,{data:i?.response?.data})});if(!a?.key)throw new Err("!publicKey");if(!a?.key_id)throw new Err("!publicKeyId");await h.ready;let e=h,s=e.from_base64(a.key,e.base64_variants.ORIGINAL),u=e.from_string(o),l=e.crypto_box_seal(u,s),d=e.to_base64(l,e.base64_variants.ORIGINAL);await this.client({method:"put",url:`/actions/secrets/${t}`,data:{encrypted_value:d,key_id:a.key_id}});}async uploadVariable(t,o){let{data:a,status:e}=await this.client({method:"get",url:`/actions/variables/${t}`}).catch(s=>s?.response);e===404&&await this.client({method:"post",url:"/actions/variables",data:{name:t,value:o}}),e===200&&a.name.toLowerCase()===t.toLowerCase()&&await this.client({method:"patch",url:`/actions/variables/${t}`,data:{name:t,value:o}});}uploadHook(){throw new Err("Github hooks not supported yet")}}; export { p as a }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-GTIYM2EM.js.map