Created
July 9, 2020 21:16
-
-
Save imbstack/402ea776aa0f3823681b55cb2559e39a to your computer and use it in GitHub Desktop.
tc secrets backup script
This file contains hidden or 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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome :)