Commit e45c86f3 authored by Nugine's avatar Nugine
Browse files

codegen: update model

parent 8b030bb5
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -35,6 +35,12 @@ pub struct Operation {

pub type Operations = BTreeMap<String, Operation>;

fn is_skipped_operation(op_name: &str) -> bool {
    // TODO: handle these operations
    let skipped = ["CreateSession", "ListDirectoryBuckets"];
    skipped.contains(&op_name)
}

pub fn collect_operations(model: &smithy::Model) -> Operations {
    let mut operations: Operations = default();
    let mut insert = |name, op| assert!(operations.insert(name, op).is_none());
@@ -44,6 +50,10 @@ pub fn collect_operations(model: &smithy::Model) -> Operations {

        let op_name = dto::to_type_name(shape_name).to_owned();

        if is_skipped_operation(&op_name) {
            continue;
        }

        let cvt = |n| {
            if n == "smithy.api#Unit" {
                o("Unit")
@@ -124,7 +134,6 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) {
    g!();

    glines![
        ""
        "#![allow(clippy::declare_interior_mutable_const)]"
        "#![allow(clippy::borrow_interior_mutable_const)]"
        "#![allow(clippy::needless_pass_by_value)]"
@@ -856,7 +865,7 @@ fn codegen_router(ops: &Operations, rust_types: &RustTypes) {
                Some(group) => {
                    // NOTE: To debug the routing order, uncomment the lines below.
                    // {
                    //     println!("{} {:?}", method, pattern);
                    //     println!("{method} {pattern:?}");
                    //     println!();
                    //     for route in group {
                    //         println!(
@@ -945,8 +954,8 @@ fn codegen_router(ops: &Operations, rust_types: &RustTypes) {

                            let qs = route.required_query_strings.as_slice();
                            let hs = route.required_headers.as_slice();
                            assert!(qs.len() <= 1);
                            assert!(hs.len() <= 2);
                            assert!(qs.len() <= 2, "qs = {qs:?}");
                            assert!(hs.len() <= 2, "hs = {hs:?}");

                            if qs.is_empty() && hs.is_empty() {
                                continue;
@@ -954,6 +963,9 @@ fn codegen_router(ops: &Operations, rust_types: &RustTypes) {

                            let mut cond: String = default();
                            for q in qs {
                                if cond.is_empty().not() {
                                    cond.push_str(" && ");
                                }
                                cond.push_str(&f!("qs.has(\"{q}\")"));
                            }
                            for h in hs {
+376 −86

File changed.

Preview size limit exceeded, changes collapsed.

+3399 −698

File changed.

Preview size limit exceeded, changes collapsed.

+10 −0
Original line number Diff line number Diff line
@@ -48,14 +48,22 @@ pub const X_AMZ_ABORT_DATE: HeaderName = HeaderName::from_static("x-amz-abort-da

pub const X_AMZ_ABORT_RULE_ID: HeaderName = HeaderName::from_static("x-amz-abort-rule-id");

pub const X_AMZ_ACCESS_POINT_ALIAS: HeaderName = HeaderName::from_static("x-amz-access-point-alias");

pub const X_AMZ_ACL: HeaderName = HeaderName::from_static("x-amz-acl");

pub const X_AMZ_ARCHIVE_STATUS: HeaderName = HeaderName::from_static("x-amz-archive-status");

pub const X_AMZ_BUCKET_LOCATION_NAME: HeaderName = HeaderName::from_static("x-amz-bucket-location-name");

pub const X_AMZ_BUCKET_LOCATION_TYPE: HeaderName = HeaderName::from_static("x-amz-bucket-location-type");

pub const X_AMZ_BUCKET_OBJECT_LOCK_ENABLED: HeaderName = HeaderName::from_static("x-amz-bucket-object-lock-enabled");

pub const X_AMZ_BUCKET_OBJECT_LOCK_TOKEN: HeaderName = HeaderName::from_static("x-amz-bucket-object-lock-token");

pub const X_AMZ_BUCKET_REGION: HeaderName = HeaderName::from_static("x-amz-bucket-region");

pub const X_AMZ_BYPASS_GOVERNANCE_RETENTION: HeaderName = HeaderName::from_static("x-amz-bypass-governance-retention");

pub const X_AMZ_CHECKSUM_ALGORITHM: HeaderName = HeaderName::from_static("x-amz-checksum-algorithm");
@@ -98,6 +106,8 @@ pub const X_AMZ_COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5: HeaderName

pub const X_AMZ_COPY_SOURCE_VERSION_ID: HeaderName = HeaderName::from_static("x-amz-copy-source-version-id");

pub const X_AMZ_CREATE_SESSION_MODE: HeaderName = HeaderName::from_static("x-amz-create-session-mode");

pub const X_AMZ_DATE: HeaderName = HeaderName::from_static("x-amz-date");

pub const X_AMZ_DECODED_CONTENT_LENGTH: HeaderName = HeaderName::from_static("x-amz-decoded-content-length");
+48 −25
Original line number Diff line number Diff line
@@ -150,6 +150,16 @@ impl http::TryIntoHeaderValue for ChecksumMode {
    }
}

impl http::TryIntoHeaderValue for LocationType {
    type Error = http::InvalidHeaderValue;
    fn try_into_header_value(self) -> Result<http::HeaderValue, Self::Error> {
        match Cow::from(self) {
            Cow::Borrowed(s) => http::HeaderValue::try_from(s),
            Cow::Owned(s) => http::HeaderValue::try_from(s),
        }
    }
}

impl http::TryIntoHeaderValue for MetadataDirective {
    type Error = http::InvalidHeaderValue;
    fn try_into_header_value(self) -> Result<http::HeaderValue, Self::Error> {
@@ -312,6 +322,14 @@ impl http::TryFromHeaderValue for ChecksumMode {
    }
}

impl http::TryFromHeaderValue for LocationType {
    type Error = http::ParseHeaderError;
    fn try_from_header_value(val: &http::HeaderValue) -> Result<Self, Self::Error> {
        let val = val.to_str().map_err(|_| http::ParseHeaderError::Enum)?;
        Ok(Self::from(val.to_owned()))
    }
}

impl http::TryFromHeaderValue for MetadataDirective {
    type Error = http::ParseHeaderError;
    fn try_from_header_value(val: &http::HeaderValue) -> Result<Self, Self::Error> {
@@ -515,7 +533,7 @@ impl CompleteMultipartUpload {
    pub fn serialize_http(x: CompleteMultipartUploadOutput) -> S3Result<http::Response> {
        let mut res = http::Response::with_status(http::StatusCode::OK);
        http::set_xml_body(&mut res, &x)?;
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_EXPIRATION, x.expiration)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_AWS_KMS_KEY_ID, x.ssekms_key_id)?;
@@ -693,7 +711,7 @@ impl CopyObject {
        if let Some(ref val) = x.copy_object_result {
            http::set_xml_body(&mut res, val)?;
        }
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_COPY_SOURCE_VERSION_ID, x.copy_source_version_id)?;
        http::add_opt_header(&mut res, X_AMZ_EXPIRATION, x.expiration)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
@@ -903,7 +921,7 @@ impl CreateMultipartUpload {
        http::set_xml_body(&mut res, &x)?;
        http::add_opt_header_timestamp(&mut res, X_AMZ_ABORT_DATE, x.abort_date, TimestampFormat::HttpDate)?;
        http::add_opt_header(&mut res, X_AMZ_ABORT_RULE_ID, x.abort_rule_id)?;
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_ALGORITHM, x.checksum_algorithm)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM, x.sse_customer_algorithm)?;
@@ -1492,7 +1510,7 @@ impl DeleteObject {

    pub fn serialize_http(x: DeleteObjectOutput) -> S3Result<http::Response> {
        let mut res = http::Response::with_status(http::StatusCode::NO_CONTENT);
        http::add_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_VERSION_ID, x.version_id)?;
        Ok(res)
@@ -2617,7 +2635,7 @@ impl GetObject {
            http::set_stream_body(&mut res, val);
        }
        http::add_opt_header(&mut res, ACCEPT_RANGES, x.accept_ranges)?;
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, CACHE_CONTROL, x.cache_control)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32, x.checksum_crc32)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32C, x.checksum_crc32c)?;
@@ -2626,16 +2644,16 @@ impl GetObject {
        http::add_opt_header(&mut res, CONTENT_DISPOSITION, x.content_disposition)?;
        http::add_opt_header(&mut res, CONTENT_ENCODING, x.content_encoding)?;
        http::add_opt_header(&mut res, CONTENT_LANGUAGE, x.content_language)?;
        http::add_header(&mut res, CONTENT_LENGTH, x.content_length)?;
        http::add_opt_header(&mut res, CONTENT_LENGTH, x.content_length)?;
        http::add_opt_header(&mut res, CONTENT_RANGE, x.content_range)?;
        http::add_opt_header(&mut res, CONTENT_TYPE, x.content_type)?;
        http::add_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, ETAG, x.e_tag)?;
        http::add_opt_header(&mut res, X_AMZ_EXPIRATION, x.expiration)?;
        http::add_opt_header_timestamp(&mut res, EXPIRES, x.expires, TimestampFormat::HttpDate)?;
        http::add_opt_header_timestamp(&mut res, LAST_MODIFIED, x.last_modified, TimestampFormat::HttpDate)?;
        http::add_opt_metadata(&mut res, x.metadata)?;
        http::add_header(&mut res, X_AMZ_MISSING_META, x.missing_meta)?;
        http::add_opt_header(&mut res, X_AMZ_MISSING_META, x.missing_meta)?;
        http::add_opt_header(&mut res, X_AMZ_OBJECT_LOCK_LEGAL_HOLD, x.object_lock_legal_hold_status)?;
        http::add_opt_header(&mut res, X_AMZ_OBJECT_LOCK_MODE, x.object_lock_mode)?;
        http::add_opt_header_timestamp(
@@ -2644,7 +2662,7 @@ impl GetObject {
            x.object_lock_retain_until_date,
            TimestampFormat::DateTime,
        )?;
        http::add_header(&mut res, X_AMZ_MP_PARTS_COUNT, x.parts_count)?;
        http::add_opt_header(&mut res, X_AMZ_MP_PARTS_COUNT, x.parts_count)?;
        http::add_opt_header(&mut res, X_AMZ_REPLICATION_STATUS, x.replication_status)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_RESTORE, x.restore)?;
@@ -2653,7 +2671,7 @@ impl GetObject {
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_AWS_KMS_KEY_ID, x.ssekms_key_id)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION, x.server_side_encryption)?;
        http::add_opt_header(&mut res, X_AMZ_STORAGE_CLASS, x.storage_class)?;
        http::add_header(&mut res, X_AMZ_TAGGING_COUNT, x.tag_count)?;
        http::add_opt_header(&mut res, X_AMZ_TAGGING_COUNT, x.tag_count)?;
        http::add_opt_header(&mut res, X_AMZ_VERSION_ID, x.version_id)?;
        http::add_opt_header(&mut res, X_AMZ_WEBSITE_REDIRECT_LOCATION, x.website_redirect_location)?;
        Ok(res)
@@ -2777,7 +2795,7 @@ impl GetObjectAttributes {
    pub fn serialize_http(x: GetObjectAttributesOutput) -> S3Result<http::Response> {
        let mut res = http::Response::with_status(http::StatusCode::OK);
        http::set_xml_body(&mut res, &x)?;
        http::add_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header_timestamp(&mut res, LAST_MODIFIED, x.last_modified, TimestampFormat::HttpDate)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_VERSION_ID, x.version_id)?;
@@ -3109,8 +3127,13 @@ impl HeadBucket {
        })
    }

    pub fn serialize_http(_: HeadBucketOutput) -> S3Result<http::Response> {
        Ok(http::Response::with_status(http::StatusCode::OK))
    pub fn serialize_http(x: HeadBucketOutput) -> S3Result<http::Response> {
        let mut res = http::Response::with_status(http::StatusCode::OK);
        http::add_opt_header(&mut res, X_AMZ_ACCESS_POINT_ALIAS, x.access_point_alias)?;
        http::add_opt_header(&mut res, X_AMZ_BUCKET_LOCATION_NAME, x.bucket_location_name)?;
        http::add_opt_header(&mut res, X_AMZ_BUCKET_LOCATION_TYPE, x.bucket_location_type)?;
        http::add_opt_header(&mut res, X_AMZ_BUCKET_REGION, x.bucket_region)?;
        Ok(res)
    }
}

@@ -3194,7 +3217,7 @@ impl HeadObject {
        let mut res = http::Response::with_status(http::StatusCode::OK);
        http::add_opt_header(&mut res, ACCEPT_RANGES, x.accept_ranges)?;
        http::add_opt_header(&mut res, X_AMZ_ARCHIVE_STATUS, x.archive_status)?;
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, CACHE_CONTROL, x.cache_control)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32, x.checksum_crc32)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32C, x.checksum_crc32c)?;
@@ -3203,15 +3226,15 @@ impl HeadObject {
        http::add_opt_header(&mut res, CONTENT_DISPOSITION, x.content_disposition)?;
        http::add_opt_header(&mut res, CONTENT_ENCODING, x.content_encoding)?;
        http::add_opt_header(&mut res, CONTENT_LANGUAGE, x.content_language)?;
        http::add_header(&mut res, CONTENT_LENGTH, x.content_length)?;
        http::add_opt_header(&mut res, CONTENT_LENGTH, x.content_length)?;
        http::add_opt_header(&mut res, CONTENT_TYPE, x.content_type)?;
        http::add_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, X_AMZ_DELETE_MARKER, x.delete_marker)?;
        http::add_opt_header(&mut res, ETAG, x.e_tag)?;
        http::add_opt_header(&mut res, X_AMZ_EXPIRATION, x.expiration)?;
        http::add_opt_header_timestamp(&mut res, EXPIRES, x.expires, TimestampFormat::HttpDate)?;
        http::add_opt_header_timestamp(&mut res, LAST_MODIFIED, x.last_modified, TimestampFormat::HttpDate)?;
        http::add_opt_metadata(&mut res, x.metadata)?;
        http::add_header(&mut res, X_AMZ_MISSING_META, x.missing_meta)?;
        http::add_opt_header(&mut res, X_AMZ_MISSING_META, x.missing_meta)?;
        http::add_opt_header(&mut res, X_AMZ_OBJECT_LOCK_LEGAL_HOLD, x.object_lock_legal_hold_status)?;
        http::add_opt_header(&mut res, X_AMZ_OBJECT_LOCK_MODE, x.object_lock_mode)?;
        http::add_opt_header_timestamp(
@@ -3220,7 +3243,7 @@ impl HeadObject {
            x.object_lock_retain_until_date,
            TimestampFormat::DateTime,
        )?;
        http::add_header(&mut res, X_AMZ_MP_PARTS_COUNT, x.parts_count)?;
        http::add_opt_header(&mut res, X_AMZ_MP_PARTS_COUNT, x.parts_count)?;
        http::add_opt_header(&mut res, X_AMZ_REPLICATION_STATUS, x.replication_status)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_RESTORE, x.restore)?;
@@ -4960,7 +4983,7 @@ impl PutObject {

    pub fn serialize_http(x: PutObjectOutput) -> S3Result<http::Response> {
        let mut res = http::Response::with_status(http::StatusCode::OK);
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32, x.checksum_crc32)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32C, x.checksum_crc32c)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_SHA1, x.checksum_sha1)?;
@@ -5498,7 +5521,7 @@ impl UploadPart {

        let expected_bucket_owner: Option<AccountId> = http::parse_opt_header(req, &X_AMZ_EXPECTED_BUCKET_OWNER)?;

        let part_number: PartNumber = http::parse_opt_query(req, "partNumber")?.unwrap_or(0);
        let part_number: PartNumber = http::parse_query(req, "partNumber")?;

        let request_payer: Option<RequestPayer> = http::parse_opt_header(req, &X_AMZ_REQUEST_PAYER)?;

@@ -5535,7 +5558,7 @@ impl UploadPart {

    pub fn serialize_http(x: UploadPartOutput) -> S3Result<http::Response> {
        let mut res = http::Response::with_status(http::StatusCode::OK);
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32, x.checksum_crc32)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_CRC32C, x.checksum_crc32c)?;
        http::add_opt_header(&mut res, X_AMZ_CHECKSUM_SHA1, x.checksum_sha1)?;
@@ -5605,7 +5628,7 @@ impl UploadPartCopy {

        let expected_source_bucket_owner: Option<AccountId> = http::parse_opt_header(req, &X_AMZ_SOURCE_EXPECTED_BUCKET_OWNER)?;

        let part_number: PartNumber = http::parse_opt_query(req, "partNumber")?.unwrap_or(0);
        let part_number: PartNumber = http::parse_query(req, "partNumber")?;

        let request_payer: Option<RequestPayer> = http::parse_opt_header(req, &X_AMZ_REQUEST_PAYER)?;

@@ -5647,7 +5670,7 @@ impl UploadPartCopy {
        if let Some(ref val) = x.copy_part_result {
            http::set_xml_body(&mut res, val)?;
        }
        http::add_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_BUCKET_KEY_ENABLED, x.bucket_key_enabled)?;
        http::add_opt_header(&mut res, X_AMZ_COPY_SOURCE_VERSION_ID, x.copy_source_version_id)?;
        http::add_opt_header(&mut res, X_AMZ_REQUEST_CHARGED, x.request_charged)?;
        http::add_opt_header(&mut res, X_AMZ_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM, x.sse_customer_algorithm)?;
@@ -6096,12 +6119,12 @@ pub fn resolve_route(
                    }
                }
                if let Some(qs) = qs {
                    if qs.has("uploadId") && req.headers.contains_key("x-amz-copy-source") {
                    if qs.has("partNumber") && qs.has("uploadId") && req.headers.contains_key("x-amz-copy-source") {
                        return Ok((&UploadPartCopy as &'static dyn super::Operation, false));
                    }
                }
                if let Some(qs) = qs {
                    if qs.has("uploadId") {
                    if qs.has("partNumber") && qs.has("uploadId") {
                        return Ok((&UploadPart as &'static dyn super::Operation, false));
                    }
                }
Loading