@ycmd/creds
Version:
LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials
12 lines (10 loc) • 2.31 kB
JavaScript
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 w from 'axios';
import h from 'libsodium-wrappers';
var p=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 o=`https://${this.server||"api.github.com"}/repos/${this.getProjectPath()}`;return w.create({baseURL:o,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:o}=await this.client({method:"get",url:"/actions/secrets/public-key"}).catch(i=>{throw new Err(i.message,{data:i?.response?.data})});if(!o?.key)throw new Err("!publicKey");if(!o?.key_id)throw new Err("!publicKeyId");await h.ready;let e=h,a=e.from_base64(o.key,e.base64_variants.ORIGINAL),l=e.from_string(s),u=e.crypto_box_seal(l,a),d=e.to_base64(u,e.base64_variants.ORIGINAL);await this.client({method:"put",url:`/actions/secrets/${t}`,data:{encrypted_value:d,key_id:o.key_id}});}async uploadVariable(t,s){let{data:o,status:e}=await this.client({method:"get",url:`/actions/variables/${t}`}).catch(a=>a?.response);e===404&&await this.client({method:"post",url:"/actions/variables",data:{name:t,value:s}}),e===200&&o.name.toLowerCase()===t.toLowerCase()&&await this.client({method:"patch",url:`/actions/variables/${t}`,data:{name:t,value:s}});}uploadHook(){throw new Err("Github hooks not supported yet")}};
export { p as a };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-WNARQRHV.js.map