在 Bluemix 运行时环境变量中使用诸如 ) 之类的字符

Using characters such as ) in Bluemix runtime environment variables

我在 Bluemix 上的 rails 应用 运行 上有一个 ruby。对于这个应用程序,我使用了一些服务,其中之一是对象存储。

从逻辑上讲,我想将我用于每个环境(开发和生产)的凭据放在您可以在 Bluemix 的运行时选项卡中指定的环境变量中。

我想在其中输入这样的密码:

23aSeefae,,)ewFe

运行时环境不接受 ) 符号。

它说:

我试过双引号、单引号,我试过用反斜杠转义 ) 符号。

如有任何帮助,我们将不胜感激。有什么方法可以将我的变量存储在我的应用程序之外,而是存储在 Bluemix 环境中?

PS: 密码不是真实密码。

您必须将您的对象服务实例绑定(连接)到 Bluemix 中的应用程序,以便自动为您创建 VCAP_SERVICES 环境变量。

这里是应用程序绑定对象存储服务实例的 VCAP_SERVICES env 变量示例(出于安全原因,我修改了一些数据):

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

我现在也得到了 Bluemix 支持的帮助。这是迄今为止最简单的方法来做我想做的事:

您可以通过 Cloud Foundry 命令行界面设置环境变量。

cf set-env <APP_NAME> <ENV_VAR_NAME> <ENV_VAR_VALUE>

您必须重新安装您的应用程序才能使用它们。