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/.
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
]
16 value
= base64
.b64decode(value
)
20 def fetch_secret_from_taskcluster(name
):
21 secrets
= taskcluster
.Secrets({'baseUrl': 'http://taskcluster/secrets/v1'})
22 return secrets
.get(name
)
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')
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__":