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

Adding IAM Action name trait to override using the API operation name #1665

Merged
merged 6 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 39 additions & 0 deletions docs/source-2.0/aws/aws-iam.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

-------------------------------
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

``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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Trait selector
``:test(operation)``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to be wrapped in :test().

Value type
``string``

Operations not annotated with the ``actionName`` trait use the operation name as the action name.
Copy link
Contributor

Choose a reason for hiding this comment

The 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 operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The first OperationA should be in double backticks.
  • s/annoated/annotated
  • "so has the action name OperationA which is the same as the operation name." -> and resolves the action name of OperationA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

* OperationB has the ``actionName`` trait, so has the action name ``OverridingActionName``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OperationB should be in double backticks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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:

Expand Down
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
Expand Up @@ -5,3 +5,4 @@ software.amazon.smithy.aws.iam.traits.DisableConditionKeyInferenceTrait$Provider
software.amazon.smithy.aws.iam.traits.RequiredActionsTrait$Provider
software.amazon.smithy.aws.iam.traits.SupportedPrincipalTypesTrait$Provider
software.amazon.smithy.aws.iam.traits.IamResourceTrait$Provider
software.amazon.smithy.aws.iam.traits.ActionNameTrait$Provider
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}