UNPKG

@northflank/cli

Version:

Provides a command-line interface to the Northflank platform.

1 lines 9.91 kB
const a5R=a5E;(function(m,E){const a=a5E,h=m();while(!![]){try{const I=-parseInt(a(0x199))/0x1+-parseInt(a(0x197))/0x2+parseInt(a(0x158))/0x3*(parseInt(a(0x163))/0x4)+parseInt(a(0x173))/0x5*(parseInt(a(0x15f))/0x6)+parseInt(a(0x162))/0x7*(-parseInt(a(0x189))/0x8)+parseInt(a(0x169))/0x9*(parseInt(a(0x1a7))/0xa)+parseInt(a(0x1a6))/0xb;if(I===E)break;else h['push'](h['shift']());}catch(T){h['push'](h['shift']());}}}(a5m,0x9017f));function a5m(){const k=['greenBright','askForTeam','with\x20user:','\x20--','Don\x27t\x20use\x20context\x20default\x20values,\x20explicitly\x20use\x20options\x20or\x20ask.','contextProvider','askForService','without\x20shell','Error\x20occured\x20during\x20','getTerminalSize','Project\x20for\x20exec','askForJob','\x20--cmd\x20\x27date\x27\x0a\x20\x20Single\x20command,\x20custom\x20shell:\x20northflank\x20exec\x20','Unknown','\x27Ctrl+D\x27','filter','Run\x20command\x20with\x20this\x20user','32inxzKI','\x20in\x20container\x20','stderr','join','askForAddon','Id\x20[NAME]','pipe','setRawMode','isTTY','charAt','toUpperCase','Received\x20Ctrl+D\x20twice,\x20exiting\x20shell\x20forcefully.','--cmd\x20--command\x20[COMMAND]','Team\x20id','2106166xYwzhG','option','103788SWPAPD','Command\x20to\x20execute.\x0aIf\x20--shell-cmd\x20option\x20such\x20as\x20\x27bash\x20-c\x27\x20is\x20present,\x20it\x20will\x20run\x20in\x20the\x20specified\x20shell.\x20Otherwise\x20the\x20command\x20will\x20run\x20without\x20a\x20shell.\x20If\x20no\x20command\x20is\x20provided,\x20an\x20interactive\x20session\x20with\x20stdin\x20and\x20tty\x20is\x20opened.','execServiceSession','stdErr','error','stdIn','askForProjectContext','org','(random\x20instance\x20will\x20be\x20chosen\x20if\x20not\x20specified)','--execLocationHint\x20[EXEC-LOCATION-HINT]','execJobSession','execCmd','action','834559QeCmQH','692030IpGtae','with\x20group:','exit',',\x20exit\x20code:\x20','rows','execAddonSession','stdOut','execStartLog','getCurrentProjectName','command-exec','\x20to\x20exec\x20into','message','instanceName','name','\x20command\x20exec:\x20','Instance\x20to\x20exec\x20into\x20','(exit\x20with\x20two\x20quick\x20','stdout','\x20on\x20instance\x20','status','Success','Command\x20exec\x20for\x20the\x20specified\x20','resize','exitCode','askForProject','stdin','containerName','getStandardExecCommand','columns','Run\x20command\x20with\x20this\x20group','service','12618OAAnBD','getTokenScope','job','Container\x20within\x20instance\x20to\x20exec\x20into\x20(if\x20not\x20specified,\x20first\x20container\x20of\x20the\x20instance\x20will\x20be\x20selected)','addon','getCurrentServiceName','\x0a\x20\x20Single\x20command,\x20no\x20shell:\x20\x20\x20\x20\x20northflank\x20exec\x20','12LwuObB','--container\x20--containerName\x20[NAME]','--instance\x20--instanceName\x20[NAME]','760193xozraf','88lzzzTe','Command\x20execution\x20(exec)\x20for\x20Northflank\x20services\x20and\x20jobs.','description','--shell-cmd\x20[SHELL-CMD]','--user\x20[USER]',',\x20details:\x20','117VuxmLF','exec','\x20in\x20project\x20','apiClient','\x20--cmd\x20\x27\x22ls\x20-l\x20/usr\x22\x27\x20--shell-cmd\x20\x27bash\x20-c\x27\x0a\x20\x20Shell\x20session,\x20custom\x20shell:\x20\x20northflank\x20exec\x20','emitKeypressEvents','keypress','addCommand','waitForCommandResult','none','2783585sJAYdz','bold','handleShellSession','(required)\x20','--group\x20[GROUP]'];a5m=function(){return k;};return a5m();}import{ApiClient}from'@northflank/js-client';import a5h from'chalk';import{assertContextExisting,customUserAgent,error,getCommand,success,warning}from'../utils.js';import{InquirerHelper}from'../inquirer-helper.js';function a5E(m,E){const h=a5m();return a5E=function(I,T){I=I-0x140;let e=h[I];return e;},a5E(m,E);}import a5I from'readline';export class CliExec{[a5R(0x1a4)];[a5R(0x16c)];['getStandardExecCommand']=m=>{const x=a5R,E=getCommand(!![])[x(0x146)](m)[x(0x165)](x(0x14e)+m+(m===x(0x15c)?'(only\x20applicable\x20for\x20custom\x20addon\x20types)\x20':'')+'.\x0aExamples:\x0a\x20\x20Shell\x20session:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20northflank\x20exec\x20'+m+x(0x15e)+m+x(0x184)+m+x(0x16d)+m+'\x20--shell-cmd\x20\x27sh\x27');return this['apiClient'][x(0x17d)]['getTokenScope']()===x(0x1a0)&&E[x(0x198)]('--team\x20--teamId\x20[TEAMID]',x(0x196)),E['option']('--project\x20--projectId\x20[NAME]',x(0x182))[x(0x198)]('--'+m+x(0x17b)+m+x(0x18e),m[x(0x192)](0x0)[x(0x193)]()+m['slice'](0x1)+x(0x143))['option'](x(0x161),x(0x148)+(m==='addon'?x(0x176):x(0x1a1)))[x(0x198)](x(0x166),'Run\x20command\x20with\x20shell\x20(e.g.\x20\x27bash\x27,\x27sh\x27).\x0aIf\x20not\x20set\x20and\x20no\x20command\x20is\x20provided,\x20several\x20standard\x20shells\x20will\x20be\x20attempted.\x20If\x20not\x20set\x20and\x20a\x20command\x20is\x20provided,\x20the\x20command\x20will\x20run\x20without\x20shell.')[x(0x198)]('--noDefaults',x(0x17c),![])[x(0x198)](x(0x195),x(0x19a))[x(0x198)](x(0x1a2),'Connect\x20to\x20specific\x20exec\x20endpoint.'),m!==x(0x15c)&&E['option'](x(0x167),x(0x188))[x(0x198)](x(0x177),x(0x156)),m===x(0x15c)&&E[x(0x198)](x(0x160),x(0x15b)),E;};constructor(m,E){const D=a5R;this[D(0x16c)]=new ApiClient(m,{'throwErrorOnHttpErrorCode':!![],'customUserAgent':customUserAgent,'agent':E});const h=new InquirerHelper(this[D(0x16c)]);this[D(0x1a4)]=getCommand()['name'](D(0x142))['alias'](D(0x16a))[D(0x165)](D(0x164));const I=this[D(0x154)](D(0x157))[D(0x1a5)](async o=>{const f=D,{noDefaults:g,teamId:J,projectId:L,serviceId:P,instanceName:X}=o,{shellCmd:W,user:K,group:z,command:S,quiet:H,execLocationHint:r}=o;assertContextExisting(this[f(0x16c)]);try{const F=g?undefined:m[f(0x141)](),{projectId:t,teamId:Y}=await this[f(0x19f)](m,h,L,J,F),N=g?undefined:m[f(0x15d)](),w=P||N||await h[f(0x17e)](t,Y)(),b=W??(S!==undefined?f(0x172):undefined),n=process[f(0x14a)][f(0x155)],Q=process['stdout']['rows'],c={'teamId':Y,'projectId':t,'serviceId':w},O={'instanceName':X,'command':S,'shell':b,'user':K,'group':z,'ttyColumns':n,'ttyRows':Q,'execLocationHint':r},B=await this[f(0x16c)][f(0x16a)][f(0x19b)](c,O,q=>{const M=f;this[M(0x140)](M(0x157),w,t,W,K,z,S,H,q[M(0x145)],q['containerName']);});await this[f(0x175)](B,'service',H);}catch(q){error(''+q[f(0x144)]);}finally{process[f(0x1a9)]();}}),T=this[D(0x154)](D(0x15a))[D(0x1a5)](async o=>{const U=D,{teamId:g,projectId:J,jobId:L,instanceName:P}=o,{noDefaults:X,shellCmd:W,user:K,group:z,command:S,quiet:H,execLocationHint:r}=o;assertContextExisting(this[U(0x16c)]);try{const F=X?undefined:m['getCurrentProjectName'](),{projectId:t,teamId:Y}=await this[U(0x19f)](m,h,J,g,F),N=L||await h[U(0x183)](t,Y)(),{rows:w,columns:b}=this[U(0x181)](),n={'teamId':Y,'projectId':t,'jobId':N},Q={'instanceName':P,'command':S,'shell':W,'user':K,'group':z,'ttyColumns':b,'ttyRows':w,'execLocationHint':r},c=await this[U(0x16c)]['exec'][U(0x1a3)](n,Q,O=>{const C=U;this[C(0x140)](C(0x15a),N,t,W,K,z,S,H,O[C(0x145)],O[C(0x153)]);});await this[U(0x175)](c,U(0x15a),H);}catch(O){error(''+O[U(0x144)]);}finally{process['exit']();}}),e=this['getStandardExecCommand'](D(0x15c))[D(0x1a5)](async o=>{const Z=D,{teamId:g,projectId:J,addonId:L,instanceName:P,containerName:X}=o,{noDefaults:W,shellCmd:K,user:z,group:S,command:H,quiet:r,execLocationHint:F}=o;assertContextExisting(this[Z(0x16c)]);try{const t=W?undefined:m[Z(0x141)](),{projectId:Y,teamId:N}=await this[Z(0x19f)](m,h,J,g,t),w=L||await h[Z(0x18d)](Y,N)(),{rows:b,columns:n}=this[Z(0x181)](),Q=K??(H!==undefined?Z(0x172):undefined),c={'teamId':N,'projectId':Y,'addonId':w},O={'instanceName':P,'containerName':X,'command':H,'shell':Q,'user':z,'group':S,'ttyColumns':n,'ttyRows':b,'execLocationHint':F},B=await this[Z(0x16c)][Z(0x16a)][Z(0x1ac)](c,O,q=>{const i=Z;this[i(0x140)](i(0x15c),w,Y,Q,z,S,H,r,q['instanceName'],q[i(0x153)]);});await this[Z(0x175)](B,Z(0x15c),r);}catch(q){error(''+q[Z(0x144)]);}finally{process[Z(0x1a9)]();}});this[D(0x1a4)]['addCommand'](I),this['execCmd'][D(0x170)](T),this[D(0x1a4)][D(0x170)](e);}['getTerminalSize']=()=>({'columns':process[a5R(0x14a)][a5R(0x155)],'rows':process['stdout'][a5R(0x1ab)]});[a5R(0x140)]=(m,E,h,I,T,e,o,g,J,L)=>{const V=a5R;if(g===!![])return;const P=I===V(0x172),X=J!==undefined?V(0x14b)+a5h[V(0x174)](J):'',W=L!==undefined?V(0x18a)+a5h[V(0x174)](L):'',K=P?V(0x17f):I===undefined?'with\x20shell\x20session':'shell\x20command\x20'+a5h[V(0x178)](I),z=T?V(0x17a)+T:'',S=e?V(0x1a8)+e:'',H=o?'with\x20command\x20\x27'+a5h[V(0x178)](o)+'\x27':'',r=[H,K,z,S][V(0x187)](t=>t!=='')[V(0x18c)]('\x20'),F=V(0x149)+a5h[V(0x174)](V(0x186))+')';console['log']('Exec\x20'+m+'\x20'+a5h[V(0x174)](E)+V(0x16b)+a5h['bold'](h)+X+W+'\x20'+r+'\x20'+F);};[a5R(0x175)]=async(m,E,h=![])=>{const G=a5R;let I=![];try{process[G(0x152)][G(0x191)]&&(a5I[G(0x16e)](process[G(0x152)]),process['stdin'][G(0x190)](!![]),process[G(0x14a)]['on'](G(0x14f),()=>{const l=G;m['resizeTerminal'](this[l(0x181)]());}),process['stdin']['on'](G(0x16f),(e,o)=>{const s=G;o['sequence']==='\x04'&&(I?(process[s(0x152)]['setRawMode'](![]),warning(s(0x194)),process[s(0x1a9)]()):(I=!![],setTimeout(()=>I=![],0x190)));}));process[G(0x152)][G(0x18f)](m[G(0x19e)]),m[G(0x19c)][G(0x18f)](process[G(0x18b)]),m[G(0x1ad)][G(0x18f)](process[G(0x14a)]),m['on'](G(0x19d),e=>{const y=G;error(y(0x180)+E+y(0x147)+(e[y(0x144)]??e)),process['stdin'][y(0x191)]&&process[y(0x152)][y(0x190)](![]),process[y(0x1a9)](-0x1);});const T=await m[G(0x171)]();if(h!==!![]){const e=T?.[G(0x14c)]??G(0x185),o=T?.[G(0x150)]??-0x1,g=T?.[G(0x144)]?G(0x168)+T[G(0x144)]:'';e===G(0x14d)?success('Command\x20completed\x20successfully,\x20exit\x20code:\x20'+o):warning('Command\x20didn\x27t\x20complete\x20successfully,\x20status:\x20'+e+G(0x1aa)+o+g);}return T;}finally{process[G(0x152)][G(0x191)]&&process[G(0x152)][G(0x190)](![]);}};['askForProjectContext']=async(m,E,h,I,T)=>{const u=a5R,e=m[u(0x159)]()===u(0x1a0)?I??await E[u(0x179)]()():undefined,o=h||T||await E[u(0x151)](e)();return{'teamId':e,'projectId':o};};}