Skip to content

Commit

Permalink
Add aws.cloudformation traits
Browse files Browse the repository at this point in the history
This commit adds several traits in the aws.cloudformation namespace,
contained in a new smithy-aws-cloudformation-traits package. These
traits indicate CloudFormation resources and the additional metadata
about their properties. A CfnResourceIndex is also included to make using
this information more accessible and to handle derived property
mutabilities.
  • Loading branch information
kstich committed Nov 13, 2020
1 parent ba959f0 commit 5bd9e9b
Show file tree
Hide file tree
Showing 36 changed files with 3,031 additions and 0 deletions.
846 changes: 846 additions & 0 deletions docs/source/1.0/spec/aws/aws-cloudformation.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/source/1.0/spec/aws/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ AWS specifications
aws-auth
aws-iam
amazon-apigateway
aws-cloudformation


AWS Protocols
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ include ":smithy-utils"
include ":smithy-protocol-test-traits"
include ':smithy-jmespath'
include ":smithy-waiters"
include ":smithy-aws-cloudformation-traits"
4 changes: 4 additions & 0 deletions smithy-aws-cloudformation-traits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Smithy AWS CloudFormation traits

See the [Smithy specification](https://awslabs.github.io/smithy/spec/)
for details on how these traits are used.
25 changes: 25 additions & 0 deletions smithy-aws-cloudformation-traits/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

description = "This module provides Smithy traits and validators for CloudFormation."

ext {
displayName = "Smithy :: AWS :: CloudFormation Traits"
moduleName = "software.amazon.smithy.aws.cloudformation.traits"
}

dependencies {
api project(":smithy-model")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.cloudformation.traits;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.AnnotationTrait;

/**
* Indicates that the CloudFormation property generated from this member is an
* additional identifier for the resource.
*/
public final class CfnAdditionalIdentifierTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#cfnAdditionalIdentifier");

public CfnAdditionalIdentifierTrait(ObjectNode node) {
super(ID, node);
}

public CfnAdditionalIdentifierTrait() {
this(Node.objectNode());
}

public static final class Provider extends AnnotationTrait.Provider<CfnAdditionalIdentifierTrait> {
public Provider() {
super(ID, CfnAdditionalIdentifierTrait::new);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.cloudformation.traits;

import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.AnnotationTrait;

/**
* Indicates that structure member should not be included in generated
* CloudFormation resource definitions.
*/
public final class CfnExcludePropertyTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#cfnExcludeProperty");

public CfnExcludePropertyTrait(ObjectNode node) {
super(ID, node);
}

public CfnExcludePropertyTrait() {
this(Node.objectNode());
}

public static final class Provider extends AnnotationTrait.Provider<CfnExcludePropertyTrait> {
public Provider() {
super(ID, CfnExcludePropertyTrait::new);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.cloudformation.traits;

import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.StringTrait;

/**
* Indicates an explicit CloudFormation mutability of the structure member
* when part of a CloudFormation resource.
*/
public final class CfnMutabilityTrait extends StringTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#cfnMutability");

public CfnMutabilityTrait(String value, SourceLocation sourceLocation) {
super(ID, value, sourceLocation);
}

public static final class Provider extends StringTrait.Provider<CfnMutabilityTrait> {
public Provider() {
super(ID, CfnMutabilityTrait::new);
}
}

public boolean isFullyMutable() {
return getValue().equals("full");
}

public boolean isCreate() {
return getValue().equals("create");
}

public boolean isCreateAndRead() {
return getValue().equals("create-and-read");
}

public boolean isRead() {
return getValue().equals("read");
}

public boolean isWrite() {
return getValue().equals("write");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.cloudformation.traits;

import java.util.ArrayList;
import java.util.List;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.validation.AbstractValidator;
import software.amazon.smithy.model.validation.ValidationEvent;

/**
* Validates that members marked as having write-only mutability are not also
* marked as additional identifiers for their CloudFormation resource.
*/
public final class CfnMutabilityTraitValidator extends AbstractValidator {
@Override
public List<ValidationEvent> validate(Model model) {
List<ValidationEvent> events = new ArrayList<>();

for (Shape shape : model.getShapesWithTrait(CfnMutabilityTrait.class)) {
CfnMutabilityTrait trait = shape.expectTrait(CfnMutabilityTrait.class);
// Additional identifiers must be able to be read, so write and
// create mutabilities cannot overlap.
if (shape.hasTrait(CfnAdditionalIdentifierTrait.ID) && (trait.isWrite() || trait.isCreate())) {
events.add(error(shape, trait, String.format("Member with the mutability value of \"%s\" "
+ "is also marked as an additional identifier", trait.getValue())));
}
}

return events;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.cloudformation.traits;

import software.amazon.smithy.model.SourceLocation;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.StringTrait;

public final class CfnNameTrait extends StringTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#cfnName");

public CfnNameTrait(String value, SourceLocation sourceLocation) {
super(ID, value, sourceLocation);
}

public CfnNameTrait(String value) {
this(value, SourceLocation.NONE);
}

public static final class Provider extends StringTrait.Provider<CfnNameTrait> {
public Provider() {
super(ID, CfnNameTrait::new);
}
}
}
Loading

0 comments on commit 5bd9e9b

Please sign in to comment.