ddev / ddev-platformsh

Add integration with Platform.sh hosting service
Apache License 2.0
9 stars 10 forks source link

Wrong generated PLATFORM_ROUTES env variable #64

Closed aimfeld closed 1 year ago

aimfeld commented 1 year ago

In the generated config.platformsh.yaml file, I see the following PLATFORM_ROUTES variable

web_environment:
- "PLATFORM_ROUTES=eyAiJHtEREVWX1BSSU1BUllfVVJMfSI6IHsgInByaW1hcnkiOiB0cnVlLCAiaWQiOiBudWxsLCAicHJvZHVjdGlvbl91cmwiOiAiJHtEREVWX1BSSU1BUllfVVJMfSIsICJhdHRyaWJ1dGVzIjoge30sICJ1cHN0cmVhbSI6ICJkcnVwYWwiLCAidHlwZSI6ICJ1cHN0cmVhbSIsICJvcmlnaW5hbF91cmwiOiAiaHR0cHM6Ly97ZGVmYXVsdH0vIiB9IH0="

Decoding this, I get

echo "eyAiJHtEREVWX1BSSU1BUllfVVJMfSI6IHsgInByaW1hcnkiOiB0cnVlLCAiaWQiOiBudWxsLCAicHJvZHVjdGlvbl91cmwiOiAiJHtEREVWX1BSSU1BUllfVVJMfSIsICJhdHRyaWJ1dGVzIjoge30sICJ1cHN0cmVhbSI6ICJkcnVwYWwiLCAidHlwZSI6ICJ1cHN0cmVhbSIsICJvcmlnaW5hbF91cmwiOiAiaHR0cHM6Ly97ZGVmYXVsdH0vIiB9IH0=" | base64 --decode | jq
{
  "${DDEV_PRIMARY_URL}": {
    "primary": true,
    "id": null,
    "production_url": "${DDEV_PRIMARY_URL}",
    "attributes": {},
    "upstream": "drupal",
    "type": "upstream",
    "original_url": "https://{default}/"
  }
}

However, this doesn't match my routes.yaml, which is:

https://{default}/:
  id: secure
  cache:
    enabled: true
    default_ttl: 0
    cookies: [ '*' ]
    headers: [ 'Accept', 'Accept-Language' ]
  redirects:
    expires: -1s
    paths: {}
  ssi:
    enabled: false
  type: upstream
  upstream: surveylab:php
  tls:
    strict_transport_security:
      enabled: true
      include_subdomains: true
      preload: true

The correct encoding of this routes yaml is as follows:

echo "eyJodHRwczovL3NkYmItaGl0LmxuZG8uc2l0ZS8iOnsicHJpbWFyeSI6dHJ1ZSwiYXR0cmlidXRlcyI6e30sImlkIjoic2VjdXJlIiwib3JpZ2luYWxfdXJsIjoiaHR0cHM6Ly97ZGVmYXVsdH0vIiwiY2FjaGUiOnsiZW5hYmxlZCI6dHJ1ZSwiZGVmYXVsdF90dGwiOjAsImNvb2tpZXMiOlsiKiJdLCJoZWFkZXJzIjpbIkFjY2VwdCIsIkFjY2VwdC1MYW5ndWFnZSJdfSwicmVkaXJlY3RzIjp7ImV4cGlyZXMiOiItMXMiLCJwYXRocyI6e319LCJzc2kiOnsiZW5hYmxlZCI6ZmFsc2V9LCJ0eXBlIjoidXBzdHJlYW0iLCJ1cHN0cmVhbSI6InN1cnZleWxhYiIsInRscyI6eyJzdHJpY3RfdHJhbnNwb3J0X3NlY3VyaXR5Ijp7ImVuYWJsZWQiOnRydWUsImluY2x1ZGVfc3ViZG9tYWlucyI6dHJ1ZSwicHJlbG9hZCI6dHJ1ZX19fX0=" | base64 --decode | jq
{
  "https://sdbb-hit.lndo.site/": {
    "primary": true,
    "attributes": {},
    "id": "secure",
    "original_url": "https://{default}/",
    "cache": {
      "enabled": true,
      "default_ttl": 0,
      "cookies": [
        "*"
      ],
      "headers": [
        "Accept",
        "Accept-Language"
      ]
    },
    "redirects": {
      "expires": "-1s",
      "paths": {}
    },
    "ssi": {
      "enabled": false
    },
    "type": "upstream",
    "upstream": "surveylab",
    "tls": {
      "strict_transport_security": {
        "enabled": true,
        "include_subdomains": true,
        "preload": true
      }
    }
  }
}
rfay commented 1 year ago

Thanks @aimfeld - This is actually

But the routing won't actually end up being https://sdbb-hit.lndo.site/ but rather the actual URL(s) ddev is configured to use. But it definitely won't be lndo.site :)

rfay commented 1 year ago

Closing in favor of #47, but sure appreciate the example.

aimfeld commented 1 year ago

I'll try to hack up a script to get the correct encoded routes.yaml, based on the code here: https://github.com/platformsh/ddev-platformsh/blob/main/install.yaml#L156

rfay commented 1 year ago

Would love a PR!

aimfeld commented 1 year ago

The lando platformsh recipe contains some potentially useful code as well: https://github.com/lando/platformsh/blob/b46e863f720506a6082a6e47f7fdac03f1643070/lib/run.js#L124

rfay commented 1 year ago

Awesome.