Skip to content

Commit

Permalink
Add relativeDocumentation to aws.iam#iamResource and aws.iam#defineCo…
Browse files Browse the repository at this point in the history
…nditionKeys traits
  • Loading branch information
AndrewFossAWS committed Nov 3, 2023
1 parent 0fc277a commit c55aad8
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/source-2.0/aws/aws-iam.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ Each condition key structure supports the following members:
* - externalDocumentation
- ``string``
- A valid URL that defines more information about the condition key.
* - relativeDocumentation
- ``string``
- A relative URL that defines more information about the condition key.

.. code-block:: smithy
Expand Down Expand Up @@ -410,6 +413,9 @@ members:
* - name
- ``string``
- The name of the resource in AWS IAM.
* - relativeDocumentation
- ``string``
- A relative URL that defines more information about the resource.

The following example defines a simple resource with a name in AWS IAM that
deviates from the :ref:`shape name of the shape ID <shape-id>` of the resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ public final class ConditionKeyDefinition implements ToNode, ToSmithyBuilder<Con
private static final String TYPE = "type";
private static final String DOCUMENTATION = "documentation";
private static final String EXTERNAL_DOCUMENTATION = "externalDocumentation";
private static final String RELATIVE_DOCUMENTATION = "relativeDocumentation";

private final String type;
private final String documentation;
private final String externalDocumentation;
private final String relativeDocumentation;

private ConditionKeyDefinition(Builder builder) {
type = SmithyBuilder.requiredState(TYPE, builder.type);
documentation = builder.documentation;
externalDocumentation = builder.externalDocumentation;
relativeDocumentation = builder.relativeDocumentation;
}

