0
votes

I am trying to setup a Raspberry Pi that connects to an Object Storage service on IBM Cloud. In all tutorials on Object Storage, credentials are of this format:

{
  "auth_url": "https://identity.open.softlayer.com",
  "project": "object_storage_xxxxxxxx_xxxx_xxxx_b35a_6d007e3f9118", 
  "projectId": "512xxxxxxxxxxxxxxxxxxxxxe00fe4e1", 
  "region": "dallas",
  "userId": "e8c19efxxxxxxxxxxxxxxxxxxx91d53e",
  "username": "admin_1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa66",
  "password": "fTxxxxxxxxxxw8}l",
  "domainId": "15xxxxxxxxxxxxxxxxxxxxxxxxxxxx2a", 
  "domainName": "77xxx3",
  "role": "admin"
}

According to here for example

Where the following comment is given:

Inside the IBM Cloud web interface you can create or read existing credentials. If your program runs on IBM Cloud (Cloudfoundry or Kubernetes) the credentials are also available via the VCAP environment variable

However, I am not running my Python script on IBM Cloud, rather on a RPi that sends data to it. In my Object Storage service, there is a "service credentials" tab, which has the following form:

{
  "apikey": "XXXXXX-_XXXXXXXXXXXXXXXXXX_XXXXXX",
  "endpoints": "https://cos-service.bluemix.net/endpoints",
  "iam_apikey_description": "Auto generated apikey during resource-key 
    operation for Instance - crn:v1:bluemix:public:cloud-object-
    storage:global:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "iam_apikey_name": "auto-generated-apikey-XXXXXXXX-XXXX-XXXX-XXXX-
    XXXXXXXXXXXX",
  "iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
  "iam_serviceid_crn": "crn:v1:bluemix:public:iam-
identity::XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX::serviceid:ServiceId-
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
  "resource_instance_id": "crn:v1:bluemix:public:cloud-object-
storage:global:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}

So how do I find the credentials needed so I can use the SWIFT protocol in Python to send data from my Raspberry Pi to my Object Storage service?

2

2 Answers

2
votes

Instead of swift which I don’t think is supported, you can use IBM’s flavour of S3 object storage protocol. There is a python library you can use to make this easy

For example to connect to cos s3:

import ibm_boto3
from ibm_botocore.client import Config

api_key = 'API_KEY'
service_instance_id = 'RESOURCE_INSTANCE_ID'
auth_endpoint = 'https://iam.bluemix.net/oidc/token'
service_endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'

s3 = ibm_boto3.resource('s3',
                      ibm_api_key_id=api_key,
                      ibm_service_instance_id=service_instance_id,
                      ibm_auth_endpoint=auth_endpoint,
                      config=Config(signature_version='oauth'),
                      endpoint_url=service_endpoint)

Th IBM boto3 library is very similar to the boto3 library that is used to connect to amazon s3 object storage. The main difference is in setting up the initial connection which I have shown above. After you have done that you can find plenty of examples online for using boto3, here is one:

# Upload a new file
data = open('test.jpg', 'rb')
s3.Bucket('my-bucket').put_object(Key='test.jpg', Body=data)

From: http://boto3.readthedocs.io/en/latest/guide/quickstart.html

0
votes

You might want to look at question/answer I list below. Basically what you need is an access key and secret key to add in your Python code to connect to your Cloud Object Storage account.

https://stackoverflow.com/a/48936053/9392933