@ks-opdev/cli
Version:
ksodev: A CLI based on the WPS Open Platform
1 lines • 8.45 kB
JavaScript
const a19_0x36c402=a19_0x34a3;(function(_0x56eeb8,_0x4f954c){const _0x5a5b6d=a19_0x34a3,_0x45759b=_0x56eeb8();while(!![]){try{const _0x1348cc=-parseInt(_0x5a5b6d(0x187))/0x1+-parseInt(_0x5a5b6d(0x184))/0x2+parseInt(_0x5a5b6d(0x18b))/0x3*(parseInt(_0x5a5b6d(0x17d))/0x4)+parseInt(_0x5a5b6d(0x15d))/0x5*(-parseInt(_0x5a5b6d(0x196))/0x6)+parseInt(_0x5a5b6d(0x16f))/0x7*(parseInt(_0x5a5b6d(0x161))/0x8)+-parseInt(_0x5a5b6d(0x17f))/0x9+-parseInt(_0x5a5b6d(0x179))/0xa*(-parseInt(_0x5a5b6d(0x16d))/0xb);if(_0x1348cc===_0x4f954c)break;else _0x45759b['push'](_0x45759b['shift']());}catch(_0xf8f6bc){_0x45759b['push'](_0x45759b['shift']());}}}(a19_0xb40d,0xf09aa));import{existsSync,mkdirSync,readFileSync,writeFileSync}from'node:fs';import{homedir}from'node:os';import{dirname,join}from'node:path';import{DEFAULT_CONFIG}from'../config/constants.js';export class ConfigManager{static [a19_0x36c402(0x18e)]=join(homedir(),DEFAULT_CONFIG[a19_0x36c402(0x18d)],DEFAULT_CONFIG[a19_0x36c402(0x190)]);static[a19_0x36c402(0x195)](_0x529be4){const _0x1f9740=a19_0x36c402,_0x46a3a6=this['initConfig'](),_0x353015=_0x46a3a6[_0x1f9740(0x17b)][_0x1f9740(0x189)](_0x1db111=>_0x1db111[_0x1f9740(0x167)]===_0x529be4['name']);_0x353015===-0x1?_0x46a3a6[_0x1f9740(0x17b)][_0x1f9740(0x16b)](_0x529be4):_0x46a3a6[_0x1f9740(0x17b)][_0x353015]=_0x529be4,this[_0x1f9740(0x165)](_0x46a3a6);}static[a19_0x36c402(0x18c)](_0x264120){const _0x1e6fd3=a19_0x36c402,_0x452524=this[_0x1e6fd3(0x163)](),_0x67785a=_0x452524[_0x1e6fd3(0x16e)][_0x1e6fd3(0x189)](_0x4d551a=>_0x4d551a['name']===_0x264120[_0x1e6fd3(0x167)]);_0x67785a===-0x1?_0x452524['contexts'][_0x1e6fd3(0x16b)](_0x264120):_0x452524['contexts'][_0x67785a]=_0x264120,this[_0x1e6fd3(0x165)](_0x452524);}static[a19_0x36c402(0x183)](){const _0x48fd05=a19_0x36c402,_0x3961bd={'clusters':[],'contexts':[],'current_context':''};this[_0x48fd05(0x165)](_0x3961bd);}static[a19_0x36c402(0x175)](_0x2dbb55){const _0x2c6ef5=a19_0x36c402,_0x24c496=this[_0x2c6ef5(0x15f)](_0x2dbb55[_0x2c6ef5(0x17a)]),_0xaec68c={'cluster':_0x2dbb55[_0x2c6ef5(0x17a)],'cluster_token':_0x2dbb55['clusterToken'],'name':_0x24c496,'user_info':Buffer[_0x2c6ef5(0x162)](JSON[_0x2c6ef5(0x192)](_0x2dbb55['userInfo']))[_0x2c6ef5(0x181)](_0x2c6ef5(0x18a))};this[_0x2c6ef5(0x195)](_0xaec68c);const _0x38e960=_0x2dbb55[_0x2c6ef5(0x186)]||_0x2dbb55[_0x2c6ef5(0x17a)]||_0x2c6ef5(0x191),_0x45882d={'cluster':_0x24c496,'name':_0x38e960};this[_0x2c6ef5(0x18c)](_0x45882d),this['setCurrentContext'](_0x38e960);}static[a19_0x36c402(0x15f)](_0xf1d213){const _0x5ee416=a19_0x36c402;try{const _0x184472=new URL(_0xf1d213);return''+_0x184472[_0x5ee416(0x18f)]+(_0x184472[_0x5ee416(0x180)]?':'+_0x184472[_0x5ee416(0x180)]:'');}catch{return _0xf1d213['replaceAll'](/[^a-zA-Z0-9]/g,'_');}}static[a19_0x36c402(0x164)](_0x27547a){const _0xedce62=a19_0x36c402,_0x329342=this[_0xedce62(0x173)]();if(!_0x329342)return null;return _0x329342[_0xedce62(0x17b)][_0xedce62(0x15e)](_0x14bb5d=>_0x14bb5d['name']===_0x27547a)||null;}static[a19_0x36c402(0x174)](_0x10f8ff){const _0x2583d1=a19_0x36c402,_0x472a6f=this[_0x2583d1(0x173)]();if(!_0x472a6f)return null;return _0x472a6f[_0x2583d1(0x16e)][_0x2583d1(0x15e)](_0xdd71=>_0xdd71[_0x2583d1(0x167)]===_0x10f8ff)||null;}static[a19_0x36c402(0x166)](){const _0x22d5f4=a19_0x36c402,_0x31d1b6=this['getCurrentContext']();if(!_0x31d1b6)return null;const _0x3ac5d1=this['readConfig']();if(!_0x3ac5d1)return null;return _0x3ac5d1[_0x22d5f4(0x17b)][_0x22d5f4(0x15e)](_0x3806e0=>_0x3806e0['name']===_0x31d1b6['cluster'])||null;}static[a19_0x36c402(0x168)](){const _0x244de7=a19_0x36c402,_0x37d44e=this[_0x244de7(0x173)]();if(!_0x37d44e||!_0x37d44e[_0x244de7(0x160)])return null;return _0x37d44e['contexts']['find'](_0x1d05de=>_0x1d05de['name']===_0x37d44e[_0x244de7(0x160)])||null;}static[a19_0x36c402(0x193)](){const _0x279c5=a19_0x36c402,_0x58297c=this[_0x279c5(0x166)]();if(!_0x58297c||!_0x58297c[_0x279c5(0x172)])return null;try{const _0x1e23ad=Buffer['from'](_0x58297c[_0x279c5(0x172)],_0x279c5(0x18a))['toString'](_0x279c5(0x17c));return JSON[_0x279c5(0x170)](_0x1e23ad);}catch{return null;}}static[a19_0x36c402(0x163)](){const _0x454dd6=a19_0x36c402,_0x3a4eec=this['readConfig']();if(_0x3a4eec)return _0x3a4eec;const _0x3a6be4={'clusters':[],'contexts':[],'current_context':''};return this[_0x454dd6(0x165)](_0x3a6be4),_0x3a6be4;}static['isLoggedIn'](){const _0x2ab019=a19_0x36c402,_0x2e621d=this[_0x2ab019(0x166)]();return Boolean(_0x2e621d&&_0x2e621d[_0x2ab019(0x185)]&&_0x2e621d[_0x2ab019(0x172)]);}static[a19_0x36c402(0x16a)](_0x450665){const _0x2bbfb7=a19_0x36c402,_0x2daed7=_0x450665[_0x2bbfb7(0x178)]('/')?_0x450665['slice'](0x0,-0x1):_0x450665,_0x5d192e=this[_0x2bbfb7(0x15f)](_0x2daed7),_0x524cd7=this[_0x2bbfb7(0x164)](_0x5d192e);return Boolean(_0x524cd7&&_0x524cd7[_0x2bbfb7(0x185)]&&_0x524cd7['user_info']&&_0x524cd7['cluster']===_0x2daed7);}static[a19_0x36c402(0x176)](_0x1979e8){const _0x56c987=a19_0x36c402,_0xbae43d=_0x1979e8['endsWith']('/')?_0x1979e8['slice'](0x0,-0x1):_0x1979e8,_0x4ae702=this[_0x56c987(0x15f)](_0xbae43d),_0x46c809=this[_0x56c987(0x164)](_0x4ae702);if(_0x46c809&&_0x46c809[_0x56c987(0x16c)]===_0xbae43d)return _0x46c809;return null;}static['listClusters'](){const _0x2a1ff1=a19_0x36c402,_0x30e4f5=this[_0x2a1ff1(0x173)]();return _0x30e4f5?.['clusters']||[];}static[a19_0x36c402(0x182)](){const _0x1a549c=a19_0x36c402,_0x16c842=this[_0x1a549c(0x173)]();return _0x16c842?.[_0x1a549c(0x16e)]||[];}static[a19_0x36c402(0x173)](){const _0x4b4d22=a19_0x36c402;if(!existsSync(this[_0x4b4d22(0x18e)]))return null;try{const _0x2e08bf=readFileSync(this[_0x4b4d22(0x18e)],_0x4b4d22(0x17c));return JSON['parse'](_0x2e08bf);}catch{return null;}}static['removeCluster'](_0x3e29c0){const _0x3f08e5=a19_0x36c402,_0xcc5f63=this[_0x3f08e5(0x163)]();_0xcc5f63[_0x3f08e5(0x17b)]=_0xcc5f63[_0x3f08e5(0x17b)][_0x3f08e5(0x169)](_0x2cafec=>_0x2cafec[_0x3f08e5(0x167)]!==_0x3e29c0),_0xcc5f63[_0x3f08e5(0x16e)]=_0xcc5f63[_0x3f08e5(0x16e)][_0x3f08e5(0x169)](_0x57a1e3=>_0x57a1e3['cluster']!==_0x3e29c0);const _0x1c8b77=_0xcc5f63['contexts']['find'](_0x440fbc=>_0x440fbc[_0x3f08e5(0x167)]===_0xcc5f63[_0x3f08e5(0x160)]);!_0x1c8b77&&(_0xcc5f63[_0x3f08e5(0x160)]=_0xcc5f63[_0x3f08e5(0x16e)][_0x3f08e5(0x17e)]>0x0?_0xcc5f63[_0x3f08e5(0x16e)][0x0][_0x3f08e5(0x167)]:''),this[_0x3f08e5(0x165)](_0xcc5f63);}static[a19_0x36c402(0x171)](_0x3f1a62){const _0xadb5d6=a19_0x36c402,_0x32a940=this[_0xadb5d6(0x163)]();_0x32a940[_0xadb5d6(0x16e)]=_0x32a940[_0xadb5d6(0x16e)][_0xadb5d6(0x169)](_0x48167d=>_0x48167d['name']!==_0x3f1a62),_0x32a940['current_context']===_0x3f1a62&&(_0x32a940[_0xadb5d6(0x160)]=_0x32a940['contexts'][_0xadb5d6(0x17e)]>0x0?_0x32a940[_0xadb5d6(0x16e)][0x0][_0xadb5d6(0x167)]:''),this[_0xadb5d6(0x165)](_0x32a940);}static[a19_0x36c402(0x194)](_0x1b2b59){const _0x5b90a1=a19_0x36c402,_0x21d9b3=this[_0x5b90a1(0x163)](),_0x642500=_0x21d9b3[_0x5b90a1(0x16e)][_0x5b90a1(0x188)](_0x4c6a7f=>_0x4c6a7f['name']===_0x1b2b59);if(!_0x642500)throw new Error('Context\x20\x22'+_0x1b2b59+_0x5b90a1(0x177));_0x21d9b3[_0x5b90a1(0x160)]=_0x1b2b59,this[_0x5b90a1(0x165)](_0x21d9b3);}static[a19_0x36c402(0x165)](_0x4673af){const _0x6c2649=a19_0x36c402,_0x5d32aa=dirname(this[_0x6c2649(0x18e)]);!existsSync(_0x5d32aa)&&mkdirSync(_0x5d32aa,{'recursive':!![]}),writeFileSync(this[_0x6c2649(0x18e)],JSON[_0x6c2649(0x192)](_0x4673af,null,0x2));}}function a19_0x34a3(_0x30d3b8,_0x5193b1){const _0xb40d3c=a19_0xb40d();return a19_0x34a3=function(_0x34a3e3,_0xbeeda6){_0x34a3e3=_0x34a3e3-0x15d;let _0x1cf940=_0xb40d3c[_0x34a3e3];return _0x1cf940;},a19_0x34a3(_0x30d3b8,_0x5193b1);}function a19_0xb40d(){const _0x16bdc1=['findIndex','base64','74775ouEaWz','addContext','WORK_DIR_NAME','configPath','hostname','CONFIG_FILE','default','stringify','getCurrentUserInfo','setCurrentContext','addCluster','776418pfzSyU','5FzObuX','find','generateClusterName','current_context','8xrPZsU','from','initConfig','getCluster','writeConfig','getCurrentCluster','name','getCurrentContext','filter','isLoggedInForCluster','push','cluster','55QpnIOm','contexts','2830569IAjYnz','parse','removeContext','user_info','readConfig','getContext','createLoginConfig','getClusterByUrl','\x22\x20not\x20found','endsWith','5418410Nxfipq','clusterUrl','clusters','utf8','212PlyoEf','length','2622438HPgCJV','port','toString','listContexts','clearAllConfig','2206120BOzoQu','cluster_token','contextName','1925238xdrfal','some'];a19_0xb40d=function(){return _0x16bdc1;};return a19_0xb40d();}