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

Add relativeDocumentation to aws.iam#iamResource and aws.iam#defineConditionKeys traits #2027

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
8 changes: 8 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,10 @@ 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 path that defines more information about the condition key
within a set of IAM-related documentation.

.. code-block:: smithy

Expand Down Expand Up @@ -410,6 +414,10 @@ members:
* - name
- ``string``
- The name of the resource in AWS IAM.
* - relativeDocumentation
- ``string``
- A relative URL path that defines more information about the resource
within a set of IAM-related documentation.

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,22 @@ public Optional<String> getExternalDocumentation() {
return Optional.ofNullable(externalDocumentation);
}

/**
* Get the relative URL path that defines more information about the condition key
* within a set of IAM-related 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 +106,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 +121,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 +155,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,16 @@ public Optional<String> getName() {
return Optional.of(name);
}

/**
* Get the relative URL path that defines more information about the resource
* within a set of IAM-related documentation.
*
* @return A relative URL to the documentation page.
*/
public Optional<String> getRelativeDocumentation() {
return Optional.ofNullable(relativeDocumentation);
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -80,6 +92,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 +105,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 @@ -39,6 +39,10 @@ structure disableConditionKeyInference {}
structure iamResource {
/// The name of the resource in AWS IAM.
name: String

/// A relative URL path that defines more information about the resource
/// within a set of IAM-related documentation.
relativeDocumentation: String
}

/// Other actions that the invoker must be authorized to perform when executing the targeted operation.
Expand All @@ -63,14 +67,18 @@ 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 path that defines more information about the condition key
/// within a set of IAM-related documentation.
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