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 ResourceIndex is also included to make using
this information more accessible and to handle derived property
mutabilities.
  • Loading branch information
kstich committed Oct 16, 2020
1 parent a6aa693 commit ba01567
Show file tree
Hide file tree
Showing 33 changed files with 2,785 additions and 0 deletions.
780 changes: 780 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 @@ -22,3 +22,4 @@ include ":smithy-jsonschema"
include ":smithy-openapi"
include ":smithy-utils"
include ":smithy-protocol-test-traits"
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 AdditionalIdentifierTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#additionalIdentifier");

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

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

public static final class Provider extends AnnotationTrait.Provider<AdditionalIdentifierTrait> {
public Provider() {
super(ID, AdditionalIdentifierTrait::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 ExcludePropertyTrait extends AnnotationTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#excludeProperty");

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

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

public static final class Provider extends AnnotationTrait.Provider<ExcludePropertyTrait> {
public Provider() {
super(ID, ExcludePropertyTrait::new);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 the CloudFormation mutability of a structure member.
*/
public final class MutabilityTrait extends StringTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#mutability");

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

public static final class Provider extends StringTrait.Provider<MutabilityTrait> {
public Provider() {
super(ID, MutabilityTrait::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 MutabilityTraitValidator extends AbstractValidator {
@Override
public List<ValidationEvent> validate(Model model) {
List<ValidationEvent> events = new ArrayList<>();

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

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 PropertyNameTrait extends StringTrait {
public static final ShapeId ID = ShapeId.from("aws.cloudformation#propertyName");

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

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

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

0 comments on commit ba01567

Please sign in to comment.