Skip to content

Commit

Permalink
object store config naming changes for consistency
Browse files Browse the repository at this point in the history
`object_store` becomes `object_stores` for consistency with `backends`
and `dictionaries`.  `path` becomes `file` for consistency with
dictionaries and geolocation config.

An example object store in the fastly.toml file might now look something
like:

```
[local_server]
object_stores.store_one = [{key = "one", file = "/path/to/something"}]
```

or

```
[local_server]
[local_server.object_stores]
store_one = [{key = "one", file = "/path/to/something"}]
```

or

```
[local_server]
[local_server.object_stores]
[[local_server.object_stores.store_one]]
key = "one"
file = "/path/to/something"
```
  • Loading branch information
joeshaw committed Nov 16, 2022
1 parent 48ea9ef commit 458c8c2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
52 changes: 26 additions & 26 deletions cli/tests/integration/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ async fn object_store() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.empty_store = []
object_store.store_one = [{key = "first", data = "This is some data"},{key = "second", path = "../test-fixtures/data/object-store.txt"}]
object_stores.empty_store = []
object_stores.store_one = [{key = "first", data = "This is some data"},{key = "second", file = "../test-fixtures/data/object-store.txt"}]
"#;

let resp = Test::using_fixture("object_store.wasm")
Expand All @@ -36,7 +36,7 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = 3, data = "This is some data"}]
object_stores.store_one = [{key = 3, data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_1_FASTLY_TOML) {
Err(e) => assert_eq!(
Expand All @@ -52,7 +52,7 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "first", data = 3}]
object_stores.store_one = [{key = "first", data = 3}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_2_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': The `data` value for the object `first` is not a string.", &e.to_string()),
Expand All @@ -65,10 +65,10 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "first", data = "This is some data", path = "../test-fixtures/data/object-store.txt"}]
object_stores.store_one = [{key = "first", data = "This is some data", file = "../test-fixtures/data/object-store.txt"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_3_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': The `path` and `data` keys for the object `first` are set. Only one can be used.", &e.to_string()),
Err(e) => assert_eq!("invalid configuration for 'store_one': The `file` and `data` keys for the object `first` are set. Only one can be used.", &e.to_string()),
_ => panic!(),
}

Expand All @@ -78,10 +78,10 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "first", path = 3}]
object_stores.store_one = [{key = "first", file = 3}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_4_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': The `path` value for the object `first` is not a string.", &e.to_string()),
Err(e) => assert_eq!("invalid configuration for 'store_one': The `file` value for the object `first` is not a string.", &e.to_string()),
_ => panic!(),
}

Expand All @@ -91,7 +91,7 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "first", path = "../path/does/not/exist"}]
object_stores.store_one = [{key = "first", file = "../path/does/not/exist"}]
"#;

// For CI to pass we need to include the specific message for each platform
Expand All @@ -116,10 +116,10 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "first"}]
object_stores.store_one = [{key = "first"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_6_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': The `path` or `data` key for the object `first` is not set. One must be used.", &e.to_string()),
Err(e) => assert_eq!("invalid configuration for 'store_one': The `file` or `data` key for the object `first` is not set. One must be used.", &e.to_string()),
_ => panic!(),
}

Expand All @@ -129,7 +129,7 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{data = "This is some data"}]
object_stores.store_one = [{data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_7_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': The `key` key for an object is not set. It must be used.", &e.to_string()),
Expand All @@ -142,7 +142,7 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = "lol lmao"
object_stores.store_one = "lol lmao"
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_8_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': There is no array of objects for the given store.", &e.to_string()),
Expand All @@ -155,7 +155,7 @@ async fn object_store_bad_configs() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = ["This is some data"]
object_stores.store_one = ["This is some data"]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_9_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': There is an object in the given store that is not a table of keys.", &e.to_string()),
Expand All @@ -173,7 +173,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "", data = "This is some data"}]
object_stores.store_one = [{key = "", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_1_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot be empty.", &e.to_string()),
Expand All @@ -186,7 +186,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey", data = "This is some data"}]
object_stores.store_one = [{key = "LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong,keeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeEEEEEEEEEEEEEEEEEEEEEEEEEEEEEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeey", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_2_FASTLY_TOML) {
Err(e) => assert_eq!(
Expand All @@ -202,7 +202,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = ".well-known/acme-challenge/wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", data = "This is some data"}]
object_stores.store_one = [{key = ".well-known/acme-challenge/wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_3_FASTLY_TOML) {
Err(e) => assert_eq!(
Expand All @@ -218,7 +218,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = ".", data = "This is some data"}]
object_stores.store_one = [{key = ".", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_4_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot be named `.`.", &e.to_string()),
Expand All @@ -231,7 +231,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "..", data = "This is some data"}]
object_stores.store_one = [{key = "..", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_5_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot be named `..`.", &e.to_string()),
Expand All @@ -244,7 +244,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "carriage\rreturn", data = "This is some data"}]
object_stores.store_one = [{key = "carriage\rreturn", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_6_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `\r`.", &e.to_string()),
Expand All @@ -257,7 +257,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "newlines\nin\nthis\neconomy?", data = "This is some data"}]
object_stores.store_one = [{key = "newlines\nin\nthis\neconomy?", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_7_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `\n`.", &e.to_string()),
Expand All @@ -270,7 +270,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "howdy[", data = "This is some data"}]
object_stores.store_one = [{key = "howdy[", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_8_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `[`.", &e.to_string()),
Expand All @@ -283,7 +283,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "hello]", data = "This is some data"}]
object_stores.store_one = [{key = "hello]", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_9_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `]`.", &e.to_string()),
Expand All @@ -296,7 +296,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "yoohoo*", data = "This is some data"}]
object_stores.store_one = [{key = "yoohoo*", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_10_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `*`.", &e.to_string()),
Expand All @@ -309,7 +309,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "hey?", data = "This is some data"}]
object_stores.store_one = [{key = "hey?", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_11_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `?`.", &e.to_string()),
Expand All @@ -322,7 +322,7 @@ async fn object_store_bad_key_values() -> TestResult {
authors = ["Jill Bryson <jbryson@fastly.com>", "Rose McDowall <rmcdowall@fastly.com>"]
language = "rust"
[local_server]
object_store.store_one = [{key = "ello ello#", data = "This is some data"}]
object_stores.store_one = [{key = "ello ello#", data = "This is some data"}]
"#;
match Test::using_fixture("object_store.wasm").using_fastly_toml(BAD_12_FASTLY_TOML) {
Err(e) => assert_eq!("invalid configuration for 'store_one': Invalid `key` value used: Keys for objects cannot contain a `#`.", &e.to_string()),
Expand Down
1 change: 1 addition & 0 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ struct RawLocalServerConfig {
backends: Option<Table>,
geolocation: Option<Table>,
dictionaries: Option<Table>,
#[serde(rename = "object_stores")]
object_store: Option<Table>,
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/config/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ impl TryFrom<Table> for ObjectStoreConfig {
name: store.to_string(),
err: ObjectStoreConfigError::KeyNotAString,
})?;
let bytes = match (item.get("path"), item.get("data")) {
let bytes = match (item.get("file"), item.get("data")) {
(None, None) => {
return Err(FastlyConfigError::InvalidObjectStoreDefinition {
name: store.to_string(),
err: ObjectStoreConfigError::NoPathOrData(key.to_string()),
err: ObjectStoreConfigError::NoFileOrData(key.to_string()),
})
}
(Some(_), Some(_)) => {
return Err(FastlyConfigError::InvalidObjectStoreDefinition {
name: store.to_string(),
err: ObjectStoreConfigError::PathAndData(key.to_string()),
err: ObjectStoreConfigError::FileAndData(key.to_string()),
})
}
(Some(path), None) => {
let path = path.as_str().ok_or_else(|| {
FastlyConfigError::InvalidObjectStoreDefinition {
name: store.to_string(),
err: ObjectStoreConfigError::PathNotAString(key.to_string()),
err: ObjectStoreConfigError::FileNotAString(key.to_string()),
}
})?;
fs::read(path).map_err(|e| {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,14 @@ pub enum ObjectStoreConfigError {
/// An I/O error that occured while reading the file.
#[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,
#[error("The `key` value for an object is not a string.")]
Expand Down

0 comments on commit 458c8c2

Please sign in to comment.