diff --git a/threescale_api/resources.py b/threescale_api/resources.py index 9c1838c..b1a733e 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -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) @@ -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): @@ -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)