From 33f43cfaa724ea46b601c40e544c78d1ae1f464e Mon Sep 17 00:00:00 2001 From: paulnoirel <87332996+paulnoirel@users.noreply.github.com> Date: Mon, 11 Aug 2025 19:55:24 +0100 Subject: [PATCH 1/3] API key creation: fix support of role with a space in the name --- libs/labelbox/src/labelbox/schema/api_key.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/labelbox/src/labelbox/schema/api_key.py b/libs/labelbox/src/labelbox/schema/api_key.py index 9f3094016..3d2fe7b3c 100644 --- a/libs/labelbox/src/labelbox/schema/api_key.py +++ b/libs/labelbox/src/labelbox/schema/api_key.py @@ -333,7 +333,9 @@ def create_api_key( allowed_roles = ApiKey._get_available_api_key_roles(client) # Normalize the allowed roles to lowercase for case-insensitive comparison - normalized_allowed_roles = [r.lower() for r in allowed_roles] + normalized_allowed_roles = [ + r.lower().replace(" ", "_") for r in allowed_roles + ] if role_name.lower() not in normalized_allowed_roles: raise ValueError( f"Invalid role specified. Allowed roles are: {allowed_roles}" From 1723ae19bc8f3e73c5520b4f8a86c22afb4377b9 Mon Sep 17 00:00:00 2001 From: paulnoirel <87332996+paulnoirel@users.noreply.github.com> Date: Tue, 12 Aug 2025 14:28:10 +0100 Subject: [PATCH 2/3] Revert "API key creation: fix support of role with a space in the name" This reverts commit 33f43cfaa724ea46b601c40e544c78d1ae1f464e. --- libs/labelbox/src/labelbox/schema/api_key.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/api_key.py b/libs/labelbox/src/labelbox/schema/api_key.py index 3d2fe7b3c..9f3094016 100644 --- a/libs/labelbox/src/labelbox/schema/api_key.py +++ b/libs/labelbox/src/labelbox/schema/api_key.py @@ -333,9 +333,7 @@ def create_api_key( allowed_roles = ApiKey._get_available_api_key_roles(client) # Normalize the allowed roles to lowercase for case-insensitive comparison - normalized_allowed_roles = [ - r.lower().replace(" ", "_") for r in allowed_roles - ] + normalized_allowed_roles = [r.lower() for r in allowed_roles] if role_name.lower() not in normalized_allowed_roles: raise ValueError( f"Invalid role specified. Allowed roles are: {allowed_roles}" From 35d711d94a86c413b6fad60a156dcd363ee84858 Mon Sep 17 00:00:00 2001 From: paulnoirel <87332996+paulnoirel@users.noreply.github.com> Date: Tue, 12 Aug 2025 18:41:40 +0100 Subject: [PATCH 3/3] API key creation: fix support of space in role name --- libs/labelbox/src/labelbox/schema/api_key.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/labelbox/src/labelbox/schema/api_key.py b/libs/labelbox/src/labelbox/schema/api_key.py index 9f3094016..c5dba9148 100644 --- a/libs/labelbox/src/labelbox/schema/api_key.py +++ b/libs/labelbox/src/labelbox/schema/api_key.py @@ -8,7 +8,7 @@ from lbox.exceptions import LabelboxError from labelbox.schema.user import User -from labelbox.schema.role import Role +from labelbox.schema.role import Role, format_role if TYPE_CHECKING: from labelbox import Client @@ -258,7 +258,7 @@ def _get_available_api_key_roles(client: "Client") -> List[str]: if role["name"] in ["None", "Tenant Admin"]: continue if all(perm in current_permissions for perm in role["permissions"]): - available_roles.append(role["name"]) + available_roles.append(format_role(role["name"])) client._cached_available_api_key_roles = available_roles return available_roles @@ -332,9 +332,9 @@ def create_api_key( raise ValueError("role must be a Role object or a valid role name") allowed_roles = ApiKey._get_available_api_key_roles(client) - # Normalize the allowed roles to lowercase for case-insensitive comparison - normalized_allowed_roles = [r.lower() for r in allowed_roles] - if role_name.lower() not in normalized_allowed_roles: + # Format the input role name consistently with available roles + formatted_role_name = format_role(role_name) + if formatted_role_name not in allowed_roles: raise ValueError( f"Invalid role specified. Allowed roles are: {allowed_roles}" )