我正在尝试设置一个Raspberry Pi,它连接到IBM上的对象存储服务。在关于对象存储的所有教程中,凭据都是这种格式的:
{
"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"
}如有下列意见:
在Inside接口中,您可以创建或读取现有凭据。如果程序在IBM (Cloudfoundry或Kubernetes)上运行,则凭据也可以通过VCAP环境变量获得。
但是,我不是在IBM上运行我的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发送到对象存储服务?
发布于 2018-02-17 05:36:20
您可以使用IBM风格的S3对象存储协议,而不是我认为不支持的。您可以使用一个python库来简化此操作。
例如,要连接到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对象存储的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
发布于 2018-02-23 04:33:51
你可能想看看我下面列出的问题/答案。基本上,您需要的是一个访问密钥和秘密密钥来添加您的Python代码,以连接到云对象存储帐户。
https://stackoverflow.com/questions/48837373
复制相似问题