-
Notifications
You must be signed in to change notification settings - Fork 890
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
Added support for IamPolicy in new module software.amazon.awssdk:iam-… #4185
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,6 @@ | ||
{ | ||
"type": "feature", | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"description": "Added support for IamPolicy in new module software.amazon.awssdk:iam-policy-builder, a class to simplify the use of AWS policies." | ||
} |
39 changes: 39 additions & 0 deletions
39
core/annotations/src/main/java/software/amazon/awssdk/annotations/NotNull.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,39 @@ | ||
/* | ||
* Copyright 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.awssdk.annotations; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* The annotated element must not be null. Accepts any type. | ||
* <p> | ||
* This is useful to tell linting and testing tools that a particular value will never be null. It's not meant to be used on | ||
* public interfaces as something that customers should rely on. | ||
*/ | ||
@Documented | ||
@Target({ElementType.METHOD, | ||
ElementType.FIELD, | ||
ElementType.ANNOTATION_TYPE, | ||
ElementType.CONSTRUCTOR, | ||
ElementType.PARAMETER}) | ||
@Retention(RetentionPolicy.CLASS) | ||
@SdkProtectedApi | ||
public @interface NotNull { | ||
} |
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.nio.ByteBuffer; | ||
|
@@ -36,17 +37,17 @@ | |
*/ | ||
@SdkProtectedApi | ||
public class JsonWriter implements SdkAutoCloseable { | ||
|
||
private static final int DEFAULT_BUFFER_SIZE = 1024; | ||
private final JsonFactory jsonFactory; | ||
private final ByteArrayOutputStream baos; | ||
private final JsonGenerator generator; | ||
|
||
private JsonWriter(Builder builder) { | ||
jsonFactory = builder.jsonFactory != null ? builder.jsonFactory : DEFAULT_JSON_FACTORY; | ||
JsonGeneratorFactory jsonGeneratorFactory = builder.jsonGeneratorFactory != null | ||
? builder.jsonGeneratorFactory | ||
: DEFAULT_JSON_FACTORY::createGenerator; | ||
try { | ||
baos = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE); | ||
generator = jsonFactory.createGenerator(baos); | ||
generator = jsonGeneratorFactory.createGenerator(baos); | ||
} catch (IOException e) { | ||
throw new JsonGenerationException(e); | ||
} | ||
|
@@ -170,7 +171,7 @@ private JsonWriter unsafeWrite(FunctionalUtils.UnsafeRunnable r) { | |
* A builder for configuring and creating {@link JsonWriter}. Created via {@link #builder()}. | ||
*/ | ||
public static final class Builder { | ||
private JsonFactory jsonFactory; | ||
private JsonGeneratorFactory jsonGeneratorFactory; | ||
|
||
private Builder() { | ||
} | ||
|
@@ -179,13 +180,31 @@ private Builder() { | |
* The {@link JsonFactory} implementation to be used when parsing the input. This allows JSON extensions like CBOR or | ||
* Ion to be supported. | ||
* | ||
* <p>It's highly recommended us use a shared {@code JsonFactory} where possible, so they should be stored statically: | ||
* <p>It's highly recommended to use a shared {@code JsonFactory} where possible, so they should be stored statically: | ||
* http://wiki.fasterxml.com/JacksonBestPracticesPerformance | ||
* | ||
* <p>By default, this is {@link JsonNodeParser#DEFAULT_JSON_FACTORY}. | ||
* | ||
* <p>Setting this value will also override any values set via {@link #jsonGeneratorFactory}. | ||
*/ | ||
public JsonWriter.Builder jsonFactory(JsonFactory jsonFactory) { | ||
this.jsonFactory = jsonFactory; | ||
jsonGeneratorFactory(jsonFactory::createGenerator); | ||
return this; | ||
} | ||
|
||
/** | ||
* A factory for {@link JsonGenerator}s based on an {@link OutputStream}. This allows custom JSON generator | ||
* configuration, like pretty-printing output. | ||
* | ||
* <p>It's highly recommended to use a shared {@code JsonFactory} within this generator factory, where possible, so they | ||
* should be stored statically: http://wiki.fasterxml.com/JacksonBestPracticesPerformance | ||
* | ||
* <p>By default, this delegates to {@link JsonNodeParser#DEFAULT_JSON_FACTORY} to create the generator. | ||
* | ||
* <p>Setting this value will also override any values set via {@link #jsonFactory}. | ||
*/ | ||
public JsonWriter.Builder jsonGeneratorFactory(JsonGeneratorFactory jsonGeneratorFactory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this to allow me to configure the underlying JSON generator to pretty-print the JSON. |
||
this.jsonGeneratorFactory = jsonGeneratorFactory; | ||
return this; | ||
} | ||
|
||
|
@@ -197,6 +216,14 @@ public JsonWriter build() { | |
} | ||
} | ||
|
||
/** | ||
* Generate a {@link JsonGenerator} for a {@link OutputStream}. This will get called once for each "write" call. | ||
*/ | ||
@FunctionalInterface | ||
public interface JsonGeneratorFactory { | ||
JsonGenerator createGenerator(OutputStream outputStream) throws IOException; | ||
} | ||
|
||
/** | ||
* Indicates an issue writing JSON content. | ||
*/ | ||
|
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,134 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ Copyright 2010-2019 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. | ||
--> | ||
|
||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>aws-sdk-java-pom</artifactId> | ||
<version>2.20.104-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>iam-policy-builder</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
<name>AWS Java SDK :: IAM :: Policy Builder</name> | ||
<description> | ||
Library simplifying the building, marshalling and unmarshalling of IAM Policies. | ||
</description> | ||
<url>https://aws.amazon.com/sdkforjava</url> | ||
|
||
<properties> | ||
<jre.version>1.8</jre.version> | ||
<awsjavasdk.version>${project.parent.version}</awsjavasdk.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>bom-internal</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>json-utils</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>software.amazon.awssdk</groupId> | ||
<artifactId>third-party-jackson-core</artifactId> | ||
<version>${awsjavasdk.version}</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>${junit5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>nl.jqno.equalsverifier</groupId> | ||
<artifactId>equalsverifier</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>software.amazon.awssdk.policybuilder.iam</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
42 changes: 42 additions & 0 deletions
42
.../iam-policy-builder/src/main/java/software/amazon/awssdk/policybuilder/iam/IamAction.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,42 @@ | ||
/* | ||
* Copyright 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.awssdk.policybuilder.iam; | ||
|
||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.annotations.ThreadSafe; | ||
import software.amazon.awssdk.policybuilder.iam.internal.DefaultIamAction; | ||
|
||
/** | ||
* The {@code Action} element of a {@link IamStatement}, specifying which service actions the statement applies to. | ||
* | ||
* @see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html">Action user guide</a> | ||
*/ | ||
@SdkPublicApi | ||
@ThreadSafe | ||
public interface IamAction extends IamValue { | ||
/** | ||
* An {@link IamAction} representing ALL actions. When used on a statement, it means the policy should apply to | ||
* every action. | ||
*/ | ||
IamAction ALL = create("*"); | ||
|
||
/** | ||
* Create a new {@code IamAction} element with the provided {@link #value()}. | ||
*/ | ||
static IamAction create(String value) { | ||
return new DefaultIamAction(value); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this because EqualsVerifier will use it to detect which fields are considered not-null. It allows me to test all of the equals/hashcode methods in the package at once from a single test (EqualsHashCodeTest).