2424--passphrase_file: Specify a file to read the passphrase from (only reads the
2525 first line). Use "-" (without quotes) for stdin.
2626--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.
2729
2830This script will perform the following:
2931
5052flags .DEFINE_string ("passphrase" , None , "The passphrase itself." )
5153flags .DEFINE_string ("passphrase_file" , None ,
5254 "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." )
5458
5559
5660def main (argv ):
@@ -69,17 +73,23 @@ def main(argv):
6973 else :
7074 raise ValueError ("Must supply passphrase or passphrase_file arg." )
7175
76+ if FLAGS .apis :
77+ print ("Retrieving secrets for product APIs: " , FLAGS .apis )
78+
7279 secrets_dir = os .path .join (repo_dir , "scripts" , "gha-encrypted" )
7380 encrypted_files = _find_encrypted_files (secrets_dir )
7481 print ("Found these encrypted files:\n %s" % "\n " .join (encrypted_files ))
7582
7683 for path in encrypted_files :
7784 if "google-services" in path or "GoogleService" in path :
78- print ("Encrypted Google Service file found: %s" % path )
7985 # We infer the destination from the file's directory, example:
8086 # /scripts/gha-encrypted/auth/google-services.json.gpg turns into
8187 # /<repo_dir>/auth/integration_test/google-services.json
8288 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 )
8393 file_name = os .path .basename (path ).replace (".gpg" , "" )
8494 dest_paths = [os .path .join (repo_dir , api , "integration_test" , file_name )]
8595 if FLAGS .artifact :
@@ -107,17 +117,19 @@ def main(argv):
107117 if FLAGS .artifact :
108118 return
109119
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 )
121133
122134 print ("Attempting to decrypt GCS service account key file." )
123135 decrypted_key_file = os .path .join (secrets_dir , "gcs_key_file.json" )
0 commit comments