@northflank/cli
Version:
Provides a command-line interface to the Northflank platform.
1 lines • 7.36 kB
JavaScript
const a16D=a16E;(function(m,E){const x=a16E,h=m();while(!![]){try{const I=-parseInt(x(0x13a))/0x1*(-parseInt(x(0x124))/0x2)+parseInt(x(0x173))/0x3*(-parseInt(x(0x156))/0x4)+-parseInt(x(0x150))/0x5*(-parseInt(x(0x116))/0x6)+parseInt(x(0x12a))/0x7*(parseInt(x(0x15c))/0x8)+-parseInt(x(0x172))/0x9+-parseInt(x(0x16f))/0xa+-parseInt(x(0x168))/0xb;if(I===E)break;else h['push'](h['shift']());}catch(T){h['push'](h['shift']());}}}(a16m,0x5e0d1));import{ApiClient}from'@northflank/js-client';import{assertContextExisting,customUserAgent,error,getCommand,success,warning}from'../utils.js';function a16m(){const u=['\x20\x20>\x20RSYNC:\x20\x20\x09','name','/usr/local/bin/ssh','description','startSSH','Ctrl+C\x20received\x20-\x20Terminating\x20SSH\x20proxy...','\x20\x20>\x20SSH\x20session:','606AzkPNq','.\x20Creates\x20an\x20SSH\x20terminal\x20session\x20by\x20default.','sftp\x20-P\x20','askForService','Only\x20startup\x20SSH\x20proxy\x20without\x20opening\x20an\x20SSH\x20terminal\x20session.','execFileAsync','\x20\x20>\x20SFTP:\x20\x20\x09','SSH\x20for\x20Northflank\x20services\x20and\x20jobs.','--proxyOnly','--user\x20[USER]','inherit','blackBright','getCurrentProjectName','--noDefaults','2JltOOK','Team\x20id','error','getTokenScope','--useHostnames','Must\x20be\x20run\x20in\x20an\x20interactive\x20terminal\x20(TTY\x20required).','424459IPXqNl','-tt','Use\x20specific\x20username\x20for\x20SSH\x20connection','service','Unable\x20to\x20initiate\x20SSH\x20tunnel.\x20Ensure\x20your\x20service\x20is\x20running\x20and\x20has\x20SSH\x20enabled','isTTY','\x20hostnames\x20on\x20local\x20machine.\x20Requires\x20sudo\x20permissions','Don\x27t\x20use\x20context\x20default\x20values,\x20explicitly\x20use\x20options\x20or\x20ask.','data','charAt','exit','toString','--team\x20--teamId\x20[TEAMID]',',\x20stop\x20with\x20Ctrl+D','/usr/bin/ssh','SSH\x20exited\x20with\x20code:\x20','741106FYKzHF','which','sshCmd','contextProvider','trim','Establish\x20SSH\x20connectivity\x20to\x20Northflank\x20','action','option','kill','apiClient','portName','ssh\x20','SIGINT','UserKnownHostsFile=/dev/null','\x20-l','SSH\x20proxy\x20started\x20on\x20endpoint:\x20','slice','ssh','message','unknown\x20error','Project\x20of\x20the\x20','C:\x5cWindows\x5cSystem32\x5cOpenSSH\x5cssh.exe','36490coDGbs','withServiceForwarding','log','SIGTERM','RequestTTY=yes','\x20file.txt\x20','258296fJnWww','push','close','forwarding',',\x20stop\x20with\x20Ctrl+C','askForProject','32EhAEWP','\x20to\x20ssh\x20into','Use\x20with\x20any\x20SSH\x20compatible\x20client.\x20Example\x20usages:','SSH\x20session\x20ended.','LogLevel=ERROR','stdin','org','findSSH','Replicate\x20','getCurrentServiceName','\x22\x20./data/\x20',':/rsync-test/','3265361LreFoz','SSH\x20killed\x20by\x20signal:\x20','uncaughtException','\x20\x20>\x20SCP:\x20\x20\x09','find','askForProjectContext','addCommand','7323630crQkzK',':/remote/path/','\x20-p\x20','432081wZLFCB','12AVCwMO','Id\x20[NAME]','StrictHostKeyChecking=no','root','SSH\x20binary\x20not\x20found.\x20Please\x20install\x20OpenSSH.'];a16m=function(){return u;};return a16m();}import{InquirerHelper}from'../inquirer-helper.js';function a16E(m,E){const h=a16m();return a16E=function(I,T){I=I-0x112;let e=h[I];return e;},a16E(m,E);}import{spawn}from'child_process';import{execFile}from'child_process';import{promisify}from'util';import a16h from'chalk';export class CliSsh{[a16D(0x13c)];[a16D(0x143)];constructor(m,E){const f=a16D;this[f(0x143)]=new ApiClient(m,{'throwErrorOnHttpErrorCode':!![],'customUserAgent':customUserAgent,'agent':E});const h=new InquirerHelper(this[f(0x143)]);this[f(0x13c)]=getCommand(!![])['name'](f(0x14b))[f(0x112)](f(0x11d));const I=f(0x12d),T=getCommand(!![])[f(0x179)](I)[f(0x112)](f(0x13f)+I+f(0x117))[f(0x141)]('--project\x20--projectId\x20[NAME]',f(0x14e)+I)[f(0x141)]('--'+I+'\x20--'+I+f(0x174),I[f(0x133)](0x0)['toUpperCase']()+I[f(0x14a)](0x1)+f(0x15d))[f(0x141)]('--instance\x20--instanceName\x20[NAME]','Instance\x20to\x20use\x20for\x20SSH\x20(random\x20instance\x20will\x20be\x20chosen\x20if\x20not\x20specified)')['option'](f(0x11e),f(0x11a),![])['option'](f(0x128),f(0x164)+I+f(0x130),![])[f(0x141)](f(0x11f),f(0x12c))[f(0x141)](f(0x123),f(0x131),![]);this[f(0x143)][f(0x13d)][f(0x127)]()===f(0x162)&&T[f(0x141)](f(0x136),f(0x125));const e=T[f(0x140)](async o=>{const M=f,{noDefaults:g,teamId:J,projectId:L,serviceId:P,instanceName:X,proxyOnly:W,useHostnames:K}=o,{user:user=M(0x176),quiet:z}=o;assertContextExisting(this[M(0x143)]);try{const S=g?undefined:m[M(0x122)](),{projectId:H,teamId:r}=await this[M(0x16d)](m,h,L,J,S),F=g?undefined:m[M(0x165)](),t=P||F||await h[M(0x119)](H,r)(),Y=X||await h['askForContainer'](H,t,undefined,![],r,!![])(),N=process[M(0x161)]['isTTY'],w=N&&!W,b={'teamId':r,'projectId':H,'serviceId':t,'instanceId':Y,'portsFilter':[0x16]};await this['apiClient'][M(0x159)][M(0x151)](b,async n=>{const U=M,Q=n[U(0x16c)](a=>a[U(0x132)]?.[U(0x144)]==='default-ssh');if(Q===undefined)throw new Error(U(0x12e));if(Q?.['error']!==undefined||Q?.[U(0x132)]===undefined)throw new Error('Error\x20trying\x20to\x20forward:\x20'+(Q?.[U(0x126)]?.[U(0x14c)]??U(0x14d)));const {address:c,port:O,hostnames:B}=Q[U(0x132)],q=K?B[0x0]??c:c;w?(!z&&success('SSH\x20proxy\x20started\x20on\x20endpoint:\x20'+(q+':'+O)+U(0x137)),await this['startSSH']({'address':q,'port':O,'user':user})):(!z?(success(U(0x149)+(q+':'+O)+U(0x15a)),console[U(0x152)](U(0x15e)),console[U(0x152)](U(0x115)+a16h[U(0x121)](U(0x145)+user+'@'+q+U(0x171)+O)),console[U(0x152)](U(0x11c)+a16h[U(0x121)](U(0x118)+O+'\x20'+user+'@'+q)),console[U(0x152)](U(0x178)+a16h[U(0x121)]('rsync\x20-avz\x20-e\x20\x22ssh\x20-p\x20'+O+U(0x166)+user+'@'+q+U(0x167))),console[U(0x152)](U(0x16b)+a16h[U(0x121)]('scp\x20-P\x20'+O+U(0x155)+user+'@'+q+U(0x170)))):console[U(0x152)](user,q,O),await new Promise((a,R)=>{const C=U;process['on'](C(0x146),()=>{const Z=C;if(!z)success(Z(0x114));a();}),process['on'](C(0x16a),R);}));},!K);}catch(n){error(''+n['message']);}finally{process[M(0x134)]();}});this[f(0x13c)][f(0x16e)](e);}[a16D(0x11b)]=promisify(execFile);async[a16D(0x163)](){const i=a16D;try{const {stdout:m}=await this['execFileAsync'](i(0x13b),['ssh']);return m[i(0x13e)]();}catch{const E=[i(0x14b),i(0x138),i(0x17a),i(0x14f)];for(const h of E){try{return await this[i(0x11b)](h,['-V']),h;}catch{}}return null;}}async[a16D(0x113)](m){const V=a16D,E=await this[V(0x163)]();if(!E)throw new Error(V(0x177));if(!process[V(0x161)][V(0x12f)])throw new Error(V(0x129));const {address:h,port:port=0x16,user:user=V(0x176),args:args=[],trusted:trusted=!![]}=m,I=[];trusted&&I[V(0x157)]('-o',V(0x175),'-o',V(0x147),'-o',V(0x160));user!==V(0x176)&&I[V(0x157)]('-o','RemoteCommand=su\x20'+user+V(0x148),'-o',V(0x154));const T=spawn(E,[V(0x12b),'-p',port[V(0x135)](),'-l',V(0x176),...I,...args,h],{'stdio':V(0x120)});await new Promise((e,o)=>{const G=V;T['on'](G(0x158),(g,J)=>{const l=G;if(J)warning(l(0x169)+J);else g!==0x0?warning(l(0x139)+g):success(l(0x15f));e(g);}),T['on']('error',g=>{const s=G;o(new Error('Failed\x20to\x20spawn\x20SSH\x20command:\x20'+g[s(0x14c)]));}),process['on'](G(0x146),()=>T[G(0x142)](G(0x146))),process['on']('SIGTERM',()=>T[G(0x142)](G(0x153)));});}[a16D(0x16d)]=async(m,E,h,I,T)=>{const y=a16D,e=m[y(0x127)]()===y(0x162)?I??await E['askForTeam']()():undefined,o=h||T||await E[y(0x15b)](e)();return{'teamId':e,'projectId':o};};}