public static Builder builder() {
Expand All @@ -51,6 +54,8 @@ public static ConditionKeyDefinition fromNode(Node value) {
.ifPresent(builder::documentation);
objectNode.getStringMember(EXTERNAL_DOCUMENTATION).map(StringNode::getValue)
.ifPresent(builder::externalDocumentation);
objectNode.getStringMember(RELATIVE_DOCUMENTATION).map(StringNode::getValue)
.ifPresent(builder::relativeDocumentation);

return builder.build();
}
Expand All @@ -76,11 +81,21 @@ public Optional<String> getExternalDocumentation() {
return Optional.ofNullable(externalDocumentation);
}

/**
* Get the relative URL for the condition key documentation.
*
* @return A relative URL to the documentation page.
*/
public Optional<String> getRelativeDocumentation() {
return Optional.ofNullable(relativeDocumentation);
}

@Override
public SmithyBuilder<ConditionKeyDefinition> toBuilder() {
return builder()
.documentation(documentation)
.externalDocumentation(externalDocumentation)
.relativeDocumentation(relativeDocumentation)
.type(type);
}

Expand All @@ -90,6 +105,7 @@ public Node toNode() {
.withMember(TYPE, Node.from(type))
.withOptionalMember(DOCUMENTATION, getDocumentation().map(Node::from))
.withOptionalMember(EXTERNAL_DOCUMENTATION, getExternalDocumentation().map(Node::from))
.withOptionalMember(RELATIVE_DOCUMENTATION, getRelativeDocumentation().map(Node::from))
.build();
}

Expand All @@ -104,18 +120,20 @@ public boolean equals(Object o) {
ConditionKeyDefinition that = (ConditionKeyDefinition) o;
return Objects.equals(type, that.type)
&& Objects.equals(documentation, that.documentation)
&& Objects.equals(externalDocumentation, that.externalDocumentation);
&& Objects.equals(externalDocumentation, that.externalDocumentation)
&& Objects.equals(relativeDocumentation, that.relativeDocumentation);
}

@Override
public int hashCode() {
return Objects.hash(type, documentation, externalDocumentation);
return Objects.hash(type, documentation, externalDocumentation, relativeDocumentation);
}

public static final class Builder implements SmithyBuilder<ConditionKeyDefinition> {
private String type;
private String documentation;
private String externalDocumentation;
private String relativeDocumentation;

@Override
public ConditionKeyDefinition build() {
Expand All @@ -136,5 +154,10 @@ public Builder externalDocumentation(String externalDocumentation) {
this.externalDocumentation = externalDocumentation;
return this;
}

public Builder relativeDocumentation(String relativeDocumentation) {
this.relativeDocumentation = relativeDocumentation;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public final class IamResourceTrait extends AbstractTrait
public static final ShapeId ID = ShapeId.from("aws.iam#iamResource");

public final String name;
public final String relativeDocumentation;

private IamResourceTrait(Builder builder) {
super(ID, builder.getSourceLocation());
name = builder.name;
relativeDocumentation = builder.relativeDocumentation;
}

/**
Expand All @@ -48,6 +50,15 @@ public Optional<String> getName() {
return Optional.of(name);
}

/**
* Get the relative URL for the resource documentation.
*
* @return A relative URL for the resource.
*/
public Optional<String> getRelativeDocumentation() {
return Optional.ofNullable(relativeDocumentation);
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -80,6 +91,7 @@ public Trait createTrait(ShapeId target, Node value) {

public static final class Builder extends AbstractTraitBuilder<IamResourceTrait, Builder> {
private String name;
private String relativeDocumentation;

private Builder() {}

Expand All @@ -92,5 +104,10 @@ public Builder name(String name) {
this.name = name;
return this;
}

public Builder relativeDocumentation(String relativeDocumentation) {
this.relativeDocumentation = relativeDocumentation;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
@SmithyInternalApi
public class IamResourceTraitValidator extends AbstractValidator {

@Override
public List<ValidationEvent> validate(Model model) {
List<ValidationEvent> results = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ structure disableConditionKeyInference {}
structure iamResource {
/// The name of the resource in AWS IAM.
name: String

/// A relative URL to documentation for an individual IAM resource.
relativeDocumentation: String
}

/// Other actions that the invoker must be authorized to perform when executing the targeted operation.
Expand All @@ -63,14 +66,17 @@ list supportedPrincipalTypes {
/// A defined condition key to appear within a service in addition to inferred and global condition keys.
@private
structure ConditionKeyDefinition {
@required
type: ConditionKeyType

/// Defines documentation about the condition key.
documentation: String

/// A valid URL that defines more information about the condition key.
externalDocumentation: String

@required
type: ConditionKeyType
/// A relative URL to documentation for an individual IAM context key.
relativeDocumentation: String
}

/// The IAM policy type of the value that will supplied for this context key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public void successfullyLoadsConditionKeys() {
assertThat(index.getConditionKeyNames(service, ShapeId.from("smithy.example#GetResource2")), is(empty()));

// Defined context keys are assembled from the names and mapped with the definitions.
assertEquals(index.getDefinedConditionKeys(service).get("foo:baz").getDocumentation().get(), "Foo baz");
assertEquals(index.getDefinedConditionKeys(service).get("foo:baz").getRelativeDocumentation().get(),
"condition-keys.html");
assertThat(index.getDefinedConditionKeys(service).get("myservice:Resource1Id1").getDocumentation(),
not(Optional.empty()));
assertEquals(index.getDefinedConditionKeys(service).get("myservice:ResourceTwoId2").getDocumentation().get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public void loadsFromModel() {

assertTrue(superResource.hasTrait(IamResourceTrait.class));
assertEquals(superResource.expectTrait(IamResourceTrait.class).getName().get(), "super");
assertEquals(superResource.expectTrait(IamResourceTrait.class).getRelativeDocumentation().get(), "API-Super.html");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ service MyService {
resources: [SuperResource]
}

@aws.iam#iamResource(name: "super")
@aws.iam#iamResource(
name: "super",
relativeDocumentation: "API-Super.html"
)
@arn(template: "super/{id1}")
resource SuperResource {
identifiers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ $version: "1.0"
namespace smithy.example

@aws.api#service(sdkId: "My")
@aws.iam#defineConditionKeys("foo:baz": {type: "String", documentation: "Foo baz"})
@aws.iam#defineConditionKeys(
"foo:baz": {
type: "String",
documentation: "Foo baz",
relativeDocumentation: "condition-keys.html"
}
)
service MyService {
version: "2019-02-20",
operations: [Operation1],
Expand Down

0 comments on commit c55aad8

Please sign in to comment.