Skip to content

Commit

Permalink
feat: make sure hooks are created with the disabled flag always set
Browse files Browse the repository at this point in the history
  • Loading branch information
TwelveNights committed Jun 1, 2023
1 parent da5a5f8 commit f92dc99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
7 changes: 2 additions & 5 deletions bin/auth0_create.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ function handleCreate(args) {
args.params = [];
args.meta['auth0-extension'] = 'runtime';
args.meta['auth0-extension-name'] = args.extensionName;

// If updating exising hook, preserve the enabled/disabled state
if (!claims || claims.meta['auth0-extension-disabled'])
args.meta['auth0-extension-disabled'] = '1';
args.meta['auth0-extension-disabled'] = claims ? claims.meta['auth0-extension-disabled'] : '1';

// If wt-compiler specified explicitly, use it. Otherwise use the default per hook type.
if (!args.meta['wt-compiler'])
Expand All @@ -132,7 +129,7 @@ function handleCreate(args) {
action: 'created',
onOutput: function (log, build, url) {
var action = claims ? 'updated' : 'created';
var state = args.meta['auth0-extension-disabled'] ? 'disabled' : 'enabled';
var state = args.meta['auth0-extension-disabled'] === "1" ? 'disabled' : 'enabled';
log(Chalk.green('Auth0 hook ' + action + ' in ' + state + ' state.') +
(state == 'disabled' ? (' To enable this hook to run in production, call:\n\n'
+ Chalk.green('$ auth0 enable ' + args.name)) : ''));
Expand Down
2 changes: 1 addition & 1 deletion bin/auth0_ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function handleListAuth0Extensions(args) {
var record = {
name: json.name,
type: args.extensionName || (webtask.meta && webtask.meta['auth0-extension-name']) || 'N/A',
enabled: !!(webtask.meta && !webtask.meta['auth0-extension-disabled'])
enabled: !!(webtask.meta && webtask.meta['auth0-extension-disabled'] !== "1")
};
if (!types[record.type]) {
types[record.type] = [ record ];
Expand Down
16 changes: 8 additions & 8 deletions bin/auth0_toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function createHandleUpdate(action) {

var profile = args.profile;

return profile.inspectWebtask({
name: args.name,
return profile.inspectWebtask({
name: args.name,
decrypt: true,
meta: true
meta: true
})
.then(onClaims);

Expand All @@ -40,9 +40,9 @@ function createHandleUpdate(action) {
var extensionName = claims.meta['auth0-extension-name'];
if (!extensionName)
return Cli.error.invalid('The ' + args.name + ' webtask is not a an Auth0 hook.');
if (action === 'enable' && !claims.meta['auth0-extension-disabled'])
if (action === 'enable' && claims.meta['auth0-extension-disabled'] !== "1")
return console.log(Chalk.green('The ' + args.name + ' (' + extensionName + ') hook is already enabled.'));
if (action === 'disable' && claims.meta['auth0-extension-disabled'])
if (action === 'disable' && claims.meta['auth0-extension-disabled'] === "1")
return console.log(Chalk.green('The ' + args.name + ' (' + extensionName + ') hook is already disabled.'));

if (action === 'disable') {
Expand All @@ -61,7 +61,7 @@ function createHandleUpdate(action) {
}).then(function (webtasks) {
var toDisable = [];
webtasks.forEach(function (wt) {
if (!wt.meta['auth0-extension-disabled']) {
if (wt.meta['auth0-extension-disabled'] !== "1") {
toDisable.push(toggleExtension(wt.toJSON().name, false));
}
});
Expand All @@ -87,11 +87,11 @@ function createHandleUpdate(action) {
function adjustExtensionClaims(claims, enable) {
if (enable) {
console.log('Enabling hook ' + claims.jtn + '.');
delete claims.meta['auth0-extension-disabled'];
claims.meta['auth0-extension-disabled'] = '0';
}
else {
console.log('Disabling hook ' + claims.jtn + '.');
claims.meta['auth0-extension-disabled'] = '1';
claims.meta['auth0-extension-disabled'] = '1';
}
['jti','ca','iat','webtask_url'].forEach(function (c) { delete claims[c]; });
return claims;
Expand Down

0 comments on commit f92dc99

Please sign in to comment.