-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
36 changed files
with
3,031 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ AWS specifications | |
aws-auth | ||
aws-iam | ||
amazon-apigateway | ||
aws-cloudformation | ||
|
||
|
||
AWS Protocols | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
43 changes: 43 additions & 0 deletions
43
...n/java/software/amazon/smithy/aws/cloudformation/traits/CfnAdditionalIdentifierTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...c/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnExcludePropertyTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...ts/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...in/java/software/amazon/smithy/aws/cloudformation/traits/CfnMutabilityTraitValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...n-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnNameTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.