Skip to content
This repository has been archived by the owner on Dec 28, 2019. It is now read-only.

Commit

Permalink
#1 check for required resource properties
Browse files Browse the repository at this point in the history
  • Loading branch information
shalupov committed Feb 26, 2014
1 parent fca9bb7 commit b543ccd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.intellij.aws.cloudformation.metadata;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class CloudFormationResourceType {
public String name;
Expand All @@ -16,4 +18,15 @@ public CloudFormationResourceProperty findProperty(String name) {

return null;
}

public Set<String> getRequiredProperties() {
Set<String> requiredProperties = new HashSet<String>();
for (CloudFormationResourceProperty property : properties) {
if (property.required) {
requiredProperties.add(property.name);
}
}

return requiredProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ format.no.outputs.declared=the Outputs section must declare at least one stack o
format.type.property.required=Type property is required for resource
format.unknown.type=Unknown CloudFormation resource type\: {0}
format.properties.property.should.properties.list=Expected properties list
format.unknown.resource.type.property=Unknown resource type property\: {0}
format.unknown.resource.type.property=Unknown resource type property\: {0}
format.required.resource.properties.are.not.set=Required resource properties are not set\: {0}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

public class CloudFormationFormatChecker {
Expand Down Expand Up @@ -174,9 +176,21 @@ private void resource(JSProperty resourceProperty) {
final JSProperty propertiesProperty = obj.findProperty(CloudFormationConstants.PropertiesPropertyName);
if (propertiesProperty != null) {
resourceProperties(propertiesProperty, typeProperty);
} else {
final String resourceType = checkAndGetUnquotedStringText(typeProperty.getValue());
if (resourceType != null) {
final CloudFormationResourceType resourceTypeMetadata = CloudFormationMetadataProvider.METADATA.findResourceType(resourceType);
if (resourceTypeMetadata != null) {
Set<String> requiredProperties = new HashSet<String>(resourceTypeMetadata.getRequiredProperties());
if (!requiredProperties.isEmpty()) {
final String requiredPropertiesString = StringUtil.join(requiredProperties, " ");
addProblemOnNameElement(
resourceProperty,
CloudFormationBundle.getString("format.required.resource.properties.are.not.set", requiredPropertiesString));
}
}
}
}

// TODO Handle case with required properties and no Properties section
}

private void resourceProperties(JSProperty propertiesProperty, JSProperty typeProperty) {
Expand All @@ -196,6 +210,8 @@ private void resourceProperties(JSProperty propertiesProperty, JSProperty typePr
return;
}

Set<String> requiredProperties = new HashSet<String>(resourceType.getRequiredProperties());

for (JSProperty property : properties.getProperties()) {
final String propertyName = property.getName();
if (propertyName == null) {
Expand All @@ -205,26 +221,26 @@ private void resourceProperties(JSProperty propertiesProperty, JSProperty typePr
if (resourceType.findProperty(propertyName) == null) {
addProblemOnNameElement(property, CloudFormationBundle.getString("format.unknown.resource.type.property", propertyName));
}

requiredProperties.remove(propertyName);
}

// TODO Required properties
if (!requiredProperties.isEmpty()) {
final String requiredPropertiesString = StringUtil.join(requiredProperties, " ");
addProblemOnNameElement(propertiesProperty,
CloudFormationBundle.getString("format.required.resource.properties.are.not.set", requiredPropertiesString));
}
}

private void resourceType(JSProperty typeProperty) {
final String value = checkAndGetQuotedStringText(typeProperty.getValue());
final String value = checkAndGetUnquotedStringText(typeProperty.getValue());
if (value == null) {
return;
}

final String unquotedValue = StringUtil.stripQuotesAroundValue(value);

for (CloudFormationResourceType resourceType : CloudFormationMetadataProvider.METADATA.resourceTypes) {
if (unquotedValue.equals(resourceType.name)) {
return;
}
if (CloudFormationMetadataProvider.METADATA.findResourceType(value) == null) {
addProblem(typeProperty, CloudFormationBundle.getString("format.unknown.type", value));
}

addProblem(typeProperty, CloudFormationBundle.getString("format.unknown.type", value));
}

private JSObjectLiteralExpression checkAndGetObject(JSExpression expression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
},

"bbb": {
"Type": "AWS::IAM::AccessKey"
"Type": "AWS::IAM::AccessKey",
"Properties": {
"Status": "aaas",
"UserName": "bbbs"
}
}
}
}

0 comments on commit b543ccd

Please sign in to comment.