Skip to content

Commit

Permalink
fix basic methods for application keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mkudlej committed May 15, 2024
1 parent d1e479e commit 82eb4e6
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion threescale_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def url(self) -> str:


class ApplicationKeys(DefaultClient):
def __init__(self, *args, entity_name='application', entity_collection='applications',
def __init__(self, *args, entity_name='key', entity_collection='keys',
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
Expand All @@ -325,6 +325,30 @@ def __init__(self, *args, entity_name='application', entity_collection='applicat
def url(self) -> str:
return self.parent.url + '/keys'

def create(self, params: dict = None, **kwargs) -> 'ApplicationKey':
"""Create a new instance of ApplicationKey. "keys" POST request
returns Application instead of newly create key.
Returns: Newly created key.
"""
super().create(params=params, **kwargs)
key = sorted(self.list(), key=lambda key: key["created_at"])[-1]
key.entity_id = key["value"]
return key

def list(self, **kwargs) -> List['ApplicationKey']:
"""List all entities of ApplicationKey.
There is no id in list response, so it needs to be assigned the value
to be able to work with key instance.
Args:
**kwargs: Optional parameters
Returns(List['ApplicationKey']): List of ApplicationKey resources
"""
key_list = super().list(**kwargs)
for key in key_list:
key.entity_id = key["value"]
return key_list


class Providers(DefaultClient):
def __init__(self, *args, entity_name='user', entity_collection='users', **kwargs):
Expand Down Expand Up @@ -1396,6 +1420,11 @@ def test_request(self, relpath=None, verify: bool = None):
return client.get(relpath)


class ApplicationKey(DefaultResource):
def __init__(self, entity_name='', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)


class Account(DefaultResource):
def __init__(self, entity_name='org_name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
Expand Down

0 comments on commit 82eb4e6

Please sign in to comment.