[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/88 - Add Default +...
[gecko.git] / mobile / android / fenix / automation / taskcluster / get-secret.py
blob1e8ca6314a6c439bc252d8b3a7734372a16090e9
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import argparse
6 import base64
7 import os
8 import taskcluster
11 def write_secret_to_file(path, data, key, base64decode=False):
12 path = os.path.join(os.path.dirname(__file__), '../../' + path)
13 with open(path, 'w') as f:
14 value = data['secret'][key]
15 if base64decode:
16 value = base64.b64decode(value)
17 f.write(value)
20 def fetch_secret_from_taskcluster(name):
21 secrets = taskcluster.Secrets({'baseUrl': 'http://taskcluster/secrets/v1'})
22 return secrets.get(name)
25 def main():
26 parser = argparse.ArgumentParser(
27 description='Fetch a taskcluster secret value and save it to a file.')
29 parser.add_argument('-s', dest="secret", action="store", help="name of the secret")
30 parser.add_argument('-k', dest='key', action="store", help='key of the secret')
31 parser.add_argument('-f', dest="path", action="store", help='file to save secret to')
32 parser.add_argument(
33 '--decode', dest="decode", action="store_true", default=False,
34 help='base64 decode secret before saving to file'
37 result = parser.parse_args()
39 secret = fetch_secret_from_taskcluster(result.secret)
40 write_secret_to_file(result.path, secret, result.key, result.decode)
43 if __name__ == "__main__":
44 main()