Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions bin/_plugins/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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 = Array.isArray(profile.onBeforeRequest)
? profile.onBeforeRequest.concat(onBeforeRequestRuntime)
: [onBeforeRequestRuntime];
}

return profile;
}
});
Expand Down
4 changes: 4 additions & 0 deletions bin/_plugins/profileOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])));
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down