Created
February 17, 2017 19:46
-
-
Save imbstack/a3bb6ee1a3cbdc5ee07fcf3f493e0884 to your computer and use it in GitHub Desktop.
Update Taskcluster Azure Access Scopes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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