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 conditionKeyValue and conditionKeysResolvedByService traits #1677

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

0xjjoyy
Copy link
Contributor

@0xjjoyy 0xjjoyy commented Mar 14, 2023

Issue #, if available:

Description of changes:
Adding conditionKeyValue and conditionKeysResolvedByService traits

conditionKeyValue
Uses the associated member’s value as this condition key’s value. Needed when the member name doesn't match the condition key name.

conditionKeysResolvedByService
Specifies the list of IAM condition keys which must be resolved by the service, as opposed to being pulled from the request.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@0xjjoyy 0xjjoyy requested a review from a team as a code owner March 14, 2023 03:35
Value type
``string``

Specifies the list of IAM condition keys which must be resolved by the
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant with the Summary, can remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed redundant text

Specifies the list of IAM condition keys which must be resolved by the
service, as opposed to being pulled from the request.

The following example defines two operations:
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this interact with derived condition keys?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added
Derived resource condition keys MUST NOT be included
with the conditionKeysResolvedByService trait.

Trait selector
``service``
Value type
``string``
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a list<string>

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 to be a list

Value type
``string``

Uses the associated member’s value as this condition key’s value. Needed when
Copy link
Contributor

Choose a reason for hiding this comment

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

Should mimic the language for actionName.

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, also added that MUST also be defined via the :ref:aws.iam#defineConditionKeys-trait trait.


The following example defines two operations:

``myservice:ActionContextKey1`` is an service-specific IAM action
Copy link
Contributor

Choose a reason for hiding this comment

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

s/is an/is a

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 text

String conditionKey = trait.getValue();
if (!knownKeys.contains(conditionKey)) {
results.add(error(operation, String.format(
"This operation scoped within the `%s` service refers to an undefined "
Copy link
Contributor

Choose a reason for hiding this comment

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

This error message doesn't correctly map to the trait being validated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should also pass the trait in as the second parameter to error() for source location clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. added operation id and member id to the error message details
  2. ah cool, didn't realize there was sourcelocation on the trait. Added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added errorfiles test case

Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of content changed in this file that wasn't actually the specific test additions.

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 this file and applied only the new tests.

@0xjjoyy
Copy link
Contributor Author

0xjjoyy commented Apr 7, 2023

I've updated the pull request based on feedback.

}


@aws.iam#actionName("overridingActionName")
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: the Echo operation isn't needed to express the test here, can remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shapes and traits cleaned up.

"smithy:ActionContextKey3": { type: "String" },
"smithy:requesterId": { type: "String" }
)
@aws.iam#conditionKeysResolvedByService(["smithy:requesterId"])
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: the conditionKeysResolvedByService trait isn't needed to express the test here, can remove

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

$version: "2.0"
namespace smithy.example

use aws.iam#conditionKeyValue
Copy link
Contributor

Choose a reason for hiding this comment

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

The trait is applied with the namespace, meaning this use statement is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Copy link
Contributor

Choose a reason for hiding this comment

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

Should have newline at EOF

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Should have newline at EOF

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

ConditionKeyValueTrait trait = memberShape.expectTrait(ConditionKeyValueTrait.class);
String conditionKey = trait.getValue();
if (!knownKeys.contains(conditionKey)) {
results.add(error(memberShape, trait.getSourceLocation(), String.format(
Copy link
Contributor

Choose a reason for hiding this comment

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

trait doesn't need the getSourceLocation() call applied, it's handled by error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

}
}
if (!invalidNames.isEmpty()) {
results.add(error(service, trait.getSourceLocation(), String.format(
Copy link
Contributor

Choose a reason for hiding this comment

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

trait doesn't need the getSourceLocation() call applied, it's handled by error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

.. _aws.iam#conditionKeysResolvedByService-trait:

------------------------------------------------
``aws.iam#conditionKeysResolvedByService`` trait
Copy link
Contributor

Choose a reason for hiding this comment

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

What about serviceResolvedConditionKeys for the name of this trait? It's a clearer read to me and aligns more with the other IAM traits. Would need updating in several places (docs, code (ID, class names, etc.), test files.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

Copy link
Contributor Author

@0xjjoyy 0xjjoyy left a comment

Choose a reason for hiding this comment

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

addressed feedback
adding validation to check condition key value doesn't intersect with service resolved keys

@0xjjoyy 0xjjoyy requested a review from kstich June 6, 2023 03:50
Copy link
Contributor

@kstich kstich left a comment

Choose a reason for hiding this comment

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

A lot/all of the test case files could also use empty lines at EOF.

docs/source-2.0/aws/aws-iam.rst Outdated Show resolved Hide resolved
@aws.iam#defineConditionKeys(
"smithy:ServiceResolveContextKey": { type: "String" }
)
@aws.iam#conditionKeysResolvedByService(["smithy:ServiceResolveContextKey"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Will need to be updated with the trait rename.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated

@@ -0,0 +1,23 @@
$version: "2.0"
namespace smithy.example
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should have a new line between $version and `namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, updated

docs/source-2.0/aws/aws-iam.rst Outdated Show resolved Hide resolved
docs/source-2.0/aws/aws-iam.rst Outdated Show resolved Hide resolved
docs/source-2.0/aws/aws-iam.rst Outdated Show resolved Hide resolved
@0xjjoyy 0xjjoyy requested a review from a team as a code owner July 26, 2023 04:45
@0xjjoyy
Copy link
Contributor Author

0xjjoyy commented Jul 26, 2023

Updated based on feedback. Updated trait and class names to match new name. Added EOF to *.smithy and *.errors

@0xjjoyy 0xjjoyy requested a review from kstich July 26, 2023 18:54
"myservice:ActionContextKey1": { type: "String" },
"myservice:ActionContextKey2": { type: "String" }
)
@conditionKeyResolvers(["myservice:ActionContextKey1"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@conditionKeyResolvers(["myservice:ActionContextKey1"])
@serviceResolvedConditionKeys(["myservice:ActionContextKey1"])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated

@0xjjoyy 0xjjoyy requested a review from kstich August 9, 2023 03:54
@kstich
Copy link
Contributor

kstich commented Aug 17, 2023

Appears to need a rebase before merging, but content looks good.

@0xjjoyy 0xjjoyy requested a review from kstich August 18, 2023 17:32
@kstich kstich merged commit b5b708a into smithy-lang:main Aug 18, 2023
alextwoods pushed a commit to alextwoods/smithy that referenced this pull request Sep 15, 2023
)

* Adding conditionKeyValue and serviceResolvedConditionKeys traits
* Update trait constructors to be public
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants