Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(codegen/minio): DeleteReplication #226

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion codegen/src/v1/aws_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
"SelectObjectContentRequest" => continue,
"SelectObjectContentInput" => continue,
"AssumeRoleOutput" => continue,
"Tag" => continue,
_ if super::sts::NAMES.iter().any(|n| n.eq_ignore_ascii_case(name)) => continue,
_ => {}
}
Expand All @@ -37,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
16 changes: 16 additions & 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 Expand Up @@ -246,6 +247,21 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes
}

fn patch_types(space: &mut RustTypes) {
// patch Tag
{
let Some(rust::Type::Struct(ty)) = space.get_mut("Tag") else { panic!() };
for field in &mut ty.fields {
if field.name == "key" {
field.is_required = false;
field.option_type = true;
}
if field.name == "value" {
field.is_required = false;
field.option_type = true;
}
}
}

// patch LifecycleExpiration
{
let Some(rust::Type::Struct(ty)) = space.get_mut("LifecycleExpiration") else { panic!() };
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
20 changes: 20 additions & 0 deletions crates/s3s-aws/src/conv/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,23 @@ impl AwsConversion for s3s::dto::SelectObjectContentInput {
.map_err(S3Error::internal_error)
}
}

impl AwsConversion for s3s::dto::Tag {
type Target = aws_sdk_s3::types::Tag;

type Error = S3Error;

fn try_from_aws(x: Self::Target) -> S3Result<Self> {
Ok(Self {
key: Some(try_from_aws(x.key)?),
value: Some(try_from_aws(x.value)?),
})
}

fn try_into_aws(x: Self) -> S3Result<Self::Target> {
let mut y = Self::Target::builder();
y = y.set_key(try_into_aws(x.key)?);
y = y.set_value(try_into_aws(x.value)?);
y.build().map_err(S3Error::internal_error)
}
}
19 changes: 0 additions & 19 deletions crates/s3s-aws/src/conv/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8236,25 +8236,6 @@ impl AwsConversion for s3s::dto::StorageClassAnalysisSchemaVersion {
}
}

impl AwsConversion for s3s::dto::Tag {
type Target = aws_sdk_s3::types::Tag;
type Error = S3Error;

fn try_from_aws(x: Self::Target) -> S3Result<Self> {
Ok(Self {
key: try_from_aws(x.key)?,
value: try_from_aws(x.value)?,
})
}

fn try_into_aws(x: Self) -> S3Result<Self::Target> {
let mut y = Self::Target::builder();
y = y.set_key(Some(try_into_aws(x.key)?));
y = y.set_value(Some(try_into_aws(x.value)?));
y.build().map_err(S3Error::internal_error)
}
}

impl AwsConversion for s3s::dto::Tagging {
type Target = aws_sdk_s3::types::Tagging;
type Error = S3Error;
Expand Down
16 changes: 10 additions & 6 deletions 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:354`
//! Auto generated by `codegen/src/v1/dto.rs:370`

#![allow(clippy::empty_structs_with_brackets)]
#![allow(clippy::too_many_lines)]
Expand Down Expand Up @@ -18349,19 +18349,23 @@ impl FromStr for StorageClassAnalysisSchemaVersion {
pub type Suffix = String;

/// <p>A container of a key value name pair.</p>
#[derive(Clone, PartialEq)]
#[derive(Clone, Default, PartialEq)]
pub struct Tag {
/// <p>Name of the object key.</p>
pub key: ObjectKey,
pub key: Option<ObjectKey>,
/// <p>Value of the tag.</p>
pub value: Value,
pub value: Option<Value>,
}

impl fmt::Debug for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut d = f.debug_struct("Tag");
d.field("key", &self.key);
d.field("value", &self.value);
if let Some(ref val) = self.key {
d.field("key", val);
}
if let Some(ref val) = self.value {
d.field("value", val);
}
d.finish_non_exhaustive()
}
}
Expand Down
13 changes: 7 additions & 6 deletions crates/s3s/src/xml/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8665,8 +8665,12 @@ impl<'xml> DeserializeContent<'xml> for StorageClassAnalysisSchemaVersion {
}
impl SerializeContent for Tag {
fn serialize_content<W: Write>(&self, s: &mut Serializer<W>) -> SerResult {
s.content("Key", &self.key)?;
s.content("Value", &self.value)?;
if let Some(ref val) = self.key {
s.content("Key", val)?;
}
if let Some(ref val) = self.value {
s.content("Value", val)?;
}
Ok(())
}
}
Expand All @@ -8692,10 +8696,7 @@ impl<'xml> DeserializeContent<'xml> for Tag {
}
_ => Err(DeError::UnexpectedTagName),
})?;
Ok(Self {
key: key.ok_or(DeError::MissingField)?,
value: value.ok_or(DeError::MissingField)?,
})
Ok(Self { key, value })
}
}
impl SerializeContent for Tagging {
Expand Down
100 changes: 81 additions & 19 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 @@ -181,8 +183,8 @@ fn tagging() {

assert_eq!(ans.tag_set.len(), 1);
let tag = &ans.tag_set[0];
assert_eq!(tag.key, "Key4");
assert_eq!(tag.value, "Value4");
assert_eq!(tag.key.as_deref(), Some("Key4"));
assert_eq!(tag.value.as_deref(), Some("Value4"));

test_serde(&ans);
}
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": ""
}
}
}
}
Loading