IBM Cloud Object Storage凭据

问题描述 投票:0回答:2

我正在尝试设置连接到IBM Cloud上的对象存储服务的Raspberry Pi。在有关对象存储的所有教程中,凭据都具有以下格式:

{
  "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上运行。在我的对象存储服务中,有一个“服务凭据”选项卡,其格式如下:

{
  "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发送到我的对象存储服务?

ibm-cloud object-storage ibm-cloud-storage
2个回答
1
投票

您可以使用IBM的S3对象存储协议,而不是我认为不支持的swift。有一个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


0
投票

您可能想查看我在下面列出的问题/答案。基本上您需要的是一个访问密钥和密钥,用于添加Python代码以连接到您的Cloud Object Storage帐户。

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

© www.soinside.com 2019 - 2024. All rights reserved.