UNPKG

@northflank/cli

Version:

Provides a command-line interface to the Northflank platform.

2 lines 15.9 kB
#!/usr/bin/env -S node --no-deprecation const a1X8=a1j;(function(X,j){const X7=a1j,V=X();while(!![]){try{const H=parseInt(X7(0x2a2))/0x1+parseInt(X7(0x258))/0x2+parseInt(X7(0x245))/0x3+parseInt(X7(0x1f8))/0x4+parseInt(X7(0x284))/0x5*(parseInt(X7(0x28d))/0x6)+parseInt(X7(0x29f))/0x7*(-parseInt(X7(0x1f3))/0x8)+-parseInt(X7(0x1f0))/0x9;if(H===j)break;else V['push'](V['shift']());}catch(O){V['push'](V['shift']());}}}(a1X,0x52e11));import{ApiClient,ApiClientFileContextProvider,GetApiEndpointPaginated}from'@northflank/js-client';import{Command}from'commander';import a1V from'fs';import a1H from'chalk';import{CliContext}from'./context/contextCommands.js';import{agent,assertContextExisting,asyncSequential,checkUpdate,customUserAgent,error,getCommand,proxyEnvsSet,warning}from'./utils.js';import*as a1O from'./defaults.js';import{InquirerHelper}from'./inquirer-helper.js';import{consoleFormat,handleJsonOutput,handleYamlOutput,printAsTable}from'./formatting/console-format-helpers.js';import{getCommandOverview}from'./formatting/command-overview.js';import{CliPortForward}from'./port-forward/index.js';function a1X(){const XW=['--verbose','branches','restores','load','pipelineId','utf-8','askForAddon','type','join','action','addon','=>\x20running\x20command\x20with:\x20','yaml','buildId','help\x20[command]','VERBOSE:\x20Using\x20endpoint\x20->\x20','pop',',\x20NF\x20error\x20id:\x20','../package.json','tag','file','loadAll','askForLogSink','OPTIONAL:\x20','all','region','dmn','\x0a\x09details\x20:','custom-columns=','noDefaults','Unknown\x20input\x20file\x20type:\x20','existsSync','name','getMetricsCommand','askForClusterId','opt','2027910RQgVXT','askForTemplateRun','\x20properties','adn','toUpperCase','VERBOSE:\x20HTTP_PROXY\x20or\x20HTTPS_PROXY\x20environment\x20variable\x20set:\x20tunnelling\x20traffic\x20through\x20HTTP\x20proxy.','Display\x20help\x20for\x20command','repo','askForSubdomain','File\x20to\x20load\x20resource\x20json\x20from','project','secrets','parse','subdomainId','version','vol','templateId','pln','data','79562wmqUXw','force','green','concat','call','opts','getCurrentProjectName','moveCursor','credentials','askForJob','portFwdCmd','endpoints','startsWith','login','split','svc','askForBackupDestination','output','projectId','deleteWarningPrompt','File\x20does\x20not\x20exist:\x20','askForBuild','sort','Documentation:\x20','keys','subdomainPath','API\x20request\x20failed\x0a\x09Message:\x20','url','downloadCmd','argv','toLowerCase','stdout','error','backupId','askForCredentials','isPaginatedEndpoint','getCurrentJobName','list','getCurrentServiceName','cursor','boolean','askGeneric','branch','volumeId','770GirBPB','option','repositories','inv','\x20--','-f,\x20--file\x20<file-path>','Failed\x20to\x20validate\x20input\x20(incorrect\x20format):\x20','alias','endsWith','24954svyXZP','secretId','stringify','getOwnPropertyNames','path','secret','map','bind','docsTagsPath','askForAddonBackup','trim','toString','execCmd','Northflank\x20cli\x20version:\x20','askForVolume','readFileSync','description','plan','7irlDis','JSON-formatted\x20resource\x20definition,\x20takes\x20precedence\x20over\x20\x22--file\x22','count','370540yiDmQo','rgn','logs','Error\x20occured\x20while\x20trying\x20to\x20run\x20command,\x20error:\x20','invoice','askForProject','base','job','get','askForTemplate','length','backup-destination','paginationArgs','Unknown\x20input\x20format.\x20Not\x20valid\x20json\x20and\x20not\x20valid\x20yaml.','hasNextPage','request','clearLine','credential','(HTTP\x20status\x20code:\x20','there\x20are\x20more\x20rows,\x20load?','projects','tags','jobId','some','quiet',',\x20-','page','credentialId','askForPipeline','backupDestinationId','enablePositionalOptions','logSinkId','aliases','helpCommand','statusText','Update\x20Northflank\x20','plans','italic','askForSecret','subdomain','nonInteractiveEndpoint','contextProvider','body','addCommand','runs','volumes','13322853WBIeyj','VERBOSE:\x20Request\x20body\x20->\x20','askForJobRun','3357776oUUXXv','repos','includes','isArray','service','2050940PUjozq','backups','rawResponse','regions','\x0a>\x20Token\x20permissions\x20required:\x20','resourceTagId','addHelpText','update','/docs/v1/api/','exitCode','addonId','underline','log','Print\x20the\x20current\x20version\x20of\x20the\x20Northflank\x20cli','domainId','query','Get\x20information\x20about\x20Northflank\x20','cred','serviceId','askForTag','brn','skipValidation','askForDomain','pagination','backup','askForSubdomainPath','template','Options\x20\x27loadAll\x27\x20can\x20not\x20be\x20combined\x20with\x20\x27page\x27\x20or\x20\x27cursor\x27','getLogsCommand','domain','jobs','yml','find','templates','clusterId','Resource\x20was\x20not\x20deleted.','method','required','uploadCmd','json','defaults'];a1X=function(){return XW;};return a1X();}import{CliExec}from'./exec/index.js';function a1j(X,j){const V=a1X();return a1j=function(H,O){H=H-0x1c7;let F=V[H];return F;},a1j(X,j);}import{CliLogs}from'./logs/index.js';import{CliMetrics}from'./metrics/index.js';import{CliFileCopy}from'./copy/index.js';import{isEqual,has,set,kebabCase,upperFirst,isString,omit}from'lodash-es';import a1F from'js-yaml';import{readFileSync}from'fs';import{fileURLToPath}from'url';import{dirname,join}from'path';const __filename=fileURLToPath(import.meta[a1X8(0x273)]),__dirname=dirname(__filename),pgk=JSON['parse'](readFileSync(join(__dirname,a1X8(0x233)),a1X8(0x226)));export const getProgram=X=>{const X9=a1X8,j=new Command('northflank');j['description']('Manage\x20your\x20Northflank\x20resources\x20from\x20the\x20command\x20line'),j[X9(0x1e0)](!![]),j['version'](X9(0x29a)+a1H[X9(0x203)](pgk[X9(0x253)]),'-v,\x20--version',X9(0x205));const V=new ApiClient(X,{'throwErrorOnHttpErrorCode':![],'customUserAgent':customUserAgent,'agent':agent}),H=new CliContext(V,agent),O=new CliPortForward(X,agent),F=new CliExec(X,agent),h=new CliFileCopy(X,agent),P=new CliLogs(X,agent),o=new CliMetrics(X,agent);return j['addCommand'](O[X9(0x262)]),j[X9(0x1ed)](F[X9(0x299)]),j[X9(0x1ed)](h[X9(0x274)]),j[X9(0x1ed)](h[X9(0x21e)]),j['addCommand'](H[X9(0x265)]),j['addCommand'](H['contexts']),generateCommands(V,V[X9(0x263)],j,P,o),j[X9(0x1ed)](getCommandOverview(j)),j[X9(0x1e3)](X9(0x22f),'Display\x20help\x20for\x20command'),j['helpOption'](undefined,X9(0x24b)),j;};((async()=>{const XX=a1X8;try{const X=new ApiClientFileContextProvider();await checkUpdate(X);const j=getProgram(X);await j['parseAsync'](process[XX(0x275)]);}catch(V){error(XX(0x2a5)+V['message']),process['argv'][XX(0x218)](H=>H===XX(0x221))&&console[XX(0x204)](V),process[XX(0x201)]=0x1;}})());function isListCommand(X){const Xj=a1X8,j=[[Xj(0x1ca),Xj(0x22b),Xj(0x1f9)],[Xj(0x1ca),Xj(0x1c9),Xj(0x1ee)]];return X['find'](V=>V===Xj(0x27d))||j[Xj(0x1d9)](V=>isEqual(X,V));}function generateCommands(X,j,V,H,O,F=a1O[a1X8(0x220)],h=[]){const XV=a1X8,P=new InquirerHelper(new ApiClient(X[XV(0x1eb)],{'throwErrorOnHttpErrorCode':!![],'customUserAgent':customUserAgent,'agent':agent}));function o(S,y){const XH=XV;return S[XH(0x21d)]!==![]&&y===undefined;}function C(S,y){const XO=XV,{opt:e,name:A}=S,l=e['default'],T=o(e,l),W=g=>g['length']>0x1?'--'+g:'-'+g,v=e?.[XO(0x28b)],G=v?Array[XO(0x1f6)](v)?'-'+v?.[XO(0x293)](g=>W(g))[XO(0x229)](XO(0x1db))+',':''+W(v):'',d=T?'':XO(0x238),x=typeof e[XO(0x228)]===XO(0x280)||e['type']===XO(0x280)?G+'\x20--'+A:G+XO(0x288)+A+'\x20<'+A[XO(0x249)]()+'>',M=d+e['description'];y[XO(0x285)](x[XO(0x297)](),M,l);}function B(S,y){const XF=XV;if(y['commands'][XF(0x1d9)](e=>e[XF(0x241)]()===XF(0x2a4)))return;isEqual(S,['get',XF(0x1f7)])&&(y[XF(0x1ed)](H['getLogsCommand'](XF(0x1f7))),y[XF(0x1ed)](O[XF(0x242)](XF(0x1f7))),y[XF(0x1ed)](H[XF(0x214)](XF(0x1f7),!![])),y[XF(0x1ed)](O[XF(0x242)](XF(0x1f7),!![]))),isEqual(S,[XF(0x1ca),XF(0x1c9)])&&(y[XF(0x1ed)](H['getLogsCommand'](XF(0x1c9))),y[XF(0x1ed)](O['getMetricsCommand'](XF(0x1c9))),y[XF(0x1ed)](H[XF(0x214)](XF(0x1c9),!![])),y[XF(0x1ed)](O[XF(0x242)](XF(0x1c9),!![]))),isEqual(S,[XF(0x1ca),'addon'])&&(y['addCommand'](H[XF(0x214)](XF(0x22b))),y['addCommand'](O[XF(0x242)](XF(0x22b)))),isEqual(S,[XF(0x1ca),'addon',XF(0x210)])&&y['addCommand'](H['getLogsCommand'](XF(0x22b),![],!![])),isEqual(S,[XF(0x1ca),XF(0x22b),XF(0x223)])&&y[XF(0x1ed)](H[XF(0x214)](XF(0x22b),![],!![],!![]));}return Object[XV(0x290)](F)['forEach'](S=>{const Xh=XV,y=j[S],e=F[S],A=h[Xh(0x25b)]([S]);function l(b,E){const XP=Xh,t=Object[XP(0x290)](b||{});t['map'](Z=>{return{'name':Z,'opt':b[Z]};})[XP(0x26e)]((Z,w)=>!o(Z[XP(0x244)])?!o(w[XP(0x244)])?0x0:0x1:-0x1)['forEach'](Z=>{C(Z,E);});}function T(b,E){const Xo=Xh,t=[[Xo(0x24f),Xo(0x1d6),'prj'],[Xo(0x1f7),'services',Xo(0x267)],[Xo(0x260),Xo(0x1d3),Xo(0x209)],[Xo(0x22b),'addons',Xo(0x248)],['job',Xo(0x216)],[Xo(0x29e),Xo(0x1e6),Xo(0x256)],[Xo(0x23a),Xo(0x1fb),Xo(0x2a3)],[Xo(0x215),'domains',Xo(0x23b)],[Xo(0x292),Xo(0x250),'scrt'],[Xo(0x1ef),'volume',Xo(0x254)],[Xo(0x222),Xo(0x282),Xo(0x20c)],[Xo(0x2a6),'invoices',Xo(0x287)],[Xo(0x212),Xo(0x219),'tpl'],[Xo(0x1f4),'repository',Xo(0x286),Xo(0x24c)],[Xo(0x1cd),'backup-destinations'],[Xo(0x234),Xo(0x1d7)]],Z=t['find'](w=>w['includes'](E));if(Z!==undefined)b[Xo(0x1e2)](Z['filter'](w=>w!==E));}async function W(b){const XC=Xh,E={},{contextProvider:t}=X,Z=A[XC(0x1f5)]('delete'),w=b[XC(0x23e)]===!![];async function N(p,m,k){const XB=XC;if(has(e['opt']?.[XB(0x291)]??{},p)){const I=!w&&!Z&&k?k():undefined,K=b[p]||I||await m();set(E,p,K);}}return await asyncSequential(Object['entries'](e[XC(0x244)]?.[XC(0x291)]??{}),async([p,m])=>{const Xs=XC,k=E?.[Xs(0x26a)],I=E?.[Xs(0x255)];switch(p){case Xs(0x26a):return await N('projectId',P[Xs(0x1c7)][Xs(0x294)](P),t[Xs(0x25e)]['bind'](t));case Xs(0x20a):return await N(Xs(0x20a),P['askForService'](k)[Xs(0x294)](P),t[Xs(0x27e)][Xs(0x294)](t));case Xs(0x202):return await N(Xs(0x202),P[Xs(0x227)](k)[Xs(0x294)](P));case Xs(0x1d8):return await N(Xs(0x1d8),P[Xs(0x261)](k)[Xs(0x294)](P),t[Xs(0x27c)]['bind'](t));case'runId':return await N('runId',P[Xs(0x1f2)](E[Xs(0x1d8)],k,![])[Xs(0x294)](P));case'secretId':return await N(Xs(0x28e),P[Xs(0x1e8)](k)['bind'](P));case Xs(0x215):case Xs(0x206):return await N(Xs(0x215),P[Xs(0x20e)][Xs(0x294)](P));case'credentialId':return await N(Xs(0x1dd),P[Xs(0x27a)][Xs(0x294)](P));case Xs(0x283):return await N(Xs(0x283),P[Xs(0x29b)](k)['bind'](P));case'subdomain':return await N(Xs(0x1e9),P['askForSubdomain'](E[Xs(0x215)])['bind'](P));case Xs(0x252):return await N(Xs(0x252),P[Xs(0x24d)](E[Xs(0x206)])[Xs(0x294)](P));case Xs(0x271):return await N(Xs(0x271),P[Xs(0x211)](E['domain'],E[Xs(0x1e9)]??E[Xs(0x252)])[Xs(0x294)](P));case Xs(0x279):return await N('backupId',P[Xs(0x296)](k,E[Xs(0x202)])[Xs(0x294)](P));case Xs(0x22e):return await N('buildId',P[Xs(0x26d)](k,E[Xs(0x20a)],E[Xs(0x1d8)])[Xs(0x294)](P));case Xs(0x255):return await N('templateId',P[Xs(0x1cb)]()[Xs(0x294)](P));case'templateRunId':return await N('templateRunId',P[Xs(0x246)](I)[Xs(0x294)](P));case'logSinkId':return await N(Xs(0x1e1),P[Xs(0x237)]()[Xs(0x294)](P));case Xs(0x225):return await N(Xs(0x225),P[Xs(0x1de)](k)[Xs(0x294)](P));case'resourceTagId':return await N(Xs(0x1fd),P[Xs(0x20b)]()['bind'](P));case Xs(0x1df):return await N(Xs(0x1df),P[Xs(0x268)]()[Xs(0x294)](P));case Xs(0x21a):return await N(Xs(0x21a),P[Xs(0x243)]()['bind'](P));default:return await N(p,P[Xs(0x281)](p,m?.[Xs(0x29d)])[Xs(0x294)](P));}}),E;}async function v(b){const XS=Xh,E={},t=e[XS(0x244)]?.[XS(0x27b)]?a1O[XS(0x1ce)]:{},Z={...e[XS(0x244)]?.[XS(0x207)]??{},...t},w=Object[XS(0x270)](Z)['filter'](N=>N!==XS(0x236));return await asyncSequential(w,async N=>{if(b[N]!==undefined)return set(E,N,b[N]);}),E;}function G(){const Xy=Xh;switch(A[0x0]){case Xy(0x1ca):return Xy(0x208)+(A[0x1]||'resource')+'s';case Xy(0x1ff):return Xy(0x1e5)+(A[0x1]||'resource')+Xy(0x247);default:return upperFirst(S)+'\x20Northflank\x20resources';}}function d(b,E){const Xe=Xh;if(!E){const K=getCommand()[Xe(0x241)](kebabCase(S))[Xe(0x29d)](G());return T(K,S),K;}const t=b?.['requiredPermissions']?a1H[Xe(0x1e7)](Xe(0x1fc)+b['requiredPermissions']):'',Z=X['contextProvider']['getCurrentContext'](),w=Z!==undefined&&e?.[Xe(0x244)]?.[Xe(0x295)]!==undefined,N=Z?.['host']['replace']('api.',''),p=w?Xe(0x26f)+N+Xe(0x200)+e?.[Xe(0x244)]?.[Xe(0x295)]:'',m=b?.[Xe(0x29d)]||'',k=getCommand(!![])[Xe(0x241)](kebabCase(S))[Xe(0x29d)](m)[Xe(0x1fe)]('after',[t,p][Xe(0x229)]('\x0a'));T(k,S);(e['opt']?.[Xe(0x1ec)]||e[Xe(0x244)]?.[Xe(0x1ea)])&&(k[Xe(0x285)](Xe(0x289),Xe(0x24e)),k['option']('-i,\x20--input\x20<resource-def>',Xe(0x2a0)));l(e[Xe(0x244)]?.[Xe(0x291)],k),l(e[Xe(0x244)]?.[Xe(0x207)],k);const I=e[Xe(0x244)]?.[Xe(0x27b)];return I&&l(a1O[Xe(0x1ce)],k),l(e[Xe(0x244)]?.[Xe(0x1c8)],k),k[Xe(0x22a)](async()=>{const XA=Xe;assertContextExisting(X);const L=k[XA(0x25d)]();L?.['verbose']&&proxyEnvsSet&&warning(XA(0x24a));const a=L[XA(0x1dc)]!==undefined||L[XA(0x27f)]!==undefined;if(L['loadAll']===!![]&&a)throw new Error(XA(0x213));const r=L?.['output'],R=r==='json',n=r===XA(0x22d)||r===XA(0x217),D=await W(L);P['setPathVars'](D);const Y=await v(L),u=Object[XA(0x270)](e[XA(0x244)]?.[XA(0x291)]??{})['map'](q=>q+'='+a1H[XA(0x25a)](D[q]))['join'](',\x20');if(u[XA(0x1cc)]>0x0&&!R&&!n){const q=XA(0x22c)+u;console[XA(0x204)](q);}const Q=e[XA(0x244)]?.[XA(0x1ec)]||e[XA(0x244)]?.[XA(0x1ea)]?await s(L,e,A):undefined;if(!L[XA(0x259)]&&A[XA(0x1f5)]('delete')&&!await P[XA(0x26b)]()){warning(XA(0x21b));return;}const f=I&&(L[XA(0x236)]||(L[XA(0x269)]===XA(0x21f)||L[XA(0x269)]===XA(0x22d))&&!a);let z=f&&y instanceof GetApiEndpointPaginated?await y[XA(0x239)]({'parameters':D,'options':Y,'data':Q}):await y[XA(0x25c)]({'parameters':D,'options':{...Y},'data':Q});if(L?.['verbose']){const c=z[XA(0x1d1)];console[XA(0x204)](XA(0x230)+c[XA(0x21c)]['toUpperCase']()+':'+c[XA(0x273)]);if(Q!==undefined)console[XA(0x204)](XA(0x1f1)+Q);}if(z[XA(0x278)]){const {details:i,id:X0,message:X1,status:X2}=z[XA(0x278)],X3=i?XA(0x23c)+JSON[XA(0x28f)](i):'',X4=X0?XA(0x232)+X0:'',X5=XA(0x1d4)+X2+X4+')';throw new Error(XA(0x272)+X1+'\x20'+X5+X3);}let U=0x0;printCallResult(L,R,z[XA(0x257)],n,A,r,![],U,z[XA(0x1fa)]['statusText']);if(!L[XA(0x1da)]&&!f&&!a&&z[XA(0x20f)]?.[XA(0x1d0)])while(z['pagination']?.[XA(0x1d0)]){const X6=await P['askConfirm'](XA(0x1d5));if(X6)process[XA(0x277)][XA(0x25f)](0x0,-0x1),process[XA(0x277)][XA(0x1d2)](0x1),U+=z[XA(0x20f)][XA(0x2a1)],z=await z['pagination']['getNextPage'](),printCallResult(L,R,z['data'],n,A,r,!![],U,z[XA(0x1fa)][XA(0x1e4)]);else return;}}),k;}const x=has(e,Xh(0x244)),M=y,g=d(M,x);B(A,g),V[Xh(0x1ed)](g);const J=omit(e,'opt');Object[Xh(0x270)](J)['length']>0x0&&generateCommands(X,y,g,H,O,J,A);});async function s(S,y,A){const Xl=XV,{input:l,file:T}=S;if(l!==undefined)try{return JSON[Xl(0x251)](l);}catch(W){try{return a1F[Xl(0x224)](l);}catch(v){throw new Error(Xl(0x1cf));}}if(T!==undefined){if(!a1V[Xl(0x240)](T))throw new Error(Xl(0x26c)+T);const G=a1V[Xl(0x29c)](T)[Xl(0x298)]();let x;try{if(isString(G)){if(S[Xl(0x235)][Xl(0x28c)]('.json'))x=JSON['parse'](G);else{if(S[Xl(0x235)][Xl(0x28c)]('.yaml')||S['file']['endsWith'](Xl(0x217)))x=a1F[Xl(0x224)](G);else throw new Error(Xl(0x23f)+S[Xl(0x235)]['split']('.')[Xl(0x231)]());}}else x=G;return x;}catch(M){throw new Error(Xl(0x28a)+M['message']);}}if(y?.['opt']?.[Xl(0x1ea)])throw new Error('Expecting\x20resource\x20input\x20with\x20\x27--input\x27\x20or\x20\x27--file\x27\x20argument');return await P['retrievePayloadViaInteractiveCli'](y,{'cmdPath':A,'skipValidation':S[Xl(0x20d)]});}}const printCallResult=(X,j,V,H,O,F,h,P,o)=>{const XT=a1X8;if(!X?.[XT(0x1da)]){if(j)handleJsonOutput(X?.[XT(0x269)],V);else{if(H)handleYamlOutput(X?.[XT(0x269)],V);else{if(isListCommand(O)){const C=F?.[XT(0x264)](XT(0x23d))?F['replace'](XT(0x23d),'')[XT(0x266)](',')[XT(0x293)](e=>e[XT(0x276)]()):undefined,B=O[O[XT(0x1cc)]-0x1],s=''+B+(B[XT(0x28c)]('s')?'':'s'),S=upperFirst(s),y=has(V,s)?V[s]:V;printAsTable(y,S,C,h,P);}else console['log'](consoleFormat(V,o));}}}};