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

Update httpChecksum trait to uppercase algorithms #982

Merged
merged 1 commit into from
Nov 15, 2021
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
24 changes: 12 additions & 12 deletions docs/source/1.0/spec/aws/aws-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ The ``httpChecksum`` trait is a structure that contains the following members:
request checksum behavior. The input member MUST target a string shape
marked with the :ref:`enum-trait`. Each value in the enum represents a
supported checksum algorithm. Algorithms MUST be one of the following
supported values: "crc32c", "crc32c", "sha1", or "sha256".
supported values: "CRC32C", "CRC32", "SHA1", or "SHA256".
* - requestChecksumRequired
- ``boolean``
- Indicates an operation requires a checksum in its HTTP request. By
Expand All @@ -1267,17 +1267,17 @@ The ``httpChecksum`` trait is a structure that contains the following members:
- ``set<string>``
- Defines the checksum algorithms clients SHOULD look for when validating
checksums returned in the HTTP response. Each algorithm must be one of
the following supported values: "crc32c", "crc32", "sha1", or "sha256".
the following supported values: "CRC32C", "CRC32", "SHA1", or "SHA256".

The ``httpChecksum`` trait MUST define at least one of the request checksumming
behavior, by setting the ``requestAlgorithmMember`` or
``requestChecksumRequired`` property, or the response checksumming behavior, by
setting the ``requestValidationModeMember`` property.

The following is an example of the ``httpChecksum`` trait that defines required
request checksum behavior with support for the "crc32c", "crc32c", "sha1", and
"sha256" algorithms *and* response checksum behavior with support for the
"crc32c", "crc32c", "sha1", and "sha256" algorithms, enabled by the
request checksum behavior with support for the "CRC32C", "CRC32", "SHA1", and
"SHA256" algorithms *and* response checksum behavior with support for the
"CRC32C", "CRC32", "SHA1", and "SHA256" algorithms, enabled by the
``validationMode`` member.

Users of the ``PutSomething`` operation will opt in to request checksums by
Expand All @@ -1292,7 +1292,7 @@ setting the ``validationMode`` input property to "ENABLED".
requestChecksumRequired: true,
requestAlgorithmMember: "checksumAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c", "crc32", "sha1", "sha256"]
responseAlgorithms: ["CRC32C", "CRC32", "SHA1", "SHA256"]
)
operation PutSomething {
input: PutSomethingInput,
Expand All @@ -1312,19 +1312,19 @@ setting the ``validationMode`` input property to "ENABLED".

@enum([
{
value: "crc32c",
value: "CRC32C",
name: "CRC32C"
},
{
value: "crc32",
value: "CRC32",
name: "CRC32"
},
{
value: "sha1",
value: "SHA1",
name: "SHA1"
},
{
value: "sha256",
value: "SHA256",
name: "SHA256"
}
])
Expand Down Expand Up @@ -1470,8 +1470,8 @@ Resolving checksum name

The checksum name MUST be used as both header name and trailer name. A checksum
name MUST conform to the pattern ``x-amz-checksum-*``, where `*` is the defined
algorithm name. For example, the checksum name for the ``sha256`` algorithm is
``x-amz-checksum-sha256``.
algorithm name in lower case. For example, the checksum name for the ``SHA256``
algorithm is ``x-amz-checksum-sha256``.

.. _aws.protocols#httpChecksum-trait_header-conflict-behavior:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ service MyService {
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@http(method: "GET", uri: "/unsupported")
@readonly
Expand All @@ -35,19 +35,19 @@ structure ValidEnumsOutput {}

@enum([
{
value: "crc32c",
value: "CRC32C",
name: "CRC32C"
},
{
value: "crc32",
value: "CRC32",
name: "CRC32"
},
{
value: "sha1",
value: "SHA1",
name: "SHA1"
},
{
value: "sha256",
value: "SHA256",
name: "SHA256"
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
Expand All @@ -37,7 +38,7 @@
public final class HttpChecksumTrait extends AbstractTrait implements ToSmithyBuilder<HttpChecksumTrait> {
public static final ShapeId ID = ShapeId.from("aws.protocols#httpChecksum");
public static final String CHECKSUM_PREFIX = "x-amz-checksum-";
public static final List<String> CHECKSUM_ALGORITHMS = ListUtils.of("crc32c", "crc32", "sha1", "sha256");
public static final List<String> CHECKSUM_ALGORITHMS = ListUtils.of("CRC32C", "CRC32", "SHA1", "SHA256");
public static final List<String> VALIDATION_MODES = ListUtils.of("ENABLED");

public static final String REQUEST_CHECKSUM_REQUIRED = "requestChecksumRequired";
Expand Down Expand Up @@ -109,6 +110,16 @@ public Optional<String> getRequestValidationModeMember() {
return Optional.ofNullable(requestValidationModeMember);
}

/**
* Gets the normalized location name for a checksum algorithm.
*
* @param checksumAlgorithm The algorithm to get a location name of.
* @return The normalized location name.
*/
public static String getChecksumLocationName(String checksumAlgorithm) {
return CHECKSUM_PREFIX + checksumAlgorithm.toLowerCase(Locale.US);
}

@Override
protected Node createNode() {
ObjectNode.Builder builder = ObjectNode.objectNodeBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.MemberShape;
Expand Down Expand Up @@ -187,7 +188,8 @@ private List<ValidationEvent> validateHeaderConflicts(OperationShape operation,
events.add(danger(operation, format("The `httpPrefixHeaders` binding of `%s` uses"
+ " the prefix `%s` that conflicts with the prefix `%s` used by the"
+ " `httpChecksum` trait.",
member.getId().getName(), headerPrefix, HttpChecksumTrait.CHECKSUM_PREFIX)));
member.getId().getName(), headerPrefix.toLowerCase(Locale.US),
HttpChecksumTrait.CHECKSUM_PREFIX)));
}
});

Expand All @@ -200,7 +202,8 @@ private List<ValidationEvent> validateHeaderConflicts(OperationShape operation,
if (headerName.startsWith(HttpChecksumTrait.CHECKSUM_PREFIX)) {
events.add(warning(operation, format("The `httpHeader` binding of `%s` on `%s`"
+ " starts with the prefix `%s` used by the `httpChecksum` trait.",
headerName, member.getId().getName(), HttpChecksumTrait.CHECKSUM_PREFIX)));
headerName.toLowerCase(Locale.US), member.getId().getName(),
HttpChecksumTrait.CHECKSUM_PREFIX)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,19 @@
"traits": {
"smithy.api#enum": [
{
"value": "crc32c",
"value": "CRC32C",
"name": "CRC32C"
},
{
"value": "crc32",
"value": "CRC32",
"name": "CRC32"
},
{
"value": "sha1",
"value": "SHA1",
"name": "SHA1"
},
{
"value": "sha256",
"value": "SHA256",
"name": "SHA256"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class HttpChecksumTraitTest {
public void loadsTrait() {
TraitFactory provider = TraitFactory.createServiceFactory();

List<String> algorithms = new ArrayList<>(Arrays.asList("crc32c", "crc32", "sha1", "sha256"));
List<String> algorithms = new ArrayList<>(Arrays.asList("CRC32C", "CRC32", "SHA1", "SHA256"));
List<Node> responseAlgorithmNodes = new ArrayList<>();
for (String algorithm: algorithms) {
responseAlgorithmNodes.add(Node.from(algorithm));
Expand All @@ -62,7 +62,7 @@ public void loadsTrait() {
assertThat(checksumTrait.isRequestChecksumRequired(), is(true));
assertThat(checksumTrait.getRequestAlgorithmMember().get(), equalTo("ChecksumAlgorithm"));
assertThat(checksumTrait.getRequestValidationModeMember().get(), equalTo("ChecksumMode"));
assertThat(checksumTrait.getResponseAlgorithms(), containsInRelativeOrder("crc32c", "crc32", "sha1", "sha256"));
assertThat(checksumTrait.getResponseAlgorithms(), containsInRelativeOrder("CRC32C", "CRC32", "SHA1", "SHA256"));

assertThat(node.expectBooleanMember("requestChecksumRequired"), equalTo(BooleanNode.from(true)));
assertThat(node.expectStringMember("requestAlgorithmMember"), equalTo(Node.from("ChecksumAlgorithm")));
Expand All @@ -71,4 +71,9 @@ public void loadsTrait() {
assertThat(checksumTrait.toNode(), equalTo(node));
assertThat(checksumTrait.toBuilder().build(), equalTo(checksumTrait));
}

@Test
public void normalizesAlgorithmName() {
assertThat(HttpChecksumTrait.getChecksumLocationName("CRC32C"), equalTo("x-amz-checksum-crc32c"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use aws.protocols#httpChecksum
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@http(method: "GET", uri: "/headerconflict")
@readonly
Expand All @@ -19,7 +19,7 @@ operation HeaderConflicts {
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@http(method: "GET", uri: "/headersconflict")
@readonly
Expand All @@ -33,7 +33,7 @@ operation HeadersConflicts {
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@http(method: "GET", uri: "/noconflict")
@readonly
Expand All @@ -57,7 +57,7 @@ structure HeaderConflictsInput {
}

structure HeaderConflictsOutput {
@httpHeader("x-amz-checksum-crc32")
@httpHeader("x-amz-checksum-CRC32")
warningConflictHeader: String,
}

Expand Down Expand Up @@ -102,7 +102,7 @@ structure NoConflictsOutput {
@error("client")
@httpError(400)
structure HeaderConflictError {
@httpHeader("x-amz-checksum-crc32")
@httpHeader("x-amz-checksum-CRC32")
warningConflictHeader: String,
}

Expand All @@ -125,19 +125,19 @@ structure NoConflictError {

@enum([
{
value: "crc32c",
value: "CRC32C",
name: "CRC32C"
},
{
value: "crc32",
value: "CRC32",
name: "CRC32"
},
{
value: "sha1",
value: "SHA1",
name: "SHA1"
},
{
value: "sha256",
value: "SHA256",
name: "SHA256"
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[SUPPRESSED] smithy.example#ValidEnums: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[SUPPRESSED] smithy.example#NoEnums: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[SUPPRESSED] smithy.example#NoMember: This shape applies a trait that is unstable: aws.protocols#httpChecksum | UnstableTrait
[ERROR] smithy.example#InvalidEnums: The `requestAlgorithmMember` property of the `httpChecksum` trait targets a member with an `enum` trait that contains unsupported values: `sha2` | HttpChecksumTrait
[ERROR] smithy.example#InvalidEnums: The `requestAlgorithmMember` property of the `httpChecksum` trait targets a member with an `enum` trait that contains unsupported values: `SHA2` | HttpChecksumTrait
[ERROR] smithy.example#InvalidEnums: The `requestValidationModeMember` property of the `httpChecksum` trait targets a member with an `enum` trait that contains unsupported values: `DISABLED` | HttpChecksumTrait
[ERROR] smithy.example#NoEnums: The `requestAlgorithmMember` property of the `httpChecksum` trait targets a member that does not resolve an `enum` trait. | HttpChecksumTrait
[ERROR] smithy.example#NoEnums: The `requestValidationModeMember` property of the `httpChecksum` trait targets a member that does not resolve an `enum` trait. | HttpChecksumTrait
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use aws.protocols#httpChecksum
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@suppress(["UnstableTrait"])
operation ValidEnums {
Expand All @@ -24,7 +24,7 @@ structure ValidEnumsOutput {}
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@suppress(["UnstableTrait"])
operation InvalidEnums {
Expand All @@ -42,7 +42,7 @@ structure InvalidEnumsOutput {}
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@suppress(["UnstableTrait"])
operation NoEnums {
Expand All @@ -60,7 +60,7 @@ structure NoEnumsOutput {}
@httpChecksum(
requestAlgorithmMember: "requestAlgorithm",
requestValidationModeMember: "validationMode",
responseAlgorithms: ["crc32c"]
responseAlgorithms: ["CRC32C"]
)
@suppress(["UnstableTrait"])
operation NoMember {
Expand All @@ -74,19 +74,19 @@ structure NoMemberOutput {}

@enum([
{
value: "crc32c",
value: "CRC32C",
name: "CRC32C"
},
{
value: "crc32",
value: "CRC32",
name: "CRC32"
},
{
value: "sha1",
value: "SHA1",
name: "SHA1"
},
{
value: "sha256",
value: "SHA256",
name: "SHA256"
}
])
Expand All @@ -103,7 +103,7 @@ string ValidationMode

@enum([
{
value: "sha2",
value: "SHA2",
name: "SHA2"
}
])
Expand Down
Loading