Skip to content

Commit

Permalink
feat(codegen/minio): DeleteReplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Dec 14, 2024
1 parent 9726e1c commit 787319c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 20 deletions.
6 changes: 5 additions & 1 deletion codegen/src/v1/aws_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions codegen/src/v1/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/v1/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct StrEnum {
pub name: String,
pub variants: Vec<StrEnumVariant>,
pub doc: Option<String>,

pub is_custom_extension: bool,
}

#[derive(Debug, Clone)]
Expand Down
1 change: 1 addition & 0 deletions codegen/src/v1/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/s3s/src/dto/generated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Auto generated by `codegen/src/v1/dto.rs:369`
//! Auto generated by `codegen/src/v1/dto.rs:370`

#![allow(clippy::empty_structs_with_brackets)]
#![allow(clippy::too_many_lines)]
Expand Down
96 changes: 79 additions & 17 deletions crates/s3s/tests/xml.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use s3s::xml;

use std::fmt;
use std::ops::Not;
use std::sync::LazyLock;

use stdx::default::default;

Expand Down Expand Up @@ -276,20 +278,80 @@ fn assume_role_output() {
test_serde(&val);
}

// #[test]
// fn minio_versioning_configuration() {
// let xml = r#"
// <VersioningConfiguration>
// <Status>Enabled</Status>
// <ExcludedPrefixes>
// <Prefix>a</Prefix>
// </ExcludedPrefixes>
// <ExcludedPrefixes>
// <Prefix>b</Prefix>
// </ExcludedPrefixes>
// <ExcludeFolders>true</ExcludeFolders>
// </VersioningConfiguration>
// "#;
// let val = deserialize::<s3s::dto::VersioningConfiguration>(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<bool> = LazyLock::new(|| {
matches!(git_branch().as_str(), "minio" | "feat/minio") //
});

#[test]
fn minio_versioning_configuration() {
if IS_MINIO_BRANCH.not() {
return;
}

let xml = r#"
<VersioningConfiguration>
<Status>Enabled</Status>
<ExcludedPrefixes>
<Prefix>a</Prefix>
</ExcludedPrefixes>
<ExcludedPrefixes>
<Prefix>b</Prefix>
</ExcludedPrefixes>
<ExcludeFolders>true</ExcludeFolders>
</VersioningConfiguration>
"#;
let val = deserialize::<s3s::dto::VersioningConfiguration>(xml.as_bytes()).unwrap();
test_serde(&val);
}

#[test]
fn minio_delete_replication() {
if IS_MINIO_BRANCH.not() {
return;
}

let xml = r#"
<ReplicationConfiguration>
<Rule>
<ID>cte4oalu3vqltovlh28g</ID>
<Status>Enabled</Status>
<Priority>0</Priority>
<DeleteMarkerReplication>
<Status>Enabled</Status>
</DeleteMarkerReplication>
<DeleteReplication>
<Status>Enabled</Status>
</DeleteReplication>
<Destination>
<Bucket>arn:minio:replication:us-east-1:e02ce029-7459-4be2-8267-064712b0ead4:buc2</Bucket>
</Destination>
<Filter>
<Prefix></Prefix>
<And></And>
<Tag></Tag>
</Filter>
<SourceSelectionCriteria>
<ReplicaModifications>
<Status>Enabled</Status>
</ReplicaModifications>
</SourceSelectionCriteria>
<ExistingObjectReplication>
<Status>Enabled</Status>
</ExistingObjectReplication>
</Rule>
<Role>
</Role>
</ReplicationConfiguration>
"#;
let val = deserialize::<s3s::dto::ReplicationConfiguration>(xml.as_bytes()).unwrap();
test_serde(&val);
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 45 additions & 0 deletions model/minio-patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
}
}
}

0 comments on commit 787319c

Please sign in to comment.