@ycmd/creds
Version:
LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials
19 lines (14 loc) • 2.65 kB
JavaScript
;
var chunkZST2R6WT_js = require('./chunk-ZST2R6WT.js');
var chunkCSGQ5YH5_js = require('./chunk-CSGQ5YH5.js');
var err = require('@lsk4/err');
var log = require('@lsk4/log');
var w = require('axios');
var h = require('libsodium-wrappers');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var w__default = /*#__PURE__*/_interopDefault(w);
var h__default = /*#__PURE__*/_interopDefault(h);
var p=class extends chunkZST2R6WT_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 o=`https://${this.server||"api.github.com"}/repos/${this.getProjectPath()}`;return w__default.default.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.Err(i.message,{data:i?.response?.data})});if(!o?.key)throw new err.Err("!publicKey");if(!o?.key_id)throw new err.Err("!publicKeyId");await h__default.default.ready;let e=h__default.default,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.Err("Github hooks not supported yet")}};
exports.a = p;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-WNARQRHV.js.map