-
Notifications
You must be signed in to change notification settings - Fork 218
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
Adding IAM Action name trait to override using the API operation name #1665
Changes from 3 commits
f05d465
e6b2dfe
1439027
67fde56
d6e5843
91f96e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,6 +392,45 @@ deviates from the :ref:`shape name of the shape ID <shape-id>` of the resource. | |
} | ||
} | ||
|
||
.. smithy-trait:: aws.iam#actionName | ||
.. _aws.iam#actionName-trait: | ||
|
||
------------------------------- | ||
``aws.iam#actionName`` trait | ||
------------------------------- | ||
|
||
Summary | ||
Provides the ability to override the default action name for the operation. By convention, the action name is the same as the operation name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you wrap the new contents at 80 chars like the rest of the spec? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify the summary to "Provides a custom IAM action name." since the rest is duplicate information with somewhere else in the spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
Trait selector | ||
``:test(operation)`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't need to be wrapped in |
||
Value type | ||
``string`` | ||
|
||
Operations not annotated with the ``actionName`` trait use the operation name as the action name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults to the :ref:`shape name of the shape ID ` of the targeted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
|
||
The following example defines two operations: | ||
|
||
* OperationA is not annoated with the ``actionName`` trait, so has the action name ``OperationA`` which is the same as the operation name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
* OperationB has the ``actionName`` trait, so has the action name ``OverridingActionName``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
|
||
.. code-block:: smithy | ||
|
||
$version: "2" | ||
|
||
namespace smithy.example | ||
|
||
use aws.iam#actionName | ||
|
||
service MyService { | ||
version: "2020-07-02" | ||
operations: [OperationA, OperationB] | ||
} | ||
|
||
operation OperationA {} | ||
|
||
@actionName("OverridingActionName") | ||
operation OperationB {} | ||
|
||
|
||
.. _deriving-condition-keys: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.aws.iam.traits; | ||
|
||
import software.amazon.smithy.model.FromSourceLocation; | ||
import software.amazon.smithy.model.SourceLocation; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
import software.amazon.smithy.model.traits.StringTrait; | ||
|
||
public final class ActionNameTrait extends StringTrait { | ||
|
||
public static final ShapeId ID = ShapeId.from("aws.iam#actionName"); | ||
|
||
private ActionNameTrait(String action) { | ||
super(ID, action, SourceLocation.NONE); | ||
} | ||
|
||
private ActionNameTrait(String action, FromSourceLocation sourceLocation) { | ||
super(ID, action, sourceLocation); | ||
} | ||
|
||
kstich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public static final class Provider extends StringTrait.Provider<ActionNameTrait> { | ||
public Provider() { | ||
super(ID, ActionNameTrait::new); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,18 @@ | |
"smithy.api#private": {}, | ||
"smithy.api#documentation": "An IAM policy principal type." | ||
} | ||
}, | ||
"aws.iam#actionName": { | ||
"type": "string", | ||
"member": { | ||
"target": "aws.iam#IamIdentifier" | ||
}, | ||
"traits": { | ||
"smithy.api#trait": { | ||
"selector": "operation" | ||
}, | ||
"smithy.api#documentation": "Provides the ability to override the default action name for the operation. By convention, the action name is the same as the operation name." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/convention/default Replace the first sentence with the one recommended for the spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.aws.iam.traits; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class ActionNameTraitTest { | ||
@Test | ||
public void loadsFromModel() { | ||
Model result = Model.assembler() | ||
.discoverModels(getClass().getClassLoader()) | ||
.addImport(getClass().getResource("actionname-override.smithy")) | ||
.assemble() | ||
.unwrap(); | ||
|
||
Shape shape = result.expectShape(ShapeId.from("smithy.example#Echo")); | ||
ActionNameTrait trait = shape.expectTrait(ActionNameTrait.class); | ||
assertThat(trait.getValue(), equalTo("overridingActionName")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$version: "2.0" | ||
namespace smithy.example | ||
|
||
@aws.iam#actionName("overridingActionName") | ||
operation Echo {} | ||
|
||
operation GetResource2 { | ||
input: GetResource2Input | ||
} | ||
|
||
structure GetResource2Input { | ||
id1: String, | ||
|
||
@required | ||
id2: String | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
-
wrapping needs to be the same length as the header content.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated