Mike Frysinger | d03e6b5 | 2019-08-03 12:49:01 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2 |
Xixuan Wu | 94388e5 | 2019-04-10 14:38:58 -0700 | [diff] [blame] | 2 | |
| 3 | """ |
| 4 | Fetch credentials used by lab tools from Google storage. |
| 5 | |
| 6 | Usage? Just run it. |
| 7 | utils/download_creds.py |
| 8 | """ |
| 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | |
| 13 | import common |
| 14 | from chromite.lib import gs |
| 15 | from chromite.lib import osutils |
| 16 | |
| 17 | from autotest_lib.utils import external_packages |
| 18 | |
| 19 | |
| 20 | CRED_DIR = 'creds' |
| 21 | RUN_SUITE_SERVICE_ACCOUNT = ( |
| 22 | 'gs://chromeos-proxy.appspot.com/skylab-trampoline.json') |
| 23 | |
| 24 | def _fetch_run_suite_creds(ctx, creds_dir): |
| 25 | """Download creds for labtools run_suites. |
| 26 | |
| 27 | Args: |
| 28 | ctx: A gs.GSContext object. |
| 29 | creds_dir: A string path. |
| 30 | """ |
| 31 | cred_file = os.path.join(creds_dir, |
| 32 | 'skylab_trampoline_service_account.json') |
| 33 | ctx.Copy(RUN_SUITE_SERVICE_ACCOUNT, cred_file) |
| 34 | |
| 35 | |
| 36 | def main(): |
| 37 | """Download credentials.""" |
| 38 | autotest_dir = external_packages.find_top_of_autotest_tree() |
| 39 | creds_dir = os.path.join(autotest_dir, CRED_DIR) |
| 40 | osutils.SafeMakedirs(creds_dir) |
| 41 | ctx = gs.GSContext() |
| 42 | _fetch_run_suite_creds(ctx, creds_dir) |
| 43 | |
| 44 | |
| 45 | if __name__ == '__main__': |
| 46 | sys.exit(main()) |