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

Adds httpChecksumRequired trait #433

Merged
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
28 changes: 28 additions & 0 deletions docs/source/1.0/spec/core/behavior-traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,31 @@ to request additional results from the operation.
presence, absence, or contents of a continuation token.

.. _UUID: https://tools.ietf.org/html/rfc4122


.. _httpChecksumRequired-trait:

------------------------------
``httpChecksumRequired`` trait
------------------------------

Summary
Indicates that an operation requires a checksum in its HTTP request. By
default, the checksum used for a service is a MD5 checksum passed in the
Content-MD5 header.
Trait selector
``operation``
Value type
Annotation trait.
See
:rfc:`1864`

.. tabs::

.. code-tab:: smithy

@httpChecksumRequired
operation PutSomething {
input: PutSomethingInput,
output: PutSomethingOutput
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import software.amazon.smithy.model.traits.HttpApiKeyAuthTrait;
import software.amazon.smithy.model.traits.HttpBasicAuthTrait;
import software.amazon.smithy.model.traits.HttpBearerAuthTrait;
import software.amazon.smithy.model.traits.HttpChecksumRequiredTrait;
import software.amazon.smithy.model.traits.HttpDigestAuthTrait;
import software.amazon.smithy.model.traits.HttpErrorTrait;
import software.amazon.smithy.model.traits.HttpHeaderTrait;
Expand Down Expand Up @@ -158,6 +159,7 @@ public final class Prelude {
ExamplesTrait.ID,
ExternalDocumentationTrait.ID,
HostLabelTrait.ID,
HttpChecksumRequiredTrait.ID,
HttpErrorTrait.ID,
HttpHeaderTrait.ID,
HttpLabelTrait.ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.model.traits;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;

/**
* Indicates that an operation requires a checksum in its HTTP request.
* By default, the checksum used for a service is a MD5 checksum passed
* in the Content-MD5 header.
*/
public final class HttpChecksumRequiredTrait extends AnnotationTrait {

public static final ShapeId ID = ShapeId.from("smithy.api#httpChecksumRequired");

public HttpChecksumRequiredTrait(ObjectNode node) {
super(ID, node);
}

public HttpChecksumRequiredTrait() {
this(Node.objectNode());
}

public static final class Provider extends AnnotationTrait.Provider<HttpChecksumRequiredTrait> {
public Provider() {
super(ID, HttpChecksumRequiredTrait::new);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ software.amazon.smithy.model.traits.EventPayloadTrait$Provider
software.amazon.smithy.model.traits.ExamplesTrait$Provider
software.amazon.smithy.model.traits.ExternalDocumentationTrait$Provider
software.amazon.smithy.model.traits.HostLabelTrait$Provider
software.amazon.smithy.model.traits.HttpChecksumRequiredTrait$Provider
software.amazon.smithy.model.traits.HttpErrorTrait$Provider
software.amazon.smithy.model.traits.HttpHeaderTrait$Provider
software.amazon.smithy.model.traits.HttpLabelTrait$Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,9 @@ list suppress {
@length(min: 1)
member: String
}

/// Marks an operation as requiring checksum in its HTTP request.
/// By default, the checksum used for a service is a MD5 checksum
/// passed in the Content-MD5 header.
@trait(selector: "operation")
structure httpChecksumRequired {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ERROR] ns.foo#InvalidInput: Trait `httpChecksumRequired` cannot be applied to `ns.foo#InvalidInput`. This trait may only be applied to shapes that match the following selector: operation | TraitTarget
[ERROR] ns.foo#InvalidOutput: Trait `httpChecksumRequired` cannot be applied to `ns.foo#InvalidOutput`. This trait may only be applied to shapes that match the following selector: operation | TraitTarget
[ERROR] ns.foo#InvalidError: Trait `httpChecksumRequired` cannot be applied to `ns.foo#InvalidError`. This trait may only be applied to shapes that match the following selector: operation | TraitTarget
[ERROR] ns.foo#InvalidStructure$Body: Trait `httpChecksumRequired` cannot be applied to `ns.foo#InvalidStructure$Body`. This trait may only be applied to shapes that match the following selector: operation | TraitTarget
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"smithy": "1.0",
"shapes": {
"ns.foo#Blob": {
"type": "blob"
},
"ns.foo#ValidOperation": {
"type": "operation",
"input": {
"target": "ns.foo#Input"
},
"output": {
"target": "ns.foo#Output"
},
"traits": {
"smithy.api#httpChecksumRequired": {}
}
},
"ns.foo#Input": {
"type": "structure",
"members": {
"Body": {
"target": "smithy.api#Blob"
}
}
},
"ns.foo#Output": {
"type": "structure",
"members": {
"Body": {
"target": "smithy.api#Blob"
}
}
},
"ns.foo#InvalidOperation": {
"type": "operation",
"input": {
"target": "ns.foo#Input"
},
"output": {
"target": "ns.foo#Output"
}
},
"ns.foo#InvalidInput": {
"type": "structure",
"members": {
"Body": {
"target": "smithy.api#Blob"
}
},
"traits": {
"smithy.api#httpChecksumRequired": {}
}
},
"ns.foo#InvalidOutput": {
"type": "structure",
"members": {
"Body": {
"target": "smithy.api#Blob"
}
},
"traits": {
"smithy.api#httpChecksumRequired": {}
}
},
"ns.foo#InvalidError": {
"type": "structure",
"members": {
"Body": {
"target": "smithy.api#Blob"
}
},
"traits": {
"smithy.api#error": "client",
"smithy.api#httpChecksumRequired": {}
}
},
"ns.foo#InvalidStructure": {
"type": "structure",
"members": {
"Body": {
"target": "smithy.api#Blob",
"traits": {
"smithy.api#httpChecksumRequired": {}
}
}
}
}
}
}