Skip to content

Commit

Permalink
feat(codegen/minio): x-minio-force-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine committed Nov 18, 2024
1 parent d382229 commit 20df9ea
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- minio
pull_request:
branches:
- main
- minio
- 'feat/**'
schedule:
- cron: '0 0 * * 0' # at midnight of each sunday
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/minio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: MinIO

on:
push:
branches:
- main

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: |
git checkout main
git checkout -B minio
just codegen
- uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: minio
force: true
message: "sync codegen minio"
8 changes: 8 additions & 0 deletions codegen/src/v1/aws_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
s => s,
};

if field.is_custom_extension {
g!("{s3s_field_name}: None,");
continue;
}

if field.type_ == "SelectObjectContentEventStream" {
g!("{s3s_field_name}: Some(crate::event_stream::from_aws(x.{aws_field_name})),");
continue;
Expand Down Expand Up @@ -159,6 +164,9 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
}

for field in &ty.fields {
if field.is_custom_extension {
continue;
}
let s3s_field_name = field.name.as_str();
let aws_field_name = match s3s_field_name {
"checksum_crc32c" => "checksum_crc32_c",
Expand Down
4 changes: 4 additions & 0 deletions codegen/src/v1/aws_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
};

for field in ty.fields.iter().chain(flattened_fields) {
if field.is_custom_extension {
continue;
}

let s3s_field_name = match ty.name.as_str() {
"SelectObjectContentInput" if field.name == "request" => continue,
"SelectObjectContentInput" if field.position == "xml" => f!("request.{}", field.name),
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/v1/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ pub fn collect_rust_types(model: &smithy::Model, ops: &Operations) -> RustTypes
http_query: field.traits.http_query().map(o),
xml_name: field.traits.xml_name().map(o),
xml_flattened: field.traits.xml_flattened(),
is_custom_extension: field.traits.minio(),
};
fields.push(field);
}
Expand Down Expand Up @@ -281,6 +282,7 @@ fn patch_types(space: &mut RustTypes) {
http_query: None,
xml_name: Some(request.name.clone()),
xml_flattened: false,
is_custom_extension: false,
});
ty.name = o("SelectObjectContentInput");

Expand Down
2 changes: 1 addition & 1 deletion codegen/src/v1/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn codegen(model: &smithy::Model) {

for header in headers {
let name = to_constant_name(header);
if header.starts_with("x-amz-") || header == "Content-MD5" {
if header.starts_with("x-amz-") || header == "Content-MD5" || header.starts_with("x-minio") {
let value = header.to_ascii_lowercase();
g!("pub const {name}: HeaderName = HeaderName::from_static({value:?});",);
} else {
Expand Down
44 changes: 44 additions & 0 deletions codegen/src/v1/minio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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();
stdout.trim().to_owned()
}

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 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": ""
})),
},
);
}
2 changes: 2 additions & 0 deletions codegen/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod access;
mod dto;
mod error;
mod headers;
mod minio;
mod ops;
mod s3_trait;
mod sts;
Expand All @@ -23,6 +24,7 @@ pub fn run() {
let mut sts_model = smithy::Model::load_json("model/sts.json");
sts::reduce(&mut sts_model);
s3_model.shapes.append(&mut sts_model.shapes);
minio::patch(&mut s3_model);
s3_model
};

Expand Down
3 changes: 3 additions & 0 deletions codegen/src/v1/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub struct Struct {
pub is_error_type: bool,
}

#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)]
pub struct StructField {
pub name: String,
Expand All @@ -92,6 +93,8 @@ pub struct StructField {

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

pub is_custom_extension: bool,
}

#[derive(Debug, Clone)]
Expand Down
11 changes: 10 additions & 1 deletion codegen/src/v2/smithy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum Shape {
Service(ServiceShape),
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Default)]
#[serde(transparent)]
pub struct Traits(Option<Map<String, Value>>);

Expand Down Expand Up @@ -254,4 +254,13 @@ impl Traits {
pub fn error(&self) -> Option<&str> {
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()
}
}
1 change: 1 addition & 0 deletions crates/s3s/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
minio = []
openssl = ["dep:openssl"]
tower = ["dep:tower"]

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:348`
//! Auto generated by `codegen/src/v1/dto.rs:350`

#![allow(clippy::empty_structs_with_brackets)]
#![allow(clippy::too_many_lines)]
Expand Down

0 comments on commit 20df9ea

Please sign in to comment.