You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The update method in the APIKey class (arcgis.gis._impl.APIKey) contains two bugs in version 2.4.0:
There's a typo in the parameter name "privileges" (spelled as "priveleges" in the API)
The URL construction doesn't properly handle trailing slashes, potentially creating malformed URLs
To Reproduce
Steps to reproduce the behavior:
fromarcgis.gisimportGISimportarcgis# Connect to ArcGIS Onlinegis=GIS("https://www.arcgis.com", "username", "password")
# Get an existing API keyapi_key_item=gis.content.get("your_api_key_id")
# Create an APIKey Class instancefromarcgis.gis._implimportAPIKeyapi_key_class=APIKey(api_key_item, gis)
# Try to update privileges - this will fail due to the typoprivileges=api_key_class.properties["privileges"] + ["portal:app:access:item:some_item_id"]
result=api_key_class.update(privileges=privileges)
Error:
KeyError: 'priveleges'
Additionally, when inspecting the URL construction in the update method, it can create malformed URLs if the GIS URL already contains a trailing slash.
Expected behavior
The update method should:
Use the correct spelling "privileges" (not "priveleges")
Properly handle URL construction with consistent slash handling
Proposed fix
Here's a patched version of the method that fixes both issues:
defpatched_update(self, http_referers=None, privileges=None):
"""Patched version that fixes both the typo in 'privileges' and the URL format"""# Fix the URL format - ensure proper slash between domain and pathbase_url=self._gis._urlifbase_url.endswith('/'):
base_url=base_urlelse:
base_url=base_url+'/'url=f"{base_url}sharing/rest/content/users/{self._gis.users.me.username}/items/{self._item.id}/updateApiKey"params= {"f": "json"}
ifhttp_referersisnotNone:
params["httpReferrers"] =http_referersifprivilegesisnotNone:
params["privileges"] =privileges# Fixed spelling hereself._properties=Nonereturnself._gis._con.post(url, params)
Platform
OS: Databricks
Python API Version: 2.4.0
Additional context
This issue was discovered while working with API keys and attempting to update their privileges programmatically. The workaround is to patch the method as shown above. The issue appears to be specific to version 2.4.0.
The text was updated successfully, but these errors were encountered:
Hey all, just wanted to check in and see if this is an item that will get addressed in an upcoming release, or if it is in backlog. I'm trying to adapt my workflows around not being able to update API Keys, but it would be excellent to be able to use this library for API Key Management in the near future
Describe the bug
The
update
method in theAPIKey
class (arcgis.gis._impl.APIKey) contains two bugs in version 2.4.0:To Reproduce
Steps to reproduce the behavior:
Error:
Additionally, when inspecting the URL construction in the
update
method, it can create malformed URLs if the GIS URL already contains a trailing slash.Expected behavior
The
update
method should:Proposed fix
Here's a patched version of the method that fixes both issues:
Platform
Additional context
This issue was discovered while working with API keys and attempting to update their privileges programmatically. The workaround is to patch the method as shown above. The issue appears to be specific to version 2.4.0.
The text was updated successfully, but these errors were encountered: