Skip to content

Instantly share code, notes, and snippets.

@imbstack
Created July 9, 2020 21:16
Show Gist options
  • Save imbstack/402ea776aa0f3823681b55cb2559e39a to your computer and use it in GitHub Desktop.
Save imbstack/402ea776aa0f3823681b55cb2559e39a to your computer and use it in GitHub Desktop.
tc secrets backup script
const taskcluster = require('taskcluster-client');
const readline = require('readline');
const s = new taskcluster.Secrets({
rootUrl: process.env.TASKCLUSTER_ROOT_URL,
credentials: {
clientId: process.env.TASKCLUSTER_CLIENT_ID,
accessToken: process.env.TASKCLUSTER_ACCESS_TOKEN,
},
});
// node ./thisscript.js backup | gpg -ear [email protected] > /dev/shm/backup
const backup = async () => {
const extra = {};
do {
const {secrets, continuationToken} = await s.list(extra);
extra.continuationToken = continuationToken;
for (const secret of secrets) {
console.log(JSON.stringify({name: secret, body: await s.get(secret)}));
}
} while (extra.continuationToken);
};
// cat /dev/shm/backup | gpg -d | node ./thisscript.js restore
const restore = async () => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
for await (const line of rl) {
const record = JSON.parse(line);
await s.set(record.name, record.body);
}
};
const main = async () => {
if (process.argv[2] === 'backup') {
await backup();
} else if (process.argv[2] === 'restore') {
await restore();
} else {
throw new Error('Unrecognized input');
}
};
main().catch(console.error);
@djmitche
Copy link

djmitche commented Jul 9, 2020

Awesome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment