Update report documentation/fix gam create project (#1179)

* Update report documentation

* Wait for service account creation to complete

* Update __init__.py
This commit is contained in:
Ross Scroggs
2020-05-07 08:59:52 -07:00
committed by GitHub
parent 0268858784
commit e38ec13dac
2 changed files with 18 additions and 6 deletions

View File

@ -8608,10 +8608,22 @@ def doCreateOrRotateServiceAccountKeys(iam=None,
private_key, publicKeyData = _generatePrivateKeyAndPublicCert(
name, local_key_size)
print(' Uploading new public certificate to Google...')
result = gapi.call(iam.projects().serviceAccounts().keys(),
'upload',
name=name,
body={'publicKeyData': publicKeyData})
max_retries = 10
for i in range(1, max_retries+1):
try:
result = gapi.call(iam.projects().serviceAccounts().keys(),
'upload',
throw_reasons=[gapi_errors.ErrorReason.NOT_FOUND],
name=name,
body={'publicKeyData': publicKeyData})
break
except gapi_errors.GapiNotFoundError as e:
if i == max_retries:
raise e
sleep_time = i*5
if i > 3:
print(f'Waiting for Service Account creation to complete. Sleeping {sleep_time} seconds\n')
time.sleep(sleep_time)
private_key_id = result['name'].rsplit('/', 1)[-1]
oauth2service_data = _formatOAuth2ServiceData(project_id, client_email,
client_id, private_key,