From 1ee10fac8e8dfa021ace019601a83257870b6505 Mon Sep 17 00:00:00 2001 From: Nugine Date: Sat, 14 Dec 2024 13:22:12 +0800 Subject: [PATCH] feat(codegen/minio): `DeleteReplication` --- codegen/src/v1/aws_conv.rs | 6 ++- codegen/src/v1/dto.rs | 1 + codegen/src/v1/rust.rs | 2 + codegen/src/v1/xml.rs | 1 + crates/s3s/tests/xml.rs | 96 +++++++++++++++++++++++++++++++------- justfile | 2 +- model/minio-patches.json | 45 ++++++++++++++++++ 7 files changed, 134 insertions(+), 19 deletions(-) diff --git a/codegen/src/v1/aws_conv.rs b/codegen/src/v1/aws_conv.rs index 37f00ad..e715402 100644 --- a/codegen/src/v1/aws_conv.rs +++ b/codegen/src/v1/aws_conv.rs @@ -38,7 +38,11 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { rust::Type::Timestamp(_) => continue, rust::Type::List(_) => continue, rust::Type::Map(_) => continue, - rust::Type::StrEnum(_) => {} + rust::Type::StrEnum(ty) => { + if ty.is_custom_extension { + continue; + } + } rust::Type::Struct(ty) => { if ty.is_custom_extension { continue; diff --git a/codegen/src/v1/dto.rs b/codegen/src/v1/dto.rs index d03e821..d6e0a92 100644 --- a/codegen/src/v1/dto.rs +++ b/codegen/src/v1/dto.rs @@ -125,6 +125,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes name: rs_shape_name.clone(), variants, doc: shape.traits.doc().map(o), + is_custom_extension: shape.traits.minio(), }); insert(rs_shape_name, ty); } diff --git a/codegen/src/v1/rust.rs b/codegen/src/v1/rust.rs index 0682654..621cac3 100644 --- a/codegen/src/v1/rust.rs +++ b/codegen/src/v1/rust.rs @@ -54,6 +54,8 @@ pub struct StrEnum { pub name: String, pub variants: Vec, pub doc: Option, + + pub is_custom_extension: bool, } #[derive(Debug, Clone)] diff --git a/codegen/src/v1/xml.rs b/codegen/src/v1/xml.rs index 4797c1c..0589b80 100644 --- a/codegen/src/v1/xml.rs +++ b/codegen/src/v1/xml.rs @@ -427,6 +427,7 @@ fn codegen_xml_serde_content_struct(_ops: &Operations, rust_types: &RustTypes, t if field.option_type { g!("{},", field.name); } else { + // g!("{0}: {0}.ok_or_else(||dbg!(DeError::MissingField))?,", field.name); g!("{0}: {0}.ok_or(DeError::MissingField)?,", field.name); } } diff --git a/crates/s3s/tests/xml.rs b/crates/s3s/tests/xml.rs index e3a48a3..d176bca 100644 --- a/crates/s3s/tests/xml.rs +++ b/crates/s3s/tests/xml.rs @@ -1,6 +1,8 @@ use s3s::xml; use std::fmt; +use std::ops::Not; +use std::sync::LazyLock; use stdx::default::default; @@ -276,20 +278,80 @@ fn assume_role_output() { test_serde(&val); } -// #[test] -// fn minio_versioning_configuration() { -// let xml = r#" -// -// Enabled -// -// a -// -// -// b -// -// true -// -// "#; -// let val = deserialize::(xml.as_bytes()).unwrap(); -// test_serde(&val); -// } +fn git_branch() -> String { + let output = std::process::Command::new("git") + .args(["rev-parse", "--abbrev-ref", "HEAD"]) + .output() + .unwrap(); + let stdout = core::str::from_utf8(&output.stdout).unwrap(); + stdout.trim().to_owned() +} + +static IS_MINIO_BRANCH: LazyLock = LazyLock::new(|| { + matches!(git_branch().as_str(), "minio" | "feat/minio") // +}); + +#[test] +fn minio_versioning_configuration() { + if IS_MINIO_BRANCH.not() { + return; + } + + let xml = r#" + + Enabled + + a + + + b + + true + + "#; + let val = deserialize::(xml.as_bytes()).unwrap(); + test_serde(&val); +} + +#[test] +fn minio_delete_replication() { + if IS_MINIO_BRANCH.not() { + return; + } + + let xml = r#" + + + cte4oalu3vqltovlh28g + Enabled + 0 + + Enabled + + + Enabled + + + arn:minio:replication:us-east-1:e02ce029-7459-4be2-8267-064712b0ead4:buc2 + + + + + + + + + Enabled + + + + Enabled + + + + + + "#; + let val = deserialize::(xml.as_bytes()).unwrap(); + test_serde(&val); +} diff --git a/justfile b/justfile index 138b08b..738eb72 100644 --- a/justfile +++ b/justfile @@ -26,7 +26,7 @@ model: uv run model/main.py update codegen: - cargo run -p s3s-codegen -- model/s3.json + cargo run -p s3s-codegen cargo fmt cargo check diff --git a/model/minio-patches.json b/model/minio-patches.json index 71e0014..de8372a 100644 --- a/model/minio-patches.json +++ b/model/minio-patches.json @@ -54,6 +54,51 @@ } } } + }, + "com.amazonaws.s3#ReplicationRule": { + "type": "structure", + "members": { + "DeleteReplication": { + "target": "com.amazonaws.s3#DeleteReplication", + "traits": { + "s3s#minio": "" + } + } + } + }, + "com.amazonaws.s3#DeleteReplication": { + "type": "structure", + "members": { + "Status": { + "target": "com.amazonaws.s3#DeleteReplicationStatus", + "traits": { + "smithy.api#required": {} + } + } + }, + "traits": { + "s3s#minio": "" + } + }, + "com.amazonaws.s3#DeleteReplicationStatus": { + "type": "enum", + "members": { + "Enabled": { + "target": "smithy.api#Unit", + "traits": { + "smithy.api#enumValue": "Enabled" + } + }, + "Disabled": { + "target": "smithy.api#Unit", + "traits": { + "smithy.api#enumValue": "Disabled" + } + } + }, + "traits": { + "s3s#minio": "" + } } } } \ No newline at end of file