Skip to content

Commit

Permalink
Catalog: Modify defaulting of blob namespace (#11872)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 74b2120758b2871c8904c848d156e50a6e8a382f
  • Loading branch information
stephencpope authored and Descartes Labs Build committed May 17, 2023
1 parent d7f3535 commit ff21e99
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ The documentation for the latest release can be found at [https://docs.descartes

Changelog
=========

## [Unreleased]

### Catalog

- The defaulting of the `namespace` value for `Blob`s has changed slightly. If no namespace is specified,
it will default to `<org>:<hash>` with the user's org name and unique user hash. Otherwise, any other value,
as before, will be prefixed with the user's org name if it isn't already so.

## [2.0.0rc3]

### Geo
Expand Down
28 changes: 17 additions & 11 deletions descarteslabs/core/catalog/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Blob(CatalogObject):
a restricted alphabet (``a-zA-Z0-9:._-``), and must begin with the user's
org name, or their unique user hash if the user has no org. The required
prefix is seperated from the rest of the namespace name (if any) by a ``:``.
If not provided, the namespace will default to the users org (if any) or
If not provided, the namespace will default to the users org (if any) and
the unique user hash. The combined length of the ``namespace`` and the
``name`` cannot exceed 979 bytes.
Expand Down Expand Up @@ -315,17 +315,23 @@ def namespace_id(cls, namespace_id, client=None):
"""
if client is None:
client = CatalogClient.get_default_client()
prefix = client.auth.payload.get("org")
if prefix is None:
prefix = client.auth.namespace # defaults to the user namespace
org = client.auth.payload.get("org")
namespace = client.auth.namespace

if not namespace_id:
return prefix

if namespace_id == prefix or namespace_id.startswith(prefix + ":"):
if org:
return f"{org}:{namespace}"
else:
return namespace
elif org:
if namespace_id == org or namespace_id.startswith(org + ":"):
return namespace_id
else:
return f"{org}:{namespace_id}"
elif namespace_id == namespace or namespace_id.startswith(namespace + ":"):
return namespace_id

return f"{prefix}:{namespace_id}"
else:
return f"{namespace}:{namespace_id}"

@classmethod
def get(
Expand Down Expand Up @@ -357,8 +363,8 @@ def get(
The storage type of the Blob you wish to retrieve. Defaults to ``data``. Ignored
unless ``name`` is specified.
namespace : str, optional
The namespace of the Blob you wish to retrieve. Defaults to the user's org name.
Ignored unless ``name`` is specified.
The namespace of the Blob you wish to retrieve. Defaults to the user's org name
(if any) plus the unique user hash. Ignored unless ``name`` is specified.
name : str, optional
The name of the Blob you wish to retrieve. Required if ``id`` is not specified.
May not be specified if ``id`` is specified.
Expand Down

0 comments on commit ff21e99

Please sign in to comment.