scottwernervt / cloudstorage

Unified cloud storage API for storage services.
http://cloudstorage.readthedocs.io/en/latest/
MIT License
93 stars 27 forks source link

Testing for valid authentication? #34

Closed flewellyn closed 6 years ago

flewellyn commented 6 years ago

Is there a means of testing the provided authentication to a driver? I would like to be able to account for invalid credentials in configuration.

scottwernervt commented 6 years ago

Not currently, authentication would be checked when performing a REST action on the storage service.

Instead, I can implement a driver property is_authenticated which returns True or False as each driver has a different method for validating credentials. Or would you prefer an Exception thrown if the credentials are wrong at driver initialization?

flewellyn commented 6 years ago

I don't really have a preference, either way would work. I suppose the Exception approach would be Pythonic.

scottwernervt commented 6 years ago

Implemented with #35.

pip install cloudstorage==0.9.0

from cloudstorage.drivers.amazon import S3Driver

storage = S3Driver(key='invalid-key',
                   secret='invalid-secret',
                   region='us-east-1')

storage.validate_credentials()
# cloudstorage.exceptions.CredentialsError: An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid.

Let me know if you run into any issues.

flewellyn commented 6 years ago

Thanks! I will try it out.