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 permissions to tagging schema #146

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
*/
package software.amazon.cloudformation.resource;

import java.util.HashSet;
import java.util.Set;

import lombok.AllArgsConstructor;
import lombok.Data;

Expand All @@ -30,20 +33,23 @@ public class ResourceTagging {
public static final String TAG_UPDATABLE = "tagUpdatable";
public static final String CLOUDFORMATION_SYSTEM_TAGS = "cloudFormationSystemTags";
public static final String TAG_PROPERTY = "tagProperty";
public static final String TAG_PERMISSIONS = "permissions";
public static final ResourceTagging DEFAULT = new ResourceTagging(true);

private boolean taggable;
private boolean tagOnCreate;
private boolean tagUpdatable;
private boolean cloudFormationSystemTags;
private JSONPointer tagProperty;
private Set<String> tagPermissions;

public ResourceTagging(final boolean taggableValue) {
this.taggable = taggableValue;
this.tagOnCreate = taggableValue;
this.tagUpdatable = taggableValue;
this.cloudFormationSystemTags = taggableValue;
this.tagProperty = new JSONPointer("/properties/Tags");
this.tagPermissions = new HashSet<>();
}

public void resetTaggable(final boolean taggableValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ public ResourceTypeSchema(Schema schema) {
taggingValue.setCloudFormationSystemTags(Boolean.parseBoolean(value.toString()));
} else if (key.equals(ResourceTagging.TAG_PROPERTY)) {
taggingValue.setTagProperty(new JSONPointer(value.toString()));
} else if (key.equals(ResourceTagging.TAG_PERMISSIONS)) {
HashSet<String> tagPermissions = new HashSet<>();
((List<?>) value).forEach(p -> tagPermissions.add(p.toString()));
taggingValue.setTagPermissions(tagPermissions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to make it HashSet? Why dont we use list, then you dont really need to convert it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I follow the type definition in Handler.java as Set<String> and I think the handler permissions is also set as an Hashset, but I am not sure whether it is a must for tagging permissions. I can change it to list.

} else {
throw new ValidationException("Unexpected tagging metadata attribute", "tagging", "#/tagging/" + key);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/schema/provider.definition.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@
"description": "A reference to the Tags property in the schema.",
"$ref": "http://json-schema.org/draft-07/schema#/properties/$ref",
"default": "/properties/Tags"
},
"permissions": {
"type": "array",
"items": {
"type": "string"
},
"additionalItems": false
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashSet;

import org.everit.json.schema.JSONPointer;
import org.junit.jupiter.api.Test;

Expand All @@ -24,13 +26,14 @@ public class ResourceTaggingTest {
public void testResetTaggable() {

final ResourceTagging resourceTagging = new ResourceTagging(true, true, true,
true, new JSONPointer("/properties/tags"));
true, new JSONPointer("/properties/tags"), new HashSet<>());
resourceTagging.resetTaggable(false);

assertThat(resourceTagging.isTaggable()).isEqualTo(false);
assertThat(resourceTagging.isTagOnCreate()).isEqualTo(false);
assertThat(resourceTagging.isTagUpdatable()).isEqualTo(false);
assertThat(resourceTagging.isCloudFormationSystemTags()).isEqualTo(false);
assertThat(resourceTagging.getTagProperty().toString()).isEqualTo("/properties/tags");
assertThat(resourceTagging.getTagPermissions().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ public void schemaWithTagging_withValidConfiguration() {
assertThat(schema.getTagging().isCloudFormationSystemTags()).isEqualTo(false);
assertThat(schema.definesProperty("propertyB")).isTrue();
assertThat(schema.getTagging().getTagProperty()).asString().isEqualTo("/properties/propertyB");
assertThat(schema.getTagging().getTagPermissions()).contains("test:permission");
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/test/resources/valid-with-tagging-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"tagOnCreate": true,
"tagUpdatable": false,
"cloudFormationSystemTags": false,
"tagProperty": "/properties/propertyB"
"tagProperty": "/properties/propertyB",
"permissions": [
"test:permission"
]
},
"additionalProperties": false
}