UNPKG

@ycmd/creds

Version:

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

19 lines (14 loc) 2.71 kB
'use strict'; var chunkGQEZOQG6_js = require('./chunk-GQEZOQG6.js'); var chunkCSGQ5YH5_js = require('./chunk-CSGQ5YH5.js'); var err = require('@lsk4/err'); var log = require('@lsk4/log'); var m = require('axios'); var p = require('libsodium-wrappers'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var m__default = /*#__PURE__*/_interopDefault(m); var p__default = /*#__PURE__*/_interopDefault(p); var u=class extends chunkGQEZOQG6_js.a{static{chunkCSGQ5YH5_js.a(this,"GithubService");}projectName;projectPath;projectCredsUrl;projectCredsOwner;token;server;log=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.Err("!projectName");if(!this.projectPath)throw new err.Err("!projectPath");if(!this.projectCredsUrl)throw new err.Err("!projectCredsUrl");if(!this.projectCredsOwner)throw new err.Err("!projectCredsOwner");if(!this.token)throw new err.Err("!token")}createClient(t={}){let e=`https://${this.server||"api.github.com"}/repos/${this.getProjectPath()}`;return m__default.default.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.Err(c.message,{data:c?.response?.data})}),i=typeof s=="string"?s:s.value;if(!e?.key)throw new err.Err("!publicKey");if(!e?.key_id)throw new err.Err("!publicKeyId");await p__default.default.ready;let r=p__default.default,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.Err("Github hooks not supported yet")}}; exports.a = u; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-OGTRCXE5.js.map