Skip to content

Commit

Permalink
feat(codegen/minio): VersioningConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Nov 18, 2024
1 parent 20df9ea commit 5c64b47
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 33 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::List(_) => continue,
rust::Type::Map(_) => continue,
rust::Type::StrEnum(_) => {}
rust::Type::Struct(_) => {}
rust::Type::Struct(ty) => {
if ty.is_custom_extension {
continue;
}
}
rust::Type::StructEnum(_) => {}
}

Expand Down
4 changes: 4 additions & 0 deletions codegen/src/v1/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes

xml_name: shape.traits.xml_name().map(o),
is_error_type: shape.traits.error().is_some(),
is_custom_extension: shape.traits.minio(),
});
insert(rs_shape_name, ty);
}
Expand Down Expand Up @@ -264,6 +265,7 @@ fn patch_types(space: &mut RustTypes) {
doc: ty.doc.clone(),
xml_name: None,
is_error_type: false,
is_custom_extension: false,
};

ty.fields.iter().for_each(|x| assert!(x.name != "request"));
Expand Down Expand Up @@ -309,6 +311,7 @@ fn unify_operation_types(ops: &Operations, space: &mut RustTypes) {
doc: None,
xml_name: None,
is_error_type: false,
is_custom_extension: false,
}
} else {
assert!(op.smithy_input.ends_with("Request"));
Expand All @@ -328,6 +331,7 @@ fn unify_operation_types(ops: &Operations, space: &mut RustTypes) {
doc: None,
xml_name: None,
is_error_type: false,
is_custom_extension: false,
}
} else {
if op.smithy_output == op.output {
Expand Down
45 changes: 19 additions & 26 deletions codegen/src/v1/minio.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
use core::str;

use super::o;
use super::smithy;
use super::smithy::BooleanShape;
use super::smithy::StructureMember;

use serde_json::json;

fn git_branch() -> String {
let output = std::process::Command::new("git")
.args(["rev-parse", "--abbrev-ref", "HEAD"])
.output()
.unwrap();
let stdout = str::from_utf8(&output.stdout).unwrap();
let stdout = core::str::from_utf8(&output.stdout).unwrap();
stdout.trim().to_owned()
}

/// <https://github.com/Nugine/s3s/issues/192>
pub fn patch(model: &mut smithy::Model) {
let branch_name = git_branch();
if !matches!(branch_name.as_str(), "minio" | "feat/minio") {
return;
}

model.shapes.insert(
o("com.amazonaws.s3#ForceDelete"),
smithy::Shape::Boolean(BooleanShape {
traits: smithy::Traits::default(),
}),
);
let patches = smithy::Model::load_json("model/minio-patches.json");

let ty = "com.amazonaws.s3#DeleteBucketRequest";
let Some(smithy::Shape::Structure(shape)) = model.shapes.get_mut(ty) else { panic!() };
shape.members.insert(
o("ForceDelete"),
StructureMember {
target: o("com.amazonaws.s3#ForceDelete"),
traits: smithy::Traits::from_value(json!( {
"smithy.api#httpHeader": "x-minio-force-delete",
"s3s#minio": ""
})),
},
);
for (shape_name, patch) in patches.shapes {
match model.shapes.get_mut(&shape_name) {
None => {
model.shapes.insert(shape_name, patch);
}
Some(shape) => match shape {
smithy::Shape::Structure(shape) => {
let smithy::Shape::Structure(patch) = patch else { panic!() };
for (field_name, member) in patch.members {
assert!(shape.members.insert(field_name, member).is_none());
}
}
_ => unimplemented!(),
},
}
}
}
2 changes: 2 additions & 0 deletions codegen/src/v1/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct Struct {

pub xml_name: Option<String>,
pub is_error_type: bool,

pub is_custom_extension: bool,
}

#[allow(clippy::struct_excessive_bools)]
Expand Down
5 changes: 0 additions & 5 deletions codegen/src/v2/smithy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ impl Traits {
self.get("smithy.api#error")?.as_str()
}

pub fn from_value(value: Value) -> Self {
let Value::Object(map) = value else { panic!() };
Self(Some(map))
}

pub fn minio(&self) -> bool {
self.get("s3s#minio").is_some()
}
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:350`
//! Auto generated by `codegen/src/v1/dto.rs:354`

#![allow(clippy::empty_structs_with_brackets)]
#![allow(clippy::too_many_lines)]
Expand Down
18 changes: 18 additions & 0 deletions crates/s3s/tests/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,21 @@ fn assume_role_output() {
let val = deserialize::<s3s::dto::AssumeRoleOutput>(xml.as_bytes()).unwrap();
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);
// }
59 changes: 59 additions & 0 deletions model/minio-patches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"smithy": "2.0",
"shapes": {
"com.amazonaws.s3#ForceDelete": {
"type": "boolean"
},
"com.amazonaws.s3#DeleteBucketRequest": {
"type": "structure",
"members": {
"ForceDelete": {
"target": "com.amazonaws.s3#ForceDelete",
"traits": {
"smithy.api#httpHeader": "x-minio-force-delete",
"s3s#minio": ""
}
}
}
},
"com.amazonaws.s3#ExcludeFolders": {
"type": "boolean"
},
"com.amazonaws.s3#ExcludedPrefix": {
"type": "structure",
"members": {
"Prefix": {
"target": "com.amazonaws.s3#Prefix"
}
},
"traits": {
"s3s#minio": ""
}
},
"com.amazonaws.s3#ExcludedPrefixes": {
"type": "list",
"member": {
"target": "com.amazonaws.s3#ExcludedPrefix"
}
},
"com.amazonaws.s3#VersioningConfiguration": {
"type": "structure",
"members": {
"ExcludedPrefixes": {
"target": "com.amazonaws.s3#ExcludedPrefixes",
"traits": {
"s3s#minio": "",
"smithy.api#xmlFlattened": "",
"smithy.api#xmlName": "ExcludedPrefixes"
}
},
"ExcludeFolders": {
"target": "com.amazonaws.s3#ExcludeFolders",
"traits": {
"s3s#minio": ""
}
}
}
}
}
}

0 comments on commit 5c64b47

Please sign in to comment.