From 9f0d8fc542f9600c9c1f3cedc016ab5e60783d55 Mon Sep 17 00:00:00 2001 From: Joe Shaw Date: Fri, 3 Feb 2023 14:46:44 -0500 Subject: [PATCH] pluralize secret stores in config, and switch path to file This makes it consistent with object store and other sections --- cli/tests/integration/secret_store.rs | 46 +++++++++++++-------------- lib/src/config.rs | 12 +++---- lib/src/config/secret_store.rs | 8 ++--- lib/src/error.rs | 12 +++---- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/cli/tests/integration/secret_store.rs b/cli/tests/integration/secret_store.rs index c2ccfc2b..d066143a 100644 --- a/cli/tests/integration/secret_store.rs +++ b/cli/tests/integration/secret_store.rs @@ -11,7 +11,7 @@ async fn secret_store_works() -> TestResult { authors = ["Jill Bryson ", "Rose McDowall "] 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") @@ -48,7 +48,7 @@ fn bad_config_test(toml_fragment: &str) -> Result 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, @@ -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, @@ -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, @@ -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, @@ -104,28 +104,28 @@ 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(()) @@ -133,7 +133,7 @@ async fn bad_config_both_data_and_path() -> TestResult { #[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(_), @@ -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(_), @@ -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"), @@ -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(_), @@ -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(_), diff --git a/lib/src/config.rs b/lib/src/config.rs index cce6cec4..6d759693 100644 --- a/lib/src/config.rs +++ b/lib/src/config.rs @@ -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`. @@ -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 @@ -205,7 +205,7 @@ struct RawLocalServerConfig { dictionaries: Option, #[serde(alias = "object_store")] object_stores: Option
, - secret_store: Option
, + secret_stores: Option
, } impl TryInto for RawLocalServerConfig { @@ -216,7 +216,7 @@ impl TryInto for RawLocalServerConfig { geolocation, dictionaries, object_stores, - secret_store, + secret_stores, } = self; let backends = if let Some(backends) = backends { backends.try_into()? @@ -238,7 +238,7 @@ impl TryInto 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() @@ -249,7 +249,7 @@ impl TryInto for RawLocalServerConfig { geolocation, dictionaries, object_stores, - secret_store, + secret_stores, }) } } diff --git a/lib/src/config/secret_store.rs b/lib/src/config/secret_store.rs index 14c0addb..4ea40294 100644 --- a/lib/src/config/secret_store.rs +++ b/lib/src/config/secret_store.rs @@ -58,24 +58,24 @@ impl TryFrom
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) diff --git a/lib/src/error.rs b/lib/src/error.rs index 976aba62..69b4bc97 100644 --- a/lib/src/error.rs +++ b/lib/src/error.rs @@ -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,