@ycmd/creds
Version:
LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials
12 lines (10 loc) • 2.38 kB
JavaScript
import { a } from './chunk-GQEZOQG6.js';
import { a as a$1 } from './chunk-CSGQ5YH5.js';
import { Err } from '@lsk4/err';
import { createLogger } from '@lsk4/log';
import m from 'axios';
import p from 'libsodium-wrappers';
var u=class extends a{static{a$1(this,"GithubService");}projectName;projectPath;projectCredsUrl;projectCredsOwner;token;server;log=createLogger(this.constructor.name);constructor(t){super(t),this.assign(t),this.checkConfig(),this.client=this.createClient(t.clientOptions);}checkConfig(){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={}){let e=`https://${this.server||"api.github.com"}/repos/${this.getProjectPath()}`;return m.create({baseURL:e,headers:{Accept:"application/vnd.github+json",Authorization:`Bearer ${this.token}`,"X-GitHub-Api-Version":"2022-11-28"},...t})}getServiceHostname(){return "github.com"}getProjectPath(){return this.projectPath}getProjectUrl(){return `https://${this.getServiceHostname()}/${this.getProjectPath()}`}getProjectCICDSettingURL(){return `${this.getProjectUrl()}/settings/secrets/actions`}async uploadSecret(t,s){let{data:e}=await this.client({method:"get",url:"/actions/secrets/public-key"}).catch(c=>{throw new Err(c.message,{data:c?.response?.data})}),i=typeof s=="string"?s:s.value;if(!e?.key)throw new Err("!publicKey");if(!e?.key_id)throw new Err("!publicKeyId");await p.ready;let r=p,a=r.from_base64(e.key,r.base64_variants.ORIGINAL),l=r.from_string(i),d=r.crypto_box_seal(l,a),w=r.to_base64(d,r.base64_variants.ORIGINAL);await this.client({method:"put",url:`/actions/secrets/${t}`,data:{encrypted_value:w,key_id:e.key_id}});}async uploadVariable(t,s){let e=typeof s=="string"?s:s.value,{data:i,status:r}=await this.client({method:"get",url:`/actions/variables/${t}`}).catch(a=>a?.response);r===404&&await this.client({method:"post",url:"/actions/variables",data:{name:t,value:e}}),r===200&&i.name.toLowerCase()===t.toLowerCase()&&await this.client({method:"patch",url:`/actions/variables/${t}`,data:{name:t,value:e}});}uploadHook(){throw new Err("Github hooks not supported yet")}};
export { u as a };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-OGTRCXE5.js.map