IBM / ibm-cos-sdk-python

ibm-cos-sdk-python
Apache License 2.0
44 stars 26 forks source link

Unable to locate credentials retrieved by `ibmcloud` #24

Closed neumannrf closed 4 years ago

neumannrf commented 4 years ago

For an enhanced user experience, the ibmcloud command-line tool and ibm-cos-sdk Python library should be seamlessly interoperable.

If the service credentials are retrieved using

ibmcloud resource service-key my-service-credentials --output JSON > ~/.bluemix/cos_credentials

The resource creation command gives a ConfigParseError:

>>> cos = ibm_boto3.resource("s3")
ConfigParseError: Unable to parse config file: ~/.bluemix/cos_credentials

That happens because the JSON object written by ibmcloud is a list with only one JSON object, while ibm-cos-sdk is expecting a dictionary. Hence the error AttributeError: 'list' object has no attribute 'keys'.

To circumvent this, one can parse the JSON list with jq and use

ibmcloud resource service-key my-service-credentials --output JSON | jq '.[0]' > ~/.bluemix/cos_credentials

That yields a successful

>>> cos = ibm_boto3.resource("s3")

but then fails when I call get_buckets():

>>> get_buckets()
Retrieving list of buckets
Unable to retrieve list buckets: Unable to locate credentials

I can only make it work by copying and pasting the contents of the service credentials JSON file into ibm_boto3.resource() as shown here.

stephenskinner commented 4 years ago

Thanks for taking the time to raise this ticket and provide a detailed explanation. I've spoken with the SDK architects, we've added this enhancement to the list of items to be considered in the next major version release. If you are happy with this resolution please close the ticket, otherwise please let me know any further questions/issues you have.

neumannrf commented 4 years ago

Thanks @stephenskinner for the feedback!