Skip to content

Adds Generic Auth Concept to Client#89

Merged
CrackerJackMack merged 2 commits intosoftlayer:masterfrom
sudorandom:auth
Apr 25, 2013
Merged

Adds Generic Auth Concept to Client#89
CrackerJackMack merged 2 commits intosoftlayer:masterfrom
sudorandom:auth

Conversation

@sudorandom
Copy link
Contributor

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.

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.
@CrackerJackMack
Copy link
Contributor

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 {}  # something

Then bail if not issubclass(SoftLayerAuthentication)

Do you think that would be overkill ?

@sudorandom
Copy link
Contributor Author

The reference class that's good for inheritance would be good. The subclass check is probably too much.

@CrackerJackMack
Copy link
Contributor

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.

@sudorandom
Copy link
Contributor Author

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 __call__ for this interface.

@sudorandom
Copy link
Contributor Author

On second thought, making this act like requests' auth might be overkill for this. I added the base class you recommended.

CrackerJackMack added a commit that referenced this pull request Apr 25, 2013
Adds Generic Auth Concept to Client
@CrackerJackMack CrackerJackMack merged commit 5868ffb into softlayer:master Apr 25, 2013
@sudorandom sudorandom deleted the auth branch April 25, 2013 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants