Skip to content

Commit

Permalink
pluralize secret stores in config, and switch path to file
Browse files Browse the repository at this point in the history
This makes it consistent with object store and other sections
  • Loading branch information
joeshaw committed Feb 3, 2023
1 parent 1ba490e commit 9f0d8fc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
46 changes: 23 additions & 23 deletions cli/tests/integration/secret_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn secret_store_works() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
secret_store.store_one = [{key = "first", data = "This is some data"},{key = "second", path = "../test-fixtures/data/object-store.txt"}]
secret_stores.store_one = [{key = "first", data = "This is some data"},{key = "second", file = "../test-fixtures/data/object-store.txt"}]
"#;

let resp = Test::using_fixture("secret-store.wasm")
Expand Down Expand Up @@ -48,7 +48,7 @@ fn bad_config_test(toml_fragment: &str) -> Result<FastlyConfig, FastlyConfigErro

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_store_not_array() -> TestResult {
const TOML_FRAGMENT: &str = "secret_store.store_one = 1";
const TOML_FRAGMENT: &str = "secret_stores.store_one = 1";
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::NotAnArray,
Expand All @@ -62,7 +62,7 @@ async fn bad_config_store_not_array() -> TestResult {

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_store_not_table() -> TestResult {
const TOML_FRAGMENT: &str = "secret_store.store_one = [1]";
const TOML_FRAGMENT: &str = "secret_stores.store_one = [1]";
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::NotATable,
Expand All @@ -76,7 +76,7 @@ async fn bad_config_store_not_table() -> TestResult {

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_no_key() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_store.store_one = [{data = "This is some data"}]"#;
const TOML_FRAGMENT: &str = r#"secret_stores.store_one = [{data = "This is some data"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::NoKey,
Expand All @@ -91,7 +91,7 @@ async fn bad_config_no_key() -> TestResult {
#[tokio::test(flavor = "multi_thread")]
async fn bad_config_key_not_string() -> TestResult {
const TOML_FRAGMENT: &str =
r#"secret_store.store_one = [{key = 1, data = "This is some data"}]"#;
r#"secret_stores.store_one = [{key = 1, data = "This is some data"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::KeyNotAString,
Expand All @@ -104,36 +104,36 @@ async fn bad_config_key_not_string() -> TestResult {
}

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_no_data_or_path() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_store.store_one = [{key = "first"}]"#;
async fn bad_config_no_data_or_file() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_stores.store_one = [{key = "first"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::NoPathOrData(_),
err: SecretStoreConfigError::NoFileOrData(_),
..
}) => (),
Err(_) => panic!("Expected a FastlyConfigError::InvalidSecretStoreDefinition with SecretStoreConfigError::NoPathOrData"),
Err(_) => panic!("Expected a FastlyConfigError::InvalidSecretStoreDefinition with SecretStoreConfigError::NoFileOrData"),
_ => panic!("Expected an error"),
}
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_both_data_and_path() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_store.store_one = [{key = "first", path = "file.txt", data = "This is some data"}]"#;
async fn bad_config_both_data_and_file() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_stores.store_one = [{key = "first", file = "file.txt", data = "This is some data"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::PathAndData(_),
err: SecretStoreConfigError::FileAndData(_),
..
}) => (),
Err(_) => panic!("Expected a FastlyConfigError::InvalidSecretStoreDefinition with SecretStoreConfigError::PathAndData"),
Err(_) => panic!("Expected a FastlyConfigError::InvalidSecretStoreDefinition with SecretStoreConfigError::FileAndData"),
_ => panic!("Expected an error"),
}
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_data_not_string() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_store.store_one = [{key = "first", data = 1}]"#;
const TOML_FRAGMENT: &str = r#"secret_stores.store_one = [{key = "first", data = 1}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::DataNotAString(_),
Expand All @@ -146,23 +146,23 @@ async fn bad_config_data_not_string() -> TestResult {
}

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_path_not_string() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_store.store_one = [{key = "first", path = 1}]"#;
async fn bad_config_file_not_string() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_stores.store_one = [{key = "first", file = 1}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::PathNotAString(_),
err: SecretStoreConfigError::FileNotAString(_),
..
}) => (),
Err(_) => panic!("Expected a FastlyConfigError::InvalidSecretStoreDefinition with SecretStoreConfigError::PathNotAString"),
Err(_) => panic!("Expected a FastlyConfigError::InvalidSecretStoreDefinition with SecretStoreConfigError::FileNotAString"),
_ => panic!("Expected an error"),
}
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_path_nonexistent() -> TestResult {
async fn bad_config_file_nonexistent() -> TestResult {
const TOML_FRAGMENT: &str =
r#"secret_store.store_one = [{key = "first", path = "nonexistent.txt"}]"#;
r#"secret_stores.store_one = [{key = "first", file = "nonexistent.txt"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::IoError(_),
Expand All @@ -177,7 +177,7 @@ async fn bad_config_path_nonexistent() -> TestResult {
#[tokio::test(flavor = "multi_thread")]
async fn bad_config_invalid_store_name() -> TestResult {
const TOML_FRAGMENT: &str =
r#"secret_store.store*one = [{key = "first", data = "This is some data"}]"#;
r#"secret_stores.store*one = [{key = "first", data = "This is some data"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidFastlyToml(_)) => (),
Err(_) => panic!("Expected a FastlyConfigError::InvalidFastlyToml"),
Expand All @@ -189,7 +189,7 @@ async fn bad_config_invalid_store_name() -> TestResult {
#[tokio::test(flavor = "multi_thread")]
async fn bad_config_invalid_secret_name() -> TestResult {
const TOML_FRAGMENT: &str =
r#"secret_store.store_one = [{key = "first*", data = "This is some data"}]"#;
r#"secret_stores.store_one = [{key = "first*", data = "This is some data"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::InvalidSecretName(_),
Expand All @@ -203,7 +203,7 @@ async fn bad_config_invalid_secret_name() -> TestResult {

#[tokio::test(flavor = "multi_thread")]
async fn bad_config_secret_name_too_long() -> TestResult {
const TOML_FRAGMENT: &str = r#"secret_store.store_one = [{key = "firstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirst", data = "This is some data"}]"#;
const TOML_FRAGMENT: &str = r#"secret_stores.store_one = [{key = "firstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirstfirst", data = "This is some data"}]"#;
match bad_config_test(TOML_FRAGMENT) {
Err(FastlyConfigError::InvalidSecretStoreDefinition {
err: SecretStoreConfigError::InvalidSecretName(_),
Expand Down
12 changes: 6 additions & 6 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl FastlyConfig {

/// Get the secret store configuration.
pub fn secret_stores(&self) -> &SecretStores {
&self.local_server.secret_store.0
&self.local_server.secret_stores.0
}

/// Parse a `fastly.toml` file into a `FastlyConfig`.
Expand Down Expand Up @@ -185,7 +185,7 @@ pub struct LocalServerConfig {
geolocation: Geolocation,
dictionaries: DictionariesConfig,
object_stores: ObjectStoreConfig,
secret_store: SecretStoreConfig,
secret_stores: SecretStoreConfig,
}

/// Enum of available (experimental) wasi modules
Expand All @@ -205,7 +205,7 @@ struct RawLocalServerConfig {
dictionaries: Option<Table>,
#[serde(alias = "object_store")]
object_stores: Option<Table>,
secret_store: Option<Table>,
secret_stores: Option<Table>,
}

impl TryInto<LocalServerConfig> for RawLocalServerConfig {
Expand All @@ -216,7 +216,7 @@ impl TryInto<LocalServerConfig> for RawLocalServerConfig {
geolocation,
dictionaries,
object_stores,
secret_store,
secret_stores,
} = self;
let backends = if let Some(backends) = backends {
backends.try_into()?
Expand All @@ -238,7 +238,7 @@ impl TryInto<LocalServerConfig> for RawLocalServerConfig {
} else {
ObjectStoreConfig::default()
};
let secret_store = if let Some(secret_store) = secret_store {
let secret_stores = if let Some(secret_store) = secret_stores {
secret_store.try_into()?
} else {
SecretStoreConfig::default()
Expand All @@ -249,7 +249,7 @@ impl TryInto<LocalServerConfig> for RawLocalServerConfig {
geolocation,
dictionaries,
object_stores,
secret_store,
secret_stores,
})
}
}
8 changes: 4 additions & 4 deletions lib/src/config/secret_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ impl TryFrom<Table> for SecretStoreConfig {
});
}

let bytes = match (item.get("path"), item.get("data")) {
let bytes = match (item.get("file"), item.get("data")) {
(None, None) => {
return Err(FastlyConfigError::InvalidSecretStoreDefinition {
name: store_name.to_string(),
err: SecretStoreConfigError::NoPathOrData(key.to_string()),
err: SecretStoreConfigError::NoFileOrData(key.to_string()),
})
}
(Some(_), Some(_)) => {
return Err(FastlyConfigError::InvalidSecretStoreDefinition {
name: store_name.to_string(),
err: SecretStoreConfigError::PathAndData(key.to_string()),
err: SecretStoreConfigError::FileAndData(key.to_string()),
})
}
(Some(path), None) => {
let path = path.as_str().ok_or_else(|| {
FastlyConfigError::InvalidSecretStoreDefinition {
name: store_name.to_string(),
err: SecretStoreConfigError::PathNotAString(key.to_string()),
err: SecretStoreConfigError::FileNotAString(key.to_string()),
}
})?;
fs::read(&path)
Expand Down
12 changes: 6 additions & 6 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,14 @@ pub enum SecretStoreConfigError {
#[error(transparent)]
IoError(std::io::Error),

#[error("The `path` and `data` keys for the object `{0}` are set. Only one can be used.")]
PathAndData(String),
#[error("The `path` or `data` key for the object `{0}` is not set. One must be used.")]
NoPathOrData(String),
#[error("The `file` and `data` keys for the object `{0}` are set. Only one can be used.")]
FileAndData(String),
#[error("The `file` or `data` key for the object `{0}` is not set. One must be used.")]
NoFileOrData(String),
#[error("The `data` value for the object `{0}` is not a string.")]
DataNotAString(String),
#[error("The `path` value for the object `{0}` is not a string.")]
PathNotAString(String),
#[error("The `file` value for the object `{0}` is not a string.")]
FileNotAString(String),

#[error("The `key` key for an object is not set. It must be used.")]
NoKey,
Expand Down

0 comments on commit 9f0d8fc

Please sign in to comment.