Skip to content

Commit

Permalink
chore(middleware-flexible-checksums): use object for requestAlgorithm…
Browse files Browse the repository at this point in the history
…Member (#6698)
  • Loading branch information
trivikr authored Dec 16, 2024
1 parent 0054a3d commit b9b146c
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ export class CreateBucketMetadataTableConfigurationCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/DeleteObjectsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ export class DeleteObjectsCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ export class PutBucketAccelerateConfigurationCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: false,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketAclCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ export class PutBucketAclCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketCorsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ export class PutBucketCorsCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketEncryptionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ export class PutBucketEncryptionCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ export class PutBucketLifecycleConfigurationCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketLoggingCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ export class PutBucketLoggingCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketPolicyCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ export class PutBucketPolicyCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ export class PutBucketReplicationCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export class PutBucketRequestPaymentCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketTaggingCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ export class PutBucketTaggingCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketVersioningCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ export class PutBucketVersioningCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutBucketWebsiteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ export class PutBucketWebsiteCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutObjectAclCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ export class PutObjectAclCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutObjectCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ export class PutObjectCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: false,
}),
getCheckContentLengthHeaderPlugin(config),
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutObjectLegalHoldCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ export class PutObjectLegalHoldCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export class PutObjectLockConfigurationCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutObjectRetentionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ export class PutObjectRetentionCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/PutObjectTaggingCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ export class PutObjectTaggingCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ export class PutPublicAccessBlockCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: true,
}),
];
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/RestoreObjectCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ export class RestoreObjectCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: false,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3/src/commands/UploadPartCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,7 @@ export class UploadPartCommand extends $Command
getSerdePlugin(config, this.serialize, this.deserialize),
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
getFlexibleChecksumsPlugin(config, {
requestAlgorithmMember: "ChecksumAlgorithm",
requestAlgorithmMemberHttpHeader: "x-amz-sdk-checksum-algorithm",
requestAlgorithmMember: { httpHeader: "x-amz-sdk-checksum-algorithm", name: "ChecksumAlgorithm" },
requestChecksumRequired: false,
}),
getThrow200ExceptionsPlugin(config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,19 @@ private static Map<String, Object> getPluginFunctionParams(
HttpChecksumTrait httpChecksumTrait = operation.expectTrait(HttpChecksumTrait.class);
params.put("requestChecksumRequired", httpChecksumTrait.isRequestChecksumRequired());
httpChecksumTrait.getRequestAlgorithmMember().ifPresent(requestAlgorithmMember -> {
params.put("requestAlgorithmMember", requestAlgorithmMember);
Map<String, String> requestAlgorithmMemberMap = new TreeMap<String, String>();
requestAlgorithmMemberMap.put("name", requestAlgorithmMember);

// We know that input shape is structure, and contains requestAlgorithmMember.
StructureShape inputShape = model.expectShape(operation.getInput().get(), StructureShape.class);
MemberShape requestAlgorithmMemberShape = inputShape.getAllMembers().get(requestAlgorithmMember);

// Set requestAlgorithmMemberHttpHeader if HttpHeaderTrait is present.
requestAlgorithmMemberShape.getTrait(HttpHeaderTrait.class).ifPresent(httpHeaderTrait -> {
params.put("requestAlgorithmMemberHttpHeader", httpHeaderTrait.getValue());
requestAlgorithmMemberMap.put("httpHeader", httpHeaderTrait.getValue());
});

params.put("requestAlgorithmMember", requestAlgorithmMemberMap);
});
httpChecksumTrait.getRequestValidationModeMember().ifPresent(requestValidationModeMember -> {
params.put("requestValidationModeMember", requestValidationModeMember);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ export interface FlexibleChecksumsRequestMiddlewareConfig {
requestChecksumRequired: boolean;

/**
* Defines a top-level operation input member that is used to configure request checksum behavior.
* Member that is used to configure request checksum behavior.
*/
requestAlgorithmMember?: string;
requestAlgorithmMember?: {
/**
* Defines a top-level operation input member that is used to configure request checksum behavior.
*/
name: string;

/**
* The {@link httpHeader} value for {@link requestAlgorithmMember}, if present.
* {@link https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait httpHeader}
*/
requestAlgorithmMemberHttpHeader?: string;
/**
* The {@link httpHeader} value, if present.
* {@link https://smithy.io/2.0/spec/http-bindings.html#httpheader-trait httpHeader}
*/
httpHeader?: string;
};
}

export const flexibleChecksumsMiddlewareOptions: BuildHandlerOptions = {
Expand Down Expand Up @@ -68,7 +73,7 @@ export const flexibleChecksumsMiddleware =
input,
{
requestChecksumRequired,
requestAlgorithmMember,
requestAlgorithmMember: requestAlgorithmMember?.name,
},
!!context.isS3ExpressBucket
);
Expand Down

0 comments on commit b9b146c

Please sign in to comment.