-
Notifications
You must be signed in to change notification settings - Fork 282
Spin up should check required variables #3213
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
73a0280
54915b2
9eb086c
ffa4aad
f72cda6
a51d601
4a038e4
03bf252
fed8aaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//! Environment variable utilities | ||
|
||
/// Defines the default environment variable prefix used by Spin. | ||
pub const DEFAULT_ENV_PREFIX: &str = "SPIN_VARIABLE"; | ||
|
||
/// Creates an environment variable key based on the given prefix and key. | ||
pub fn env_key(prefix: Option<String>, key: &str) -> String { | ||
let prefix = prefix.unwrap_or_else(|| DEFAULT_ENV_PREFIX.to_string()); | ||
let upper_key = key.to_ascii_uppercase(); | ||
let key = format!("{prefix}_{upper_key}"); | ||
key | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
pub mod arg_parser; | ||
pub mod data_dir; | ||
pub mod env; | ||
pub mod paths; | ||
pub mod sha256; | ||
pub mod sloth; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,14 @@ use std::path::{Path, PathBuf}; | |
use anyhow::{anyhow, bail, ensure, Context, Result}; | ||
use futures::{future::try_join_all, StreamExt}; | ||
use reqwest::Url; | ||
use spin_common::{paths::parent_dir, sloth, ui::quoted_path}; | ||
use spin_common::{env::env_key, paths::parent_dir, sloth, ui::quoted_path}; | ||
use spin_locked_app::{ | ||
locked::{ | ||
self, ContentPath, ContentRef, LockedApp, LockedComponent, LockedComponentDependency, | ||
LockedComponentSource, LockedTrigger, | ||
}, | ||
values::{ValuesMap, ValuesMapBuilder}, | ||
Variable, | ||
}; | ||
use spin_manifest::schema::v2::{self, AppManifest, KebabId, WasiFilesMount}; | ||
use spin_outbound_networking_config::allowed_hosts::{ | ||
|
@@ -88,7 +89,7 @@ impl LocalLoader { | |
|
||
let variables = variables | ||
.into_iter() | ||
.map(|(name, v)| Ok((name.to_string(), locked_variable(v)?))) | ||
.map(|(name, v)| Self::env_checker((name.to_string(), locked_variable(v)?))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doing this here means appears to mean we can't even build the LockedApp without having the variables available. How does this worth with e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a nit, but doing this in the loader produces an error message that implies we can't understand the manifest (usually meaning invalid TOML or incorrect schema): that's potentially misleading. |
||
.collect::<Result<_>>()?; | ||
|
||
let triggers = triggers | ||
|
@@ -135,6 +136,21 @@ impl LocalLoader { | |
}) | ||
} | ||
|
||
fn env_checker((key, val): (String, Variable)) -> anyhow::Result<(String, Variable)> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function name needs to be more descriptive. What is it checking? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not clear why this takes a tuple rather than two parameters? |
||
if val.default.is_none() { | ||
if std::env::var(env_key(None, key.as_ref())).is_err() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't assume that variables will come from the host environment. They could come from Vault or Azure KeyVault - for example passwords or tokens would typically be stashed in vaults and it would be rude to demand users create dummy EVs for them. Variable sources are defined in the runtime config file - you can't validate them until you have the runtime config providers lined up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know that the user is using the default prefix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The environment provider appears to support a |
||
Err(anyhow::anyhow!( | ||
"Variable data not provided for {}", | ||
quoted_path(key) | ||
)) | ||
} else { | ||
Ok((key, val)) | ||
} | ||
} else { | ||
Ok((key, val)) | ||
} | ||
} | ||
|
||
// Load the given component into a LockedComponent, ready for execution. | ||
async fn load_component( | ||
&self, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still say we should be able to transform a TOML manifest into a LockedApp without doing validation on variables.