Adds Generic Auth Concept to Client#89
Adds Generic Auth Concept to Client#89CrackerJackMack merged 2 commits intosoftlayer:masterfrom sudorandom:auth
Conversation
API: Adds 'auth' keyword argument to SoftLayer.Client(). This object
should respond to get_headers(). If just username and api_key
are passed in, BasicAuthentication will be used for auth.
|
Looks good. Should we have an ABC or an interface to provide a validation step? I.e. class SoftLayerAuthentication(object):
def get_headers(self):
raise NotImplemented()
class BasicAuthentication(SoftLayerAuthentication):
def get_headers(self):
return {} # somethingThen bail Do you think that would be overkill ? |
|
The reference class that's good for inheritance would be good. The subclass check is probably too much. |
|
Passing in a class instance that doesn't have get_headers() will make for a fun traceback. But at this level of the API, you are probably right about it being overkill. |
|
Since this isn't pulled in yet, I'm considering doing something like requests does. Headers isn't the only thing that may change when doing authentication so requests passes in an entire request object to be modified and returned back. Example: https://github.com/kennethreitz/requests/blob/master/requests/auth.py#L41 It uses |
|
On second thought, making this act like requests' auth might be overkill for this. I added the base class you recommended. |
Adds Generic Auth Concept to Client
API: Adds 'auth' keyword argument to SoftLayer.Client(). This object should respond to get_headers(). If just username and api_key are passed in, BasicAuthentication will be used for auth.
This change is to accommodate other auth mechanisms like token-based auth.