From 3db527698c8bdbba0802e7bbb74b9a86bb9c3249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Padilla?= Date: Thu, 13 May 2021 19:53:52 -0400 Subject: [PATCH 1/3] Allow specifying an optional runtime argument --- bin/_plugins/profile.js | 31 ++++++++++++++++++++++++------- bin/_plugins/profileOptions.js | 4 ++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/bin/_plugins/profile.js b/bin/_plugins/profile.js index 4907f5b..15c675a 100644 --- a/bin/_plugins/profile.js +++ b/bin/_plugins/profile.js @@ -31,18 +31,18 @@ function onBeforeHandler(context) { var validUntil = new Date(args.profile.openid.valid_until); var now = Date.now(); - if ((validUntil - now) < 5 * 60 * 1000) { - var userAuthenticator = new UserAuthenticator({ + if ((validUntil - now) < 5 * 60 * 1000) { + var userAuthenticator = new UserAuthenticator({ sandboxUrl: args.profile.url, authorizationServer: args.profile.openid.authorization_server, audience: args.profile.openid.audience, clientId: args.profile.openid.client_id, - refreshToken: args.profile.openid.refresh_token, + refreshToken: args.profile.openid.refresh_token, }); return userAuthenticator - .login({ - container: args.profile.container, + .login({ + container: args.profile.container, admin: args.profile.openid.scopes.indexOf('wt:admin') > -1, auth0: args.profile.openid.auth0, profileName: args.profile.name, @@ -78,7 +78,10 @@ function sandboxFromArguments(args, options) { if (args.container && args.url) { try { return resolve(Sandbox.init({ - onBeforeRequest, + onBeforeRequest: [ + onBeforeRequestProxy, + onBeforeRequestRuntime + ], container: args.container, token: args.token, url: args.url, @@ -105,7 +108,7 @@ function sandboxFromArguments(args, options) { return config.getProfile(args.profile); } - function onBeforeRequest(request) { + function onBeforeRequestProxy(request) { const proxy = process.env.http_proxy || process.env.HTTP_PROXY; const result = proxy ? SuperagentProxy(request, proxy) @@ -114,11 +117,25 @@ function sandboxFromArguments(args, options) { return result; } + function onBeforeRequestRuntime(request) { + if (args.runtime) { + return request.set('x-wt-runtime', args.runtime); + } + + return request; + } + function onProfileLoaded(profile) { if (args.container) profile.container = args.container; if (args.url) profile.url = args.url; if (args.token) profile.token = args.token; + if (args.runtime) { + profile.onBeforeRequest = (profile.onBeforeRequest || []).concat( + onBeforeRequestRuntime + ); + } + return profile; } }); diff --git a/bin/_plugins/profileOptions.js b/bin/_plugins/profileOptions.js index fee36dc..682531c 100644 --- a/bin/_plugins/profileOptions.js +++ b/bin/_plugins/profileOptions.js @@ -29,6 +29,10 @@ function onBeforeConfigure(context) { description: 'Set your authorizing webtask token. If you do not have a webtask token, one can be provisioned using `wt init`.', type: 'string', }, + runtime: { + description: 'Runtime version used during execution and persisting of webtasks. Example: node8|node12', + type: 'string' + }, }; node.addOptionGroup('Webtask profile', _.omit(options, _.get(context.node.config, 'profileOptions.hide', []))); From 40ca594114a5630e6d556c3d486692ab0ec53ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Padilla?= Date: Fri, 14 May 2021 11:43:37 -0400 Subject: [PATCH 2/3] Guard against invalid `onBeforeRequest` value --- bin/_plugins/profile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/_plugins/profile.js b/bin/_plugins/profile.js index 15c675a..5c71f07 100644 --- a/bin/_plugins/profile.js +++ b/bin/_plugins/profile.js @@ -131,9 +131,9 @@ function sandboxFromArguments(args, options) { if (args.token) profile.token = args.token; if (args.runtime) { - profile.onBeforeRequest = (profile.onBeforeRequest || []).concat( - onBeforeRequestRuntime - ); + profile.onBeforeRequest = Array.isArray(profile.onBeforeRequest) + ? profile.onBeforeRequest.concat(onBeforeRequestRuntime) + : [onBeforeRequestRuntime]; } return profile; From ec776f79e712369f493635051f1ad0dcd5d1372d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Padilla?= Date: Tue, 18 May 2021 12:19:36 -0400 Subject: [PATCH 3/3] Bump up version to v12.1.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index ac5bdfd..7f7a373 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "wt-cli", - "version": "12.0.0", + "version": "12.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8263c28..ab49d2f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "url": "https://github.com/ggoodman", "twitter": "filearts" }, - "version": "12.0.0", + "version": "12.1.0", "description": "Webtask Command Line Interface", "tags": [ "nodejs",