Skip to content

Commit

Permalink
Black reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
roywilly committed Mar 21, 2024
1 parent 1438361 commit 263f36c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
36 changes: 23 additions & 13 deletions src/sumo/wrapper/_auth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ def login(self):
+ "that is before "
+ str(
(
datetime.now() + timedelta(minutes=self._login_timeout_minutes)
datetime.now()
+ timedelta(minutes=self._login_timeout_minutes)
).strftime("%H:%M:%S")
)
)
Expand All @@ -235,7 +236,9 @@ def login(self):
return

protect_token_cache(self._resource_id, ".token")
print("Equinor Azure login for Sumo access was successful (interactive)")
print(
"Equinor Azure login for Sumo access was successful (interactive)"
)
return

pass
Expand Down Expand Up @@ -273,31 +276,36 @@ def login(self):
print(
"\n\n \033[31m"
+ "Failed to initiate device-code login. Err: %s"
+ "\033[0m"
% json.dumps(flow, indent=4)
+ "\033[0m" % json.dumps(flow, indent=4)
)
return
flow['expires_at'] = int(time.time()) + self._login_timeout_minutes * 60
flow["expires_at"] = (
int(time.time()) + self._login_timeout_minutes * 60
)

print("\033[31m" +
" NOTE! Please login to Equinor Azure to enable Sumo access: "
+ flow["message"] + " \033[0m"
print(
"\033[31m"
+ " NOTE! Please login to Equinor Azure to enable Sumo access: "
+ flow["message"]
+ " \033[0m"
+ "\nYou should complete your login within "
+ str(self._login_timeout_minutes)
+ " minutes, "
+ "that is before "
+ str(
(
datetime.now() + timedelta(minutes=self._login_timeout_minutes)
datetime.now()
+ timedelta(minutes=self._login_timeout_minutes)
).strftime("%H:%M:%S")
))
)
)
result = self._app.acquire_token_by_device_flow(flow)

if "error" in result:
print(
"\n\n \033[31m Error during Equinor Azure login "
"for Sumo access: \033[0m"
)
)
print("Err: ", json.dumps(result, indent=4))
return
except Exception:
Expand All @@ -306,9 +314,11 @@ def login(self):
"one possible reason is timeout \033[0m"
)
return

protect_token_cache(self._resource_id, ".token")
print("Equinor Azure login for Sumo access was successful (device-code)")
print(
"Equinor Azure login for Sumo access was successful (device-code)"
)

return

Expand Down
1 change: 1 addition & 0 deletions src/sumo/wrapper/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ def main():
else:
print("Failed login to Sumo environment: " + env)


if __name__ == "__main__":
main()
12 changes: 8 additions & 4 deletions src/sumo/wrapper/sumo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def __init__(
access_token=access_token,
devicecode=devicecode,
)
if (self.auth.get_token() is None and
refresh_token is None and
access_token is None):
if (
self.auth.get_token() is None
and refresh_token is None
and access_token is None
):
print("\n \033[31m !!! Falling back to device-code login:\033[0m")
self.auth = get_auth_provider(
client_id=APP_REGISTRATION[env]["CLIENT_ID"],
Expand All @@ -98,7 +100,9 @@ def __init__(
devicecode=True,
)
if self.auth.get_token() is None:
print("\n\n \033[31m NOTE! Login failed/timed out. Giving up. \033[0m")
print(
"\n\n \033[31m NOTE! Login failed/timed out. Giving up. \033[0m"
)

if env == "localhost":
self.base_url = "http://localhost:8084/api/v1"
Expand Down

0 comments on commit 263f36c

Please sign in to comment.