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

Add environment variables provider #2670

Merged
merged 1 commit into from
Jul 23, 2024
Merged

Add environment variables provider #2670

merged 1 commit into from
Jul 23, 2024

Conversation

rylev
Copy link
Collaborator

@rylev rylev commented Jul 22, 2024

Adds a EnvVariables provider and moves the static provider to its own submodule. If this looks good, the next step is to implement the vault and azure extensions.

@rylev rylev requested a review from lann July 22, 2024 15:00
pub use statik::StaticVariables;

use serde::de::DeserializeOwned;
use spin_expressions::Provider;
use spin_factors::anyhow;

pub trait MakeVariablesProvider: 'static {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think we should switch to the runtime resolver pattern here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's the next PR 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

/// no .env file is loaded.
pub fn new(
prefix: Option<impl Into<String>>,
env_fetcher: impl Fn(&str) -> Result<String, VarError> + Send + Sync + 'static,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have a concrete need for this? Seems a bit marginal vs implementing an entirely new provider...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It makes testing not rely on the environment it's run in. If it complicates too many things in your opinion, we can go back to just assuming std::env::variable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a separate with_env_fetcher? 🤷

Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
@lann
Copy link
Collaborator

lann commented Jul 22, 2024

I don't know why all these other checks ran. Feel free to ignore them and merge.

@rylev rylev merged commit 8b895af into factors Jul 23, 2024
4 of 19 checks passed
@rylev rylev deleted the variables branch July 23, 2024 09:37
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