Programmatically defining Service connection settings


#1

I’m working with a hosting provider who provides connection strings to resources in environmental variables. I’m curious if there’s a good way for me to provide those environmental variables as the connection settings for a Postgres Service? In the past I’ve always had static strings and created my Services via the interface, but it doesn’t seem like I can insert environmental variables that way…


#2

@reynoldsalec Not sure I’m 100% following but you can absolutely create services in DF programmatically. Can you provide an example connection string your hosting provider provides? (“provider provides” redundant, eh?) Please redact any sensitive info in your example. I’ll be happy to provide an example payload or tell you whether what you are asking is possible. Thanks!


#3

Our particular provider (Platform.sh) provides the connection info for the Service in an environmental variable, since connection info may not remain static over time.

Example: echo $PLATFORM_RELATIONSHIPS | base64 --decode | json_pp --decode | json_pp would provide a json object with connection info:

{
    "database": [
        {
            "host": "database.internal",
            "ip": "246.0.97.91",
            "password": "",
            "path": "main",
            "port": 3306,
            "query": {
                "is_master": true
            },
            "scheme": "mysql",
            "username": "user"
        }
    ]
}

It’s normally trivial to retrieve and decode these variables (see this example for configuring a normal Laravel app), but I’m not sure the best way to provide this info to a Service. I’m guessing I need to write some code to provide a System Key or other Lookup value?

Thanks for the help!