Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eea819b

Browse filesBrowse files
authored
Fixing issue 7277 (GoogleCloudPlatform#7370)
* WIP: Triggering a new PR to have a stage for running tests and experimenting. * fix(ssh-test): Trying to fix GoogleCloudPlatform#7277 * Import reordering
1 parent 797dc75 commit eea819b
Copy full SHA for eea819b

File tree

Expand file treeCollapse file tree

1 file changed

+14
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-3
lines changed

‎compute/oslogin/service_account_ssh.py

Copy file name to clipboardExpand all lines: compute/oslogin/service_account_ssh.py
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
import time
2828
import uuid
2929

30+
from google.auth.exceptions import RefreshError
3031
import googleapiclient.discovery
3132
import requests
3233

33-
34-
# Global variables
3534
SERVICE_ACCOUNT_METADATA_URL = (
3635
'http://metadata.google.internal/computeMetadata/v1/instance/'
3736
'service-accounts/default/email')
@@ -76,7 +75,19 @@ def create_ssh_key(oslogin, account, private_key_file=None, expire_time=300):
7675
'key': public_key,
7776
'expirationTimeUsec': expiration,
7877
}
79-
oslogin.users().importSshPublicKey(parent=account, body=body).execute()
78+
print(f'Creating key {account} and {body}')
79+
for attempt_no in range(1, 4):
80+
try:
81+
# This method sometimes failed to work causing issues like #7277
82+
# Maybe retrying it with some delay will make things better
83+
oslogin.users().importSshPublicKey(parent=account, body=body).execute()
84+
except RefreshError:
85+
if attempt_no == 3:
86+
break
87+
time.sleep(attempt_no)
88+
else:
89+
break
90+
8091
return private_key_file
8192
# [END create_key]
8293

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.