IBM 云对象存储凭证

IBM Cloud Object Storage credentials

我正在尝试设置一个 Raspberry Pi 连接到 IBM Cloud 上的对象存储服务。在对象存储的所有教程中,凭据都是这种格式:

{
  "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

给出以下评论的地方:

在 IBM Cloud Web 界面中,您可以创建或读取现有凭证。如果您的程序在 IBM Cloud(Cloudfoundry 或 Kubernetes)上运行,则凭证也可通过 VCAP 环境变量获得

但是,我不是 运行 我在 IBM Cloud 上的 Python 脚本,而是在向它发送数据的 RPi 上。在我的对象存储服务中,有一个 "service credentials" 选项卡,其格式如下:

{
  "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"
}

那么我如何找到所需的凭据,以便我可以使用 Python 中的 SWIFT 协议将数据从我的 Raspberry Pi 发送到我的对象存储服务?

而不是我认为不受支持的 swift,您可以使用 IBM 的 S3 对象存储协议。您可以使用 python library 来简化此过程

例如连接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)

IBM boto3 库与用于连接到 amazon s3 对象存储的 boto3 库非常相似。主要区别在于设置我上面显示的初始连接。完成后,您可以在网上找到大量使用 boto3 的示例,这里是一个:

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

发件人:http://boto3.readthedocs.io/en/latest/guide/quickstart.html

您可能想看看 question/answer 我在下面列出的内容。基本上,您需要的是 访问密钥 秘密密钥 添加到您的 Python 代码中以连接到您的云对象存储帐户。