11import logging
22from enum import Enum
33from typing import Dict , Union , List , Iterable
4+ from urllib .parse import quote_plus
45
56from threescale_api import auth
67from threescale_api import utils
@@ -316,7 +317,7 @@ def url(self) -> str:
316317
317318
318319class ApplicationKeys (DefaultClient ):
319- def __init__ (self , * args , entity_name = 'application ' , entity_collection = 'applications ' ,
320+ def __init__ (self , * args , entity_name = 'key ' , entity_collection = 'keys ' ,
320321 ** kwargs ):
321322 super ().__init__ (* args , entity_name = entity_name ,
322323 entity_collection = entity_collection , ** kwargs )
@@ -325,6 +326,30 @@ def __init__(self, *args, entity_name='application', entity_collection='applicat
325326 def url (self ) -> str :
326327 return self .parent .url + '/keys'
327328
329+ def create (self , params : dict = None , ** kwargs ) -> 'ApplicationKey' :
330+ """Create a new instance of ApplicationKey. "keys" POST request
331+ returns Application instead of newly create key.
332+ Returns: Newly created key.
333+
334+ """
335+ super ().create (params = params , ** kwargs )
336+ key = sorted (self .list (), key = lambda key : key ["created_at" ])[- 1 ]
337+ key .entity_id = quote_plus (key ["value" ])
338+ return key
339+
340+ def list (self , ** kwargs ) -> List ['ApplicationKey' ]:
341+ """List all entities of ApplicationKey.
342+ There is no id in list response, so it needs to be assigned the value
343+ to be able to work with key instance.
344+ Args:
345+ **kwargs: Optional parameters
346+ Returns(List['ApplicationKey']): List of ApplicationKey resources
347+ """
348+ key_list = super ().list (** kwargs )
349+ for key in key_list :
350+ key .entity_id = quote_plus (key ["value" ])
351+ return key_list
352+
328353
329354class Providers (DefaultClient ):
330355 def __init__ (self , * args , entity_name = 'user' , entity_collection = 'users' , ** kwargs ):
@@ -1320,7 +1345,7 @@ def service(self) -> 'Service':
13201345 @property
13211346 def keys (self ):
13221347 "Application keys"
1323- return ApplicationKeys (parent = self , instance_klass = DefaultResource )
1348+ return ApplicationKeys (parent = self , instance_klass = ApplicationKey )
13241349
13251350 def authobj (self , auth_mode = None , location = None ):
13261351 """Returns subclass of requests.auth.BaseAuth to provide authentication
@@ -1396,6 +1421,11 @@ def test_request(self, relpath=None, verify: bool = None):
13961421 return client .get (relpath )
13971422
13981423
1424+ class ApplicationKey (DefaultResource ):
1425+ def __init__ (self , entity_name = '' , ** kwargs ):
1426+ super ().__init__ (entity_name = entity_name , ** kwargs )
1427+
1428+
13991429class Account (DefaultResource ):
14001430 def __init__ (self , entity_name = 'org_name' , ** kwargs ):
14011431 super ().__init__ (entity_name = entity_name , ** kwargs )
0 commit comments