Skip to content

Read the connection URI from the environment. #325

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

Merged
merged 6 commits into from
Feb 26, 2024

Conversation

SamirTalwar
Copy link
Contributor

What

The connection URI can now be provided from the environment, using "uri": {"variable": "..."}.

This means that we can use the same configuration in development and production, and enables the CLI or Cloud build infrastructure to fill it in with e.g. a region-specific URL.

How

We replace the ResolvedSecret from the NDC SDK (which has also been removed from the SDK) with our own Secret type, which can be Plain or FromEnvironment. We then handle the case appropriately, whereas before, we would panic if we ever received a non-resolved secret.

I have introduced the Environment trait to supply environment variables. During normal execution, this is a wrapper around sys::env::var. In tests, however, we can use EmptyEnvironment, or a HashMap containing test data.

This also simplified a couple of pieces of test infrastructure.

  • We no longer need to template the Aurora configuration (we just provide the appropriate value as an environment variable).
  • Generating configuration becomes a single call to ndc-postgres-cli update.
  • The benchmarks no longer need a generated configuration file.

When running normally, the environment is the process' environment
variables, but we can replace it with a `HashMap` or an
`EmptyEnvironment` for testing.
Let's start to reduce the hard-codedness, now we can.
We no longer need to do any splicing, so the script is a one-liner.
This means your Aurora connection URI variable must change too.
This enum will never have more than one case.
@SamirTalwar SamirTalwar requested a review from a team February 26, 2024 16:32
Copy link
Contributor

@plcplc plcplc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

./scripts/generate-configuration.sh 'ndc-postgres' '{{POSTGRESQL_CONNECTION_STRING}}' '{{POSTGRES_V3_CHINOOK_NDC_METADATA}}/configuration.json'
./scripts/generate-configuration.sh 'ndc-postgres' '{{CITUS_CONNECTION_STRING}}' '{{CITUS_V3_CHINOOK_NDC_METADATA}}/configuration.json'
./scripts/generate-configuration.sh 'ndc-postgres' '{{COCKROACH_CONNECTION_STRING}}' '{{COCKROACH_V3_CHINOOK_NDC_METADATA}}/configuration.json'
CONNECTION_URI='{{POSTGRESQL_CONNECTION_URI}}' cargo run --bin ndc-postgres-cli -- --context='{{POSTGRES_V3_CHINOOK_NDC_METADATA}}' update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite nice how this bit of internal test infrastructure is now powered by a component that's part of the actual workflow of users!

@plcplc plcplc added this pull request to the merge queue Feb 26, 2024
Merged via the queue into main with commit 355aa42 Feb 26, 2024
@plcplc plcplc deleted the samirtalwar/config-from-env branch February 26, 2024 17:41
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

Successfully merging this pull request may close these issues.

2 participants