Skip to content

Commit

Permalink
[Core-249] Compute: Credentials checking (#12420)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 2c13397cc5eb62d39576cb283cc0be413514108e
  • Loading branch information
stephencpope authored and Descartes Labs Build committed Jan 30, 2024
1 parent a4d1ab4 commit d821e08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Changelog
- The efficiency of deleting many jobs at once has been significantly improved using `Function.delete` and
`Function.delete_jobs`. It is still possible to encounter request timeouts with very large numbers of jobs;
workarounds are now documented in the API documentation for the `Function.delete_jobs` method.
- The `ComputeClient.check_credentials` method has been added, so that the client can determine if valid
user credentials have already been registered with the Compute service.

### Vector

Expand Down
25 changes: 18 additions & 7 deletions descarteslabs/core/compute/compute_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,25 @@ def iter_log_lines(self, url: str, timestamps: bool = True) -> Iterator[str]:

yield log

def check_credentials(self):
"""Determine if valid credentials are already set for the user."""
_ = self.session.get("/credentials")

def set_credentials(self):
self.session.post(
"/credentials",
json={
"client_id": self.auth.client_id,
"client_secret": self.auth.client_secret,
},
)
if self.auth.client_id and self.auth.client_secret:
self.session.post(
"/credentials",
json={
"client_id": self.auth.client_id,
"client_secret": self.auth.client_secret,
},
)
else:
# We only have a JWT and no client id/secret, so validate
# that there are already valid credentials set for the user.
# This situation will generally only arise when used from
# some backend process.
self.check_credentials()

def get_namespace(self, function_id: str) -> Optional[str]:
if function_id in self._namespace_cache:
Expand Down

0 comments on commit d821e08

Please sign in to comment.