@northflank/cli
Version:
Provides a command-line interface to the Northflank platform.
1 lines • 9.14 kB
JavaScript
const a5Z=a5j;(function(X,j){const t=a5j,V=X();while(!![]){try{const H=parseInt(t(0x182))/0x1*(-parseInt(t(0x15e))/0x2)+-parseInt(t(0x193))/0x3*(parseInt(t(0x16d))/0x4)+parseInt(t(0x1bc))/0x5+parseInt(t(0x1b8))/0x6*(parseInt(t(0x1a1))/0x7)+-parseInt(t(0x1a0))/0x8+parseInt(t(0x17b))/0x9*(-parseInt(t(0x190))/0xa)+parseInt(t(0x1a2))/0xb;if(H===j)break;else V['push'](V['shift']());}catch(O){V['push'](V['shift']());}}}(a5X,0x86bc8));import{ApiClient}from'@northflank/js-client';import a5V from'chalk';function a5X(){const Y=['\x20on\x20instance\x20','\x0a\x20\x20Single\x20command,\x20no\x20shell:\x20\x20\x20\x20\x20northflank\x20exec\x20','getCurrentServiceName','slice','exit','--project\x20--projectId\x20[NAME]','stderr','option','Run\x20command\x20with\x20this\x20group','resizeTerminal','Exec\x20','askForAddon','Received\x20Ctrl+D\x20twice,\x20exiting\x20shell\x20forcefully.','action','--user\x20[USER]','getTerminalSize','message','handleShellSession','columns','Id\x20[NAME]','54NquIjp','--container\x20--containerName\x20[NAME]','command-exec','containerName','4259465jDaEVT','Success','execJobSession','stdout','sequence','Command\x20exec\x20for\x20the\x20specified\x20','\x27Ctrl+D\x27','14vaegtQ','service','with\x20command\x20\x27','resize','askForProject','stdErr','execStartLog','--shell-cmd\x20[SHELL-CMD]','\x20to\x20exec\x20into','addon','instanceName','toUpperCase','Command\x20completed\x20successfully,\x20exit\x20code:\x20','shell\x20command\x20','waitForCommandResult','120GipuKs','keypress','exec','error','Command\x20didn\x27t\x20complete\x20successfully,\x20status:\x20','with\x20group:','with\x20shell\x20session','Run\x20command\x20with\x20this\x20user','isTTY','execCmd','emitKeypressEvents','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.','\x20--shell-cmd\x20\x27sh\x27','getStandardExecCommand','18exsHkG','stdOut','\x20command\x20exec:\x20','--cmd\x20--command\x20[COMMAND]','execAddonSession','setRawMode','alias','103596OWkRFS','Command\x20execution\x20(exec)\x20for\x20Northflank\x20services\x20and\x20jobs.','Don\x27t\x20use\x20context\x20default\x20values,\x20explicitly\x20use\x20options\x20or\x20ask.','--noDefaults','exitCode','getCurrentProjectName','\x20in\x20project\x20','Instance\x20to\x20exec\x20into\x20',',\x20details:\x20','stdin','name','description','\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','charAt','3221120YcIVpH','none','\x20--cmd\x20\x27date\x27\x0a\x20\x20Single\x20command,\x20custom\x20shell:\x20northflank\x20exec\x20','78603afhqoM','(random\x20instance\x20will\x20be\x20chosen\x20if\x20not\x20specified)',',\x20exit\x20code:\x20','job','addCommand','pipe','rows','askForService','bold','apiClient','join','filter','--instance\x20--instanceName\x20[NAME]','7578880ZToytM','51989bdvxEb','30095230HnJeWc','Error\x20occured\x20during\x20'];a5X=function(){return Y;};return a5X();}import{assertContextExisting,customUserAgent,error,getCommand,success,warning}from'../utils.js';function a5j(X,j){const V=a5X();return a5j=function(H,O){H=H-0x15b;let F=V[H];return F;},a5j(X,j);}import{InquirerHelper}from'../inquirer-helper.js';import a5H from'readline';export class CliExec{[a5Z(0x176)];['apiClient'];[a5Z(0x17a)]=X=>{const w=a5Z,j=getCommand(!![])[w(0x18c)](X)[w(0x18d)](w(0x15c)+X+(X==='addon'?'(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'+X+w(0x1a5)+X+w(0x192)+X+w(0x18e)+X+w(0x179))[w(0x1ab)](w(0x1a9),'Project\x20for\x20exec')[w(0x1ab)]('--'+X+'\x20--'+X+w(0x1b7),X[w(0x18f)](0x0)[w(0x169)]()+X[w(0x1a7)](0x1)+w(0x166))[w(0x1ab)](w(0x19f),w(0x189)+(X===w(0x167)?'(required)\x20':w(0x194)))['option'](w(0x165),w(0x178))['option'](w(0x185),w(0x184),![])[w(0x1ab)](w(0x17e),'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.');return X!==w(0x167)&&j['option'](w(0x1b2),w(0x174))[w(0x1ab)]('--group\x20[GROUP]',w(0x1ac)),X===w(0x167)&&j[w(0x1ab)](w(0x1b9),'Container\x20within\x20instance\x20to\x20exec\x20into\x20(if\x20not\x20specified,\x20first\x20container\x20of\x20the\x20instance\x20will\x20be\x20selected)'),j;};constructor(X,j){const N=a5Z;this[N(0x19c)]=new ApiClient(X,{'throwErrorOnHttpErrorCode':!![],'customUserAgent':customUserAgent,'agent':j});const V=new InquirerHelper(this[N(0x19c)]);this[N(0x176)]=getCommand()[N(0x18c)](N(0x1ba))[N(0x181)](N(0x16f))[N(0x18d)](N(0x183));const H=this['getStandardExecCommand']('service')[N(0x1b1)](async h=>{const p=N,{noDefaults:P,projectId:o,serviceId:C,instanceName:B}=h,{shellCmd:s,user:S,group:y,command:A,quiet:l}=h;assertContextExisting(this['apiClient']);try{const T=P?undefined:X[p(0x187)](),W=o||T||await V[p(0x162)](),v=P?undefined:X[p(0x1a6)](),G=C||v||await V[p(0x19a)](W)(),d=s??(A!==undefined?p(0x191):undefined),x=process[p(0x1bf)][p(0x1b6)],M=process['stdout']['rows'],g={'projectId':W,'serviceId':G},J={'instanceName':B,'command':A,'shell':d,'user':S,'group':y,'ttyColumns':x,'ttyRows':M},b=await this['apiClient']['exec']['execServiceSession'](g,J,E=>{const m=p;this['execStartLog'](m(0x15f),G,W,s,S,y,A,l,E[m(0x168)],E[m(0x1bb)]);});await this[p(0x1b5)](b,p(0x15f),l);}catch(E){error(''+E[p(0x1b4)]);}finally{process[p(0x1a8)]();}}),O=this[N(0x17a)](N(0x196))[N(0x1b1)](async h=>{const k=N,{projectId:P,jobId:o,instanceName:C}=h,{noDefaults:B,shellCmd:s,user:S,group:y,command:A,quiet:l}=h;assertContextExisting(this[k(0x19c)]);try{const T=B?undefined:X['getCurrentProjectName'](),W=P||T||await V[k(0x162)](),v=o||await V['askForJob'](W)(),{rows:G,columns:d}=this[k(0x1b3)](),x={'projectId':W,'jobId':v},M={'instanceName':C,'command':A,'shell':s,'user':S,'group':y,'ttyColumns':d,'ttyRows':G},g=await this[k(0x19c)]['exec'][k(0x1be)](x,M,J=>{const I=k;this['execStartLog']('job',v,W,s,S,y,A,l,J[I(0x168)],J[I(0x1bb)]);});await this[k(0x1b5)](g,'job',l);}catch(J){error(''+J[k(0x1b4)]);}finally{process['exit']();}}),F=this[N(0x17a)](N(0x167))['action'](async h=>{const K=N,{projectId:P,addonId:o,instanceName:C,containerName:B}=h,{noDefaults:s,shellCmd:S,user:y,group:A,command:l,quiet:T}=h;assertContextExisting(this[K(0x19c)]);try{const W=s?undefined:X[K(0x187)](),v=P||W||await V[K(0x162)](),G=o||await V[K(0x1af)](v)(),{rows:d,columns:x}=this[K(0x1b3)](),M=S??(l!==undefined?K(0x191):undefined),g={'projectId':v,'addonId':G},J={'instanceName':C,'containerName':B,'command':l,'shell':M,'user':y,'group':A,'ttyColumns':x,'ttyRows':d},b=await this['apiClient'][K(0x16f)][K(0x17f)](g,J,E=>{const L=K;this[L(0x164)]('addon',G,v,M,y,A,l,T,E['instanceName'],E[L(0x1bb)]);});await this['handleShellSession'](b,K(0x167),T);}catch(E){error(''+E[K(0x1b4)]);}finally{process[K(0x1a8)]();}});this['execCmd']['addCommand'](H),this[N(0x176)]['addCommand'](O),this[N(0x176)][N(0x197)](F);}[a5Z(0x1b3)]=()=>({'columns':process[a5Z(0x1bf)][a5Z(0x1b6)],'rows':process[a5Z(0x1bf)][a5Z(0x199)]});[a5Z(0x164)]=(X,j,V,H,O,F,h,P,o,C)=>{const a=a5Z;if(P===!![])return;const B=H==='none',s=o!==undefined?a(0x1a4)+a5V[a(0x19b)](o):'',S=C!==undefined?'\x20in\x20container\x20'+a5V['bold'](C):'',y=B?'without\x20shell':H===undefined?a(0x173):a(0x16b)+a5V['greenBright'](H),e=O?'with\x20user:'+O:'',A=F?a(0x172)+F:'',l=h?a(0x160)+a5V['greenBright'](h)+'\x27':'',T=[l,y,e,A][a(0x19e)](v=>v!=='')[a(0x19d)]('\x20'),W='(exit\x20with\x20two\x20quick\x20'+a5V[a(0x19b)](a(0x15d))+')';console['log'](a(0x1ae)+X+'\x20'+a5V[a(0x19b)](j)+a(0x188)+a5V[a(0x19b)](V)+s+S+'\x20'+T+'\x20'+W);};['handleShellSession']=async(X,j,V=![])=>{const r=a5Z;let H=![];try{process[r(0x18b)][r(0x175)]&&(a5H[r(0x177)](process[r(0x18b)]),process[r(0x18b)][r(0x180)](!![]),process[r(0x1bf)]['on'](r(0x161),()=>{const R=r;X[R(0x1ad)](this[R(0x1b3)]());}),process[r(0x18b)]['on'](r(0x16e),(F,h)=>{const n=r;h[n(0x15b)]==='\x04'&&(H?(process[n(0x18b)][n(0x180)](![]),warning(n(0x1b0)),process['exit']()):(H=!![],setTimeout(()=>H=![],0x190)));}));process[r(0x18b)]['pipe'](X['stdIn']),X[r(0x163)][r(0x198)](process[r(0x1aa)]),X[r(0x17c)][r(0x198)](process['stdout']),X['on'](r(0x170),F=>{const D=r;error(D(0x1a3)+j+D(0x17d)+(F[D(0x1b4)]??F)),process['stdin'][D(0x175)]&&process['stdin'][D(0x180)](![]),process['exit'](-0x1);});const O=await X[r(0x16c)]();if(V!==!![]){const F=O?.['status']??'Unknown',h=O?.[r(0x186)]??-0x1,P=O?.[r(0x1b4)]?r(0x18a)+O['message']:'';F===r(0x1bd)?success(r(0x16a)+h):warning(r(0x171)+F+r(0x195)+h+P);}return O;}finally{process[r(0x18b)][r(0x175)]&&process[r(0x18b)][r(0x180)](![]);}};}