Skip to content

Instantly share code, notes, and snippets.

@imbstack
Created February 17, 2017 19:46
Show Gist options
  • Save imbstack/a3bb6ee1a3cbdc5ee07fcf3f493e0884 to your computer and use it in GitHub Desktop.
Save imbstack/a3bb6ee1a3cbdc5ee07fcf3f493e0884 to your computer and use it in GitHub Desktop.
Update Taskcluster Azure Access Scopes
let Promise = require('promise');
let _ = require('lodash');
let taskcluster = require('taskcluster-client');
let auth = new taskcluster.Auth({
credentials: {
clientId: '...',
accessToken: '...',
},
});
function azureStuff(thing) {
return thing.scopes.filter(scope => scope.startsWith('auth:azure-table-access:'));
}
function addNewScopes(thing) {
let newScopes = azureStuff(thing).map(s => s.replace('auth:azure-table-access:', 'auth:azure-table:read-write:'));
thing.scopes = _.union(thing.scopes, newScopes);
}
async function main() {
let clients = _.filter(await auth.listClients(), c => _.some(azureStuff(c)));
let roles = _.filter(await auth.listRoles(), r => _.some(azureStuff(r)));
clients.map(addNewScopes);
roles.map(addNewScopes);
await Promise.all(clients.map(client => {
return auth.updateClient(client.clientId, {
scopes: client.scopes,
description: client.description,
deleteOnExpiration: client.deleteOnExpiration,
expires: client.expires,
});
}));
await Promise.all(roles.map(role => {
return auth.updateRole(role.roleId, {scopes: role.scopes, description: role.description});
}));
}
main().catch(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment