diff options
author | Alex Auvolat <alex@adnab.me> | 2023-08-30 11:24:01 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-08-30 11:24:01 +0200 |
commit | f7b409f1140addd508c626b1e80f0f8de52a5639 (patch) | |
tree | 5aa26db98407793a155a159e29f911890667668a /src | |
parent | abf011c2906d04200bb39d7bc82f7ed973215500 (diff) | |
download | garage-f7b409f1140addd508c626b1e80f0f8de52a5639.tar.gz garage-f7b409f1140addd508c626b1e80f0f8de52a5639.zip |
use a NaiveDate in data model, it serializes to string (iso 8601 format)
Diffstat (limited to 'src')
-rw-r--r-- | src/api/s3/lifecycle.rs | 15 | ||||
-rw-r--r-- | src/model/Cargo.toml | 1 | ||||
-rw-r--r-- | src/model/bucket_table.rs | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/api/s3/lifecycle.rs b/src/api/s3/lifecycle.rs index 48265870..278cf26d 100644 --- a/src/api/s3/lifecycle.rs +++ b/src/api/s3/lifecycle.rs @@ -270,12 +270,11 @@ impl Expiration { (Some(_), Some(_)) => Err("cannot have both <Days> and <Date> in <Expiration>"), (None, None) => Err("<Expiration> must contain either <Days> or <Date>"), (Some(days), None) => Ok(GarageLifecycleExpiration::AfterDays(days.0 as usize)), - (None, Some(date)) => { - if date.0.parse::<chrono::NaiveDate>().is_err() { - return Err("Invalid expiration <Date>"); - } - Ok(GarageLifecycleExpiration::AtDate(date.0)) - } + (None, Some(date)) => date + .0 + .parse::<chrono::NaiveDate>() + .map(GarageLifecycleExpiration::AtDate) + .map_err(|_| "Invalid expiration <Date>"), } } @@ -285,9 +284,9 @@ impl Expiration { days: Some(IntValue(*days as i64)), at_date: None, }, - GarageLifecycleExpiration::AtDate(days) => Expiration { + GarageLifecycleExpiration::AtDate(date) => Expiration { days: None, - at_date: Some(Value::from(days.as_str())), + at_date: Some(Value(date.to_string())), }, } } diff --git a/src/model/Cargo.toml b/src/model/Cargo.toml index 69f7eea4..58d9fdb7 100644 --- a/src/model/Cargo.toml +++ b/src/model/Cargo.toml @@ -23,6 +23,7 @@ garage_util.workspace = true async-trait = "0.1.7" arc-swap = "1.0" blake2 = "0.10" +chrono = { version = "0.4", features = ["serde"] } err-derive = "0.3" hex = "0.4" base64 = "0.21" diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index fed20e05..306a58ab 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -105,7 +105,7 @@ mod v08 { /// Objects expire x days after they were created AfterDays(usize), /// Objects expire at date x (must be in yyyy-mm-dd format) - AtDate(String), + AtDate(chrono::naive::NaiveDate), } #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Serialize, Deserialize)] |