Skip to content

Commit a508d19

Browse files
authored
API key creation: fix support of role with a space in the name (#2003)
1 parent 67eddb9 commit a508d19

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

libs/labelbox/src/labelbox/schema/api_key.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from lbox.exceptions import LabelboxError
99

1010
from labelbox.schema.user import User
11-
from labelbox.schema.role import Role
11+
from labelbox.schema.role import Role, format_role
1212

1313
if TYPE_CHECKING:
1414
from labelbox import Client
@@ -258,7 +258,7 @@ def _get_available_api_key_roles(client: "Client") -> List[str]:
258258
if role["name"] in ["None", "Tenant Admin"]:
259259
continue
260260
if all(perm in current_permissions for perm in role["permissions"]):
261-
available_roles.append(role["name"])
261+
available_roles.append(format_role(role["name"]))
262262
client._cached_available_api_key_roles = available_roles
263263
return available_roles
264264

@@ -332,9 +332,9 @@ def create_api_key(
332332
raise ValueError("role must be a Role object or a valid role name")
333333

334334
allowed_roles = ApiKey._get_available_api_key_roles(client)
335-
# Normalize the allowed roles to lowercase for case-insensitive comparison
336-
normalized_allowed_roles = [r.lower() for r in allowed_roles]
337-
if role_name.lower() not in normalized_allowed_roles:
335+
# Format the input role name consistently with available roles
336+
formatted_role_name = format_role(role_name)
337+
if formatted_role_name not in allowed_roles:
338338
raise ValueError(
339339
f"Invalid role specified. Allowed roles are: {allowed_roles}"
340340
)

0 commit comments

Comments
 (0)