24
24
--passphrase_file: Specify a file to read the passphrase from (only reads the
25
25
first line). Use "-" (without quotes) for stdin.
26
26
--repo_dir: Path to C++ SDK Github repository. Defaults to current directory.
27
+ --apis: Specify a list of particular product APIs and retrieve only their
28
+ secrets.
27
29
28
30
This script will perform the following:
29
31
50
52
flags .DEFINE_string ("passphrase" , None , "The passphrase itself." )
51
53
flags .DEFINE_string ("passphrase_file" , None ,
52
54
"Path to file with passphrase. Use \" -\" (without quotes) for stdin." )
53
- flags .DEFINE_string ("artifact" , None , "Artifact Path, google-services.json will be placed here." )
55
+ flags .DEFINE_string ("artifact" , None , "Artifact Path, google-services.json will be placed here." )
56
+ flags .DEFINE_list ("apis" ,[], "Optional comma-separated list of APIs for which to retreive "
57
+ " secrets. All secrets will be fetched if this is flag is not defined." )
54
58
55
59
56
60
def main (argv ):
@@ -69,17 +73,23 @@ def main(argv):
69
73
else :
70
74
raise ValueError ("Must supply passphrase or passphrase_file arg." )
71
75
76
+ if FLAGS .apis :
77
+ print ("Retrieving secrets for product APIs: " , FLAGS .apis )
78
+
72
79
secrets_dir = os .path .join (repo_dir , "scripts" , "gha-encrypted" )
73
80
encrypted_files = _find_encrypted_files (secrets_dir )
74
81
print ("Found these encrypted files:\n %s" % "\n " .join (encrypted_files ))
75
82
76
83
for path in encrypted_files :
77
84
if "google-services" in path or "GoogleService" in path :
78
- print ("Encrypted Google Service file found: %s" % path )
79
85
# We infer the destination from the file's directory, example:
80
86
# /scripts/gha-encrypted/auth/google-services.json.gpg turns into
81
87
# /<repo_dir>/auth/integration_test/google-services.json
82
88
api = os .path .basename (os .path .dirname (path ))
89
+ if FLAGS .apis and api not in FLAGS .apis :
90
+ print ("Skipping secret found in product api" , api )
91
+ continue
92
+ print ("Encrypted Google Service file found: %s" % path )
83
93
file_name = os .path .basename (path ).replace (".gpg" , "" )
84
94
dest_paths = [os .path .join (repo_dir , api , "integration_test" , file_name )]
85
95
if FLAGS .artifact :
@@ -107,17 +117,19 @@ def main(argv):
107
117
if FLAGS .artifact :
108
118
return
109
119
110
- print ("Attempting to patch Dynamic Links uri prefix." )
111
- uri_path = os .path .join (secrets_dir , "dynamic_links" , "uri_prefix.txt.gpg" )
112
- uri_prefix = _decrypt (uri_path , passphrase )
113
- dlinks_project = os .path .join (repo_dir , "dynamic_links" , "integration_test" )
114
- _patch_main_src (dlinks_project , "REPLACE_WITH_YOUR_URI_PREFIX" , uri_prefix )
115
-
116
- print ("Attempting to patch Messaging server key." )
117
- server_key_path = os .path .join (secrets_dir , "messaging" , "server_key.txt.gpg" )
118
- server_key = _decrypt (server_key_path , passphrase )
119
- messaging_project = os .path .join (repo_dir , "messaging" , "integration_test" )
120
- _patch_main_src (messaging_project , "REPLACE_WITH_YOUR_SERVER_KEY" , server_key )
120
+ if not FLAGS .apis or "dynamic_links" in FLAGS .apis :
121
+ print ("Attempting to patch Dynamic Links uri prefix." )
122
+ uri_path = os .path .join (secrets_dir , "dynamic_links" , "uri_prefix.txt.gpg" )
123
+ uri_prefix = _decrypt (uri_path , passphrase )
124
+ dlinks_project = os .path .join (repo_dir , "dynamic_links" , "integration_test" )
125
+ _patch_main_src (dlinks_project , "REPLACE_WITH_YOUR_URI_PREFIX" , uri_prefix )
126
+
127
+ if not FLAGS .apis or "messaging" in FLAGS .apis :
128
+ print ("Attempting to patch Messaging server key." )
129
+ server_key_path = os .path .join (secrets_dir , "messaging" , "server_key.txt.gpg" )
130
+ server_key = _decrypt (server_key_path , passphrase )
131
+ messaging_project = os .path .join (repo_dir , "messaging" , "integration_test" )
132
+ _patch_main_src (messaging_project , "REPLACE_WITH_YOUR_SERVER_KEY" , server_key )
121
133
122
134
print ("Attempting to decrypt GCS service account key file." )
123
135
decrypted_key_file = os .path .join (secrets_dir , "gcs_key_file.json" )
0 commit comments