How to update postgres uri value in cf vcaps env

时间秒杀一切 提交于 2020-01-06 06:32:52

问题


I have a bound Postgres service to my spring application in CF (Cloud foundry) The VCAPS env available are as following:

"postgresql": [
   {
    "binding_name": null,
    "credentials": {
     "dbname": "JDusZ6EpE1ixbTKS",
     "end_points": [
      {
       "host": "10.11.241.2",
       "network_id": "SF",
       "port": "46371"
      }
     ],
     "hostname": "10.11.241.2",
     "password": "SuVzOf2m5L5oNYSG",
     "port": "46371",
     "ports": {
      "5432/tcp": "46371"
     },
     "uri": "postgres://eyv6avf27X9Z55Gx:SuVzOf2m5L5oNYSG@10.11.241.2:46371/JDusZ6EpE1ixbTKS",
     "username": "eyv6avf27X9Z55Gx"
    },
    "instance_name": "mypostgres",
    "label": "postgresql",
    "name": "mypostgres",
    "plan": "v9.6-dev",
    "provider": null,
    "syslog_drain_url": null,
    "tags": [
     "postgresql",
     "relational"
    ],
    "volume_mounts": []
   }
  ],

I need to modefy the value of the uri to include also the current schema, I guess it needs to be as:

 "uri": "postgres://eyv6avf27X9Z55Gx:SuVzOf2m5L5oNYSG@10.11.241.2:46371/JDusZ6EpE1ixbTKS?currentSchema=mycurrentschema"

Is this something possible to do? and If not what is the best practice to assign current schema for a spring app?

Thanks in advance


回答1:


You have a few options.

  1. You can talk to your service provider, the operator of the service broker from which you are obtaining your service. The service broker is the one that sets the credentials, so you could ask them to include the schema by default.

  2. You can create a service key with cf create-service-key. The service key is like a service binding, but free floating so it's not attached to your app. It just exists as long as the service key exists. You can then create a user provided service, with cf cups and manually set whatever credentials or uri you require for your app. The downside of this approach is that you have to do a little more work to manage the service information.

  3. You can read the current uri into your application and modify it before creating your DataSource. This is not particularly easy if you are using Spring Cloud Connectors because it handles creating the DataSource for you. I would not recommend using SCC.

    Instead you can do this with the Spring Boot CloudFoundryVcapEnvironmentPostProcessor and property place holders. See the referenced Javadoc for how that works.

    The other option is to use java-cvenv. That provides you with an easy way to obtain credentials information, like the URL and use that to create your own DataSource, which allows you to make slight modifications to things like the URL, if necessary.

Hope that helps!



来源:https://stackoverflow.com/questions/57474030/how-to-update-postgres-uri-value-in-cf-vcaps-env

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!