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

Added support for IamPolicy in new module software.amazon.awssdk:iam-… #4185

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .brazil.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"codegen": { "packageName": "AwsJavaSdk-Codegen" },
"dynamodb-enhanced": { "packageName": "AwsJavaSdk-DynamoDb-Enhanced" },
"http-client-spi": { "packageName": "AwsJavaSdk-HttpClient" },
"iam-policy-builder": { "packageName": "AwsJavaSdk-Iam-PolicyBuilder" },
"json-utils": { "packageName": "AwsJavaSdk-Core-JsonUtils" },
"metrics-spi": { "packageName": "AwsJavaSdk-Core-MetricsSpi" },
"endpoints-spi": { "packageName": "AwsJavaSdk-Core-EndpointsSpi" },
Expand Down
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-a3a039b.json
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."
}
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 {
Copy link
Contributor Author

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).

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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() {
}
Expand All @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}

Expand All @@ -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.
*/
Expand Down
134 changes: 134 additions & 0 deletions services-custom/iam-policy-builder/pom.xml
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>
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);
}
}
Loading