|
19 | 19 |
|
20 | 20 | If being run as part of a Travis build for a merged commit, the |
21 | 21 | encrypted `key.json` file need be decrypted before running tests. |
| 22 | +
|
| 23 | +Before encrypting: |
| 24 | +
|
| 25 | +* Visit ``https://github.com/settings/tokens/new``, get a token, |
| 26 | + and store the token in travis.token file. |
| 27 | +* Visit |
| 28 | + ``https://console.cloud.google.com/apis/credentials?project={PROJ}`` |
| 29 | +* Click "Create credentials >> Service account key", select your |
| 30 | + service account and create a JSON key (we'll call it ``key.json``) |
| 31 | +
|
| 32 | +Encrypt the file via:: |
| 33 | +
|
| 34 | +$ travis login --github-token=$(cat travis.token) |
| 35 | +$ travis encrypt-file --repo=GoogleCloudPlatform/google-cloud-python key.json |
| 36 | +
|
| 37 | +After running ``travis encrypt-file``, take note of the ``openssl`` command |
| 38 | +printed out. In particular, it'll give the name of the key and |
| 39 | +IV (initialization vector) environment variables added to the Travis |
| 40 | +project. |
| 41 | +
|
| 42 | +See: |
| 43 | +https://docs.travis-ci.com/user/encrypting-files/ |
22 | 44 | """ |
23 | 45 |
|
24 | 46 |
|
25 | 47 | import os |
26 | 48 | import subprocess |
27 | 49 | import sys |
28 | 50 |
|
| 51 | +from google.cloud.environment_vars import CREDENTIALS |
| 52 | + |
29 | 53 | from run_system_test import FailedSystemTestModule |
30 | 54 | from run_system_test import run_module_tests |
31 | 55 |
|
|
46 | 70 | SCRIPTS_DIR = os.path.dirname(__file__) |
47 | 71 | ROOT_DIR = os.path.abspath(os.path.join(SCRIPTS_DIR, '..')) |
48 | 72 | ENCRYPTED_KEYFILE = os.path.join(ROOT_DIR, 'system_tests', 'key.json.enc') |
| 73 | +ENCRYPTED_KEY_ENV = 'encrypted_c16407eb06cc_key' |
| 74 | +ENCRYPTED_INIT_VECTOR_ENV = 'encrypted_c16407eb06cc_iv' |
49 | 75 |
|
50 | 76 |
|
51 | 77 | def check_environment(): |
@@ -73,9 +99,9 @@ def decrypt_keyfile(): |
73 | 99 | print('Running in Travis during merge, decrypting stored ' |
74 | 100 | 'key file.') |
75 | 101 |
|
76 | | - encrypted_key = os.getenv('encrypted_a1b222e8c14d_key') |
77 | | - encrypted_iv = os.getenv('encrypted_a1b222e8c14d_iv') |
78 | | - out_file = os.getenv('GOOGLE_APPLICATION_CREDENTIALS') |
| 102 | + encrypted_key = os.getenv(ENCRYPTED_KEY_ENV) |
| 103 | + encrypted_iv = os.getenv(ENCRYPTED_INIT_VECTOR_ENV) |
| 104 | + out_file = os.getenv(CREDENTIALS) |
79 | 105 | # Convert encrypted key file into decrypted file to be used. |
80 | 106 | subprocess.call([ |
81 | 107 | 'openssl', 'aes-256-cbc', |
|
0 commit comments