Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Environments Updates & Bulk Fetches #7

Closed
metaskills opened this issue Jun 20, 2022 · 2 comments
Closed

Support Environments Updates & Bulk Fetches #7

metaskills opened this issue Jun 20, 2022 · 2 comments

Comments

@metaskills
Copy link
Member

Right now the proof of concept will work as long as an existing ENV is set. For example, if HELLO=yall is set then the shared object hook into getenv can override that with WORLD as a value. But if HELLO were not set at all, then the current code will not return the override. Why is this important?

Let's say you want to batch fetch many parameters using ssm_parameters:/my/application/env as a path. You could have something like this in your template.yml file:

Globals:
  Function:
    Environment:
      Variables:
        X_CRYPTEIA_ENVIRONMENTS: ssm_parameters:/my/application/env

So this could pull in DATABASE_URL, SECRET_KEY_BASE, and many more. But would fail because there was no previous DATABASE_URL set. We could treat this as a feature and encourage placeholders like so, but that feels a bit superfluous?

Globals:
  Function:
    Environment:
      Variables:
        DATABASE_URL: placeholder
        SECRET_KEY_BASE: placeholder
        X_CRYPTEIA_ENVIRONMENTS: ssm_parameters:/my/application/env
@metaskills metaskills changed the title Support Bulk Environments Support Environments Updates & Bulk Fetches Jun 21, 2022
@metaskills
Copy link
Member Author

To support data sharing for #4, the structure should be as simple and portable as possible. As of now here is the final return JSON for the ssm::fetch_parameters function. Where the first item is an example of a ENV set to ssm_parameter:/my/application/SOME_SECRET and the other two are bulk fetches.

[
  {
    "args": "ssm_parameter:/my/application/SOME_SECRET",
    "items": [
      {
        "name": "/my/application/SOME_SECRET",
        "value": "1A2B3C4D5E6F"
      }
    ],
    "name": "SOME_SECRET"
  },
  {
    "args": "ssm_parameters:/my/application/env",
    "items": [
      {
        "name": "/my/application/env/DATABASE_URL",
        "value": "mysql2://user:[email protected]:3306/app"
      },
      {
        "name": "/my/application/env/NEWRELIC_KEY",
        "value": "z6y5x4w3v2u1"
      }
    ],
    "name": "X_CRYPTEIA_ENVIRONMENTS"
  }
]

Here is a proposed data structure that is more succinct and serializable with HashMap. It provides a quick lookup of any environment key.

{
  "SOME_SECRET": {
    "type": "ssm_parameter",
    "value": "1A2B3C4D5E6F"
  },
  "DATABASE_URL": {
    "type": "ssm_parameters",
    "value": "mysql2://user:[email protected]:3306/app"
  },
  "NEWRELIC_KEY": {
    "type": "ssm_parameters",
    "value": "z6y5x4w3v2u1"
  }
}

The idea of including the type key is that in these situations we can be almost certain that these env keys would be missing or is_null() but maybe that is over thinking it. Honestly, if the key is present, we should return the value. So maybe the data structure is as such. A simple HashMap<String, String>

{
  "SOME_SECRET": "1A2B3C4D5E6F",
  "DATABASE_URL": "mysql2://user:[email protected]:3306/app",
  "NEWRELIC_KEY": "z6y5x4w3v2u1"
}

@metaskills
Copy link
Member Author

Fixed by #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant