您必须将对象服务实例绑定(连接)到 Bluemix 中的应用程序,以便VCAP_SERVICES
自动为您创建环境变量。
这是应用程序绑定对象存储服务实例的 VCAP_SERVICES 环境变量的示例(出于安全原因,我修改了一些数据):
{
"Object-Storage": [
{
"credentials": {
"auth_url": "https://identity.open.softlayer.com",
"project": "object_storage_a92583b3_329e_4ed8_8918_xxx",
"projectId": "7f1f5659d21340dfaa4568dxxxx",
"region": "dallas",
"userId": "abcdefghxxxxxxxxxxxxx",
"username": "admin_3ff9bf1e187e7fa02e28c96232dxxxxxxx",
"password": "BF_0_)s3#xxxXXbY^",
"domainId": "79fc08601744486abf930000000000",
"domainName": "761111",
"role": "admin"
},
"syslog_drain_url": null,
"label": "Object-Storage",
"provider": null,
"plan": "standard",
"name": "app-object-storage",
"tags": [
"storage",
"ibm_release",
"ibm_created"
]
}
]
}
然后,您可以在 ruby 代码中将此作为 JSON 对象读取,例如:
vcap_services = JSON.parse(ENV['VCAP_SERVICES'])
credentials = vcap_services["Object-Storage"][0]["credentials"]
password = credentials["password"]