Comparing version 2.9.20 to 3.0.1
25
aka.js
@@ -646,2 +646,8 @@ #!/usr/bin/env node | ||
if (argv._ && argv._[0] && (argv._[0] === 'apps:create' || argv._[0] === 'create')) { | ||
// Support situations where a user may not specify a space but include it in the name of the app. | ||
if((typeof(argv.space) === "undefined" || argv.space === null) && argv.NAME && argv.NAME.includes("-")) { | ||
let parts = argv.NAME.split("-"); | ||
argv.NAME = parts[0]; | ||
argv.space = parts.slice(1).join("-"); | ||
} | ||
if (!argv.s && !argv.space) { | ||
@@ -656,5 +662,2 @@ argv.s = argv.space = "~$select_space$~"; | ||
} | ||
if (!argv.d && !argv.description) { | ||
argv.d = argv.description = "~$select_description$~"; | ||
} | ||
} | ||
@@ -718,11 +721,2 @@ } | ||
if (argv.description === "~$select_description$~") { | ||
questions.push({ | ||
type: 'input', | ||
name: 'description', | ||
message: 'Enter a description for your app (optional)', | ||
suffix: ':', | ||
}); | ||
} | ||
if (questions.length !== 0) { | ||
@@ -749,8 +743,3 @@ console.log(); | ||
} | ||
if (answers.description) { | ||
argv.description = argv.d = answers.description; | ||
} else if (argv.d === '~$select_description$~') { | ||
argv.description = undefined; | ||
argv.d = undefined; | ||
} | ||
argv.description = argv.d = answers.description; | ||
} | ||
@@ -757,0 +746,0 @@ } |
{ | ||
"name": "akkeris", | ||
"version": "2.9.20", | ||
"version": "3.0.1", | ||
"description": "Akkeris CLI", | ||
@@ -5,0 +5,0 @@ "main": "aka.js", |
@@ -14,3 +14,7 @@ "use strict" | ||
}).join(' ') | ||
return ' ***' + label + ':*** ' + filter.options[opt]; | ||
if(Array.isArray(filter.options[opt])) { | ||
return ' ***' + label + ':*** ' + filter.options[opt].join(", "); | ||
} else { | ||
return ' ***' + label + ':*** ' + filter.options[opt]; | ||
} | ||
}).join('\n')} | ||
@@ -24,2 +28,12 @@ `; | ||
***Filter:*** ${fa.filter.name} | ||
${Object.keys(fa.filter.options).map((opt) => { | ||
let label = opt.replace('_', ' ').split(' ').map((x) => { | ||
return x[0].toUpperCase() + x.substring(1) | ||
}).join(' ') | ||
if(Array.isArray(fa.filter.options[opt])) { | ||
return ' ***' + label + ':*** ' + fa.filter.options[opt].join(", "); | ||
} else { | ||
return ' ***' + label + ':*** ' + fa.filter.options[opt]; | ||
} | ||
}).join('\n')} | ||
${Object.keys(fa.options).map((opt) => { | ||
@@ -56,3 +70,16 @@ let label = opt.replace('_', ' ').split(' ').map((x) => { | ||
} | ||
options = {jwks_uri:args['jwt-jwks-uri'], issuer:args['jwt-issuer'], audiences:args['jwt-audiences']} | ||
options = { | ||
"jwks_uri":args['jwt-jwks-uri'], | ||
"issuer":args['jwt-issuer'], | ||
"audiences":args['jwt-audiences'], | ||
} | ||
} else if (args.type === "cors") { | ||
options = { | ||
"allow_origin":args['cors-allow-origin'], | ||
"allow_methods":args['cors-allow-methods'], | ||
"allow_headers":args['cors-allow-headers'], | ||
"expose_headers":args['cors-expose-headers'], | ||
"max_age":args['cors-max-age'], | ||
"allow_credentials":args['cors-allow-credentials'], | ||
} | ||
} else { | ||
@@ -70,2 +97,38 @@ task.end('error'); | ||
async function update(appkit, args) { | ||
let task = appkit.terminal.task(`Updating http filter **⬢ ${args.FILTER_NAME}** ###(changes take place when an attached app deploys)###`); | ||
task.start() | ||
try { | ||
let options = {} | ||
if(args.type === "jwt") { | ||
if(!args['jwt-jwks-uri'] || !args['jwt-issuer']) { | ||
task.end('error'); | ||
return appkit.terminal.error(new Error('A JWT http filter requires options "jwt-jwks-uri" and "jwt-issuer" be set. It may optionally have one (or more) "audiences".')) | ||
} | ||
options = { | ||
"jwks_uri":args['jwt-jwks-uri'], | ||
"issuer":args['jwt-issuer'], | ||
"audiences":args['jwt-audiences'], | ||
} | ||
} else if (args.type === "cors") { | ||
options = { | ||
"allow_origin":args['cors-allow-origin'], | ||
"allow_methods":args['cors-allow-methods'], | ||
"allow_headers":args['cors-allow-headers'], | ||
"expose_headers":args['cors-expose-headers'], | ||
"max_age":args['cors-max-age'], | ||
"allow_credentials":args['cors-allow-credentials'], | ||
} | ||
} else { | ||
task.end('error'); | ||
return appkit.terminal.error(new Error('The specified filter type was invalid, the supported options are: jwt')) | ||
} | ||
await appkit.api.put(JSON.stringify({"type":args.type, "name":args.FILTER_NAME, options, description:args.description, organization:args.org}),`/filters/${args.FILTER_NAME}`) | ||
} catch (e) { | ||
task.end('error'); | ||
return appkit.terminal.error(e); | ||
} | ||
task.end('ok') | ||
} | ||
async function destroy(appkit, args) { | ||
@@ -94,6 +157,2 @@ let del = async (input) => { | ||
function update(appkit, args) { | ||
// TODO | ||
} | ||
async function attach(appkit, args) { | ||
@@ -112,2 +171,5 @@ let attach = async (input) => { | ||
} | ||
if (args.includes && Array.isArray(args.includes)) { | ||
options.includes = args.includes | ||
} | ||
await appkit.api.post(JSON.stringify({"filter":{"id":filter_info.id}, options}),`/apps/${args.app}/filters`); | ||
@@ -127,13 +189,54 @@ } catch (e) { | ||
async function attach_update(appkit, args) { | ||
let attach_update = async (input) => { | ||
if(input !== args.app) { | ||
return appkit.terminal.soft_error(`Confirmation did not match !!${args.app}!!. Aborted.`); | ||
} | ||
let task = appkit.terminal.task(`Updating http filter attachment **Ⴤ ${args.FILTER_ATTACHMENT_ID}** on ##⬢ ${args.app}##`); | ||
task.start() | ||
try { | ||
let filter_info = await appkit.api.get(`/apps/${args.app}/filters/${args.FILTER_ATTACHMENT_ID}`) | ||
let options = {} | ||
if (args.excludes && Array.isArray(args.excludes)) { | ||
options.excludes = args.excludes | ||
} | ||
if (args.includes && Array.isArray(args.includes)) { | ||
options.includes = args.includes | ||
} | ||
await appkit.api.put(JSON.stringify({"filter":{"id":filter_info.filter.id}, options}),`/apps/${args.app}/filters/${args.FILTER_ATTACHMENT_ID}`); | ||
} catch (e) { | ||
task.end('error'); | ||
return appkit.terminal.error(e); | ||
} | ||
task.end('ok') | ||
} | ||
if(args.confirm) { | ||
await attach(args.confirm); | ||
} else { | ||
appkit.terminal.confirm(` ~~▸~~ !!DANGER ZONE!!: This feature is still in beta, and updating this filter attachment on **⬢ ${args.app}** may result in instability.\n ~~▸~~ Before continuing ensure you've read ##https://github.com/akkeris/akkeris/issues/9## and have implemented its recommendations.\n ~~▸~~ To proceed, type !!${args.app}!! or re-run this command with !!--confirm ${args.app}!!\n`, attach_update); | ||
} | ||
} | ||
async function detach(appkit, args) { | ||
let task = appkit.terminal.task(`Detaching **Ⴤ ${args.FILTER_ATTACHMENT_ID}**`); | ||
task.start(); | ||
try { | ||
await appkit.api.delete(`/apps/${args.app}/filters/${args.FILTER_ATTACHMENT_ID}`); | ||
} catch (e) { | ||
task.end('error'); | ||
return appkit.terminal.error(e); | ||
let del = async (input) => { | ||
if(input !== args.app) { | ||
return appkit.terminal.soft_error(`Confirmation did not match !!${args.app}!!. Aborted.`); | ||
} | ||
let task = appkit.terminal.task(`Detaching **Ⴤ ${args.FILTER_ATTACHMENT_ID}**`); | ||
task.start(); | ||
try { | ||
await appkit.api.delete(`/apps/${args.app}/filters/${args.FILTER_ATTACHMENT_ID}`); | ||
} catch (e) { | ||
task.end('error'); | ||
return appkit.terminal.error(e); | ||
} | ||
task.end('ok') | ||
}; | ||
if(args.confirm) { | ||
await del(args.confirm); | ||
} else { | ||
appkit.terminal.confirm(` ~~▸~~ WARNING: This will detach **⬢ ${args.FILTER_ATTACHMENT_ID}** from app ${args.app}.\n ~~▸~~ To proceed, type !!${args.app}!! or re-run this command with !!--confirm ${args.app}!!\n`, del); | ||
} | ||
task.end('ok') | ||
} | ||
module.exports = { | ||
@@ -148,2 +251,3 @@ init:function(appkit) { | ||
} | ||
let filters_create_option = { | ||
@@ -164,3 +268,3 @@ 'description':{ | ||
'alias':'t', | ||
'choices':['jwt'], | ||
'choices':['jwt','cors'], | ||
'demand':true, | ||
@@ -179,5 +283,87 @@ 'description':'The type of http filter.' | ||
'array':true, | ||
'description':'One or more jwt audiences to sue for a JWT oauth filter.' | ||
'description':'One or more jwt audiences to use for a JWT oauth filter (optional if type=jwt).' | ||
}, | ||
'cors-allow-origin':{ | ||
'array':true, | ||
'description':'The allowed origins for the CORS filter (optional if type=cors)' | ||
}, | ||
'cors-allow-methods':{ | ||
'array':true, | ||
'description':'The allowed HTTP methods for the CORS filter (optional if type=cors)' | ||
}, | ||
'cors-expose-headers':{ | ||
'array':true, | ||
'description':'The allowed HTTP headers for the CORS filter (optional if type=cors)' | ||
}, | ||
'cors-allow-headers':{ | ||
'array':true, | ||
'description':'The allowed HTTP headers in the request (optional if type=cors)' | ||
}, | ||
'cors-max-age':{ | ||
'number':true, | ||
'description':'The age (in seconds) the CORS filter may be cached (optional if type=cors)' | ||
}, | ||
'cors-allow-credentials':{ | ||
'boolean':true, | ||
'description':'Whether credentials are allowed to be sent in the CORS filter (optional if type=cors)', | ||
} | ||
} | ||
let filters_update_option = { | ||
'description':{ | ||
'alias':'d', | ||
'string':true, | ||
'demand':true, | ||
'description':'The description used for the http filter.' | ||
}, | ||
'org':{ | ||
'alias':'o', | ||
'string':true, | ||
'demand':true, | ||
'description':'The name of the organization who owns this filter.' | ||
}, | ||
'type':{ | ||
'alias':'t', | ||
'choices':['jwt','cors'], | ||
'demand':true, | ||
'description':'The type of http filter.' | ||
}, | ||
'jwt-issuer':{ | ||
'string':true, | ||
'description':'The issuer to use for a JWT oauth filter (required if type=jwt).' | ||
}, | ||
'jwt-jwks-uri':{ | ||
'string':true, | ||
'description':'The jwks uri to use for a JWT oauth filter (required if type=jwt).' | ||
}, | ||
'jwt-audiences':{ | ||
'array':true, | ||
'description':'One or more jwt audiences to use for a JWT oauth filter (optional if type=jwt).' | ||
}, | ||
'cors-allow-origin':{ | ||
'array':true, | ||
'description':'The allowed origins for the CORS filter (optional if type=cors)' | ||
}, | ||
'cors-allow-methods':{ | ||
'array':true, | ||
'description':'The allowed HTTP methods for the CORS filter (optional if type=cors)' | ||
}, | ||
'cors-expose-headers':{ | ||
'array':true, | ||
'description':'The exposed HTTP headers returned in the response (optional if type=cors)' | ||
}, | ||
'cors-allow-headers':{ | ||
'array':true, | ||
'description':'The allowed HTTP headers in the request (optional if type=cors)' | ||
}, | ||
'cors-max-age':{ | ||
'number':true, | ||
'description':'The age (in seconds) the CORS filter may be cached (optional if type=cors)' | ||
}, | ||
'cors-allow-credentials':{ | ||
'boolean':true, | ||
'description':'Whether credentials are allowed to be sent in the CORS filter (optional if type=cors)', | ||
} | ||
} | ||
let filters_attach = { | ||
@@ -187,4 +373,9 @@ 'excludes':{ | ||
'array':true, | ||
'description':'One or more relative path prefixes to exclude from the filter (e.g., /test would exclude /test/foo and /test).' | ||
'description':'One or more relative path prefixes to exclude from the filter (availble only on JWT filters).' | ||
}, | ||
'includes':{ | ||
'alias':'i', | ||
'array':true, | ||
'description':'One or more relative path prefixes to explicitly include (otherwise everything is included, only on JWT filters).' | ||
}, | ||
'app':{ | ||
@@ -203,2 +394,3 @@ 'alias':'a', | ||
} | ||
let require_app_option = { | ||
@@ -212,2 +404,3 @@ 'app':{ | ||
} | ||
let optional_app = { | ||
@@ -225,6 +418,8 @@ 'app':{ | ||
.command('filters:create FILTER_NAME', 'Create a new http filter', filters_create_option, create.bind(null, appkit)) | ||
.command('filters:update FILTER_NAME', 'Update an existing http filter', filters_update_option, update.bind(null, appkit)) | ||
.command('filters:destroy FILTER_NAME', 'Destroy an http filter', confirm_option, destroy.bind(null, appkit)) | ||
//.command('filters:update FILTER_NAME [options..]', 'Update an http filter', {}, update.bind(null, appkit)) | ||
.command('apps:filters:attach FILTER_NAME', 'Attach an http filter to an app', filters_attach, attach.bind(null, appkit)) | ||
.command('apps:filters:detach FILTER_ATTACHMENT_ID', 'Attach an http filter to an app', require_app_option, detach.bind(null, appkit)) | ||
.command('apps:filters:detach FILTER_ATTACHMENT_ID', 'Detach an http filter to an app', {...require_app_option, ...confirm_option}, detach.bind(null, appkit)) | ||
.command('apps:filters:update FILTER_ATTACHMENT_ID', 'Update an http filter attachment on an app', filters_attach, attach_update.bind(null, appkit)) | ||
.command('apps:filters', 'List http filters currently on an app', require_app_option, list_attachments.bind(null, appkit)) | ||
@@ -231,0 +426,0 @@ // aliases |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
259096
6786