Skip to content

Commit 9e142c2

Browse files
committed
Added support for IamPolicy in new module software.amazon.awssdk:iam-policy-builder, a class to simplify the use of AWS policies.
1 parent 87b36dd commit 9e142c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+5857
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Added support for IamPolicy in new module software.amazon.awssdk:iam-policy-builder, a class to simplify the use of AWS policies."
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.annotations;
17+
18+
import java.lang.annotation.Documented;
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* The annotated element must not be null. Accepts any type.
26+
* <p>
27+
* 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
28+
* public interfaces as something that customers should rely on.
29+
*/
30+
@Documented
31+
@Target({ElementType.METHOD,
32+
ElementType.FIELD,
33+
ElementType.ANNOTATION_TYPE,
34+
ElementType.CONSTRUCTOR,
35+
ElementType.PARAMETER})
36+
@Retention(RetentionPolicy.CLASS)
37+
@SdkProtectedApi
38+
public @interface NotNull {
39+
}

core/json-utils/src/main/java/software/amazon/awssdk/protocols/jsoncore/JsonWriter.java

+34-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.ByteArrayOutputStream;
2222
import java.io.IOException;
23+
import java.io.OutputStream;
2324
import java.math.BigDecimal;
2425
import java.math.BigInteger;
2526
import java.nio.ByteBuffer;
@@ -36,17 +37,17 @@
3637
*/
3738
@SdkProtectedApi
3839
public class JsonWriter implements SdkAutoCloseable {
39-
4040
private static final int DEFAULT_BUFFER_SIZE = 1024;
41-
private final JsonFactory jsonFactory;
4241
private final ByteArrayOutputStream baos;
4342
private final JsonGenerator generator;
4443

4544
private JsonWriter(Builder builder) {
46-
jsonFactory = builder.jsonFactory != null ? builder.jsonFactory : DEFAULT_JSON_FACTORY;
45+
JsonGeneratorFactory jsonGeneratorFactory = builder.jsonGeneratorFactory != null
46+
? builder.jsonGeneratorFactory
47+
: DEFAULT_JSON_FACTORY::createGenerator;
4748
try {
4849
baos = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
49-
generator = jsonFactory.createGenerator(baos);
50+
generator = jsonGeneratorFactory.createGenerator(baos);
5051
} catch (IOException e) {
5152
throw new JsonGenerationException(e);
5253
}
@@ -170,7 +171,7 @@ private JsonWriter unsafeWrite(FunctionalUtils.UnsafeRunnable r) {
170171
* A builder for configuring and creating {@link JsonWriter}. Created via {@link #builder()}.
171172
*/
172173
public static final class Builder {
173-
private JsonFactory jsonFactory;
174+
private JsonGeneratorFactory jsonGeneratorFactory;
174175

175176
private Builder() {
176177
}
@@ -179,13 +180,31 @@ private Builder() {
179180
* The {@link JsonFactory} implementation to be used when parsing the input. This allows JSON extensions like CBOR or
180181
* Ion to be supported.
181182
*
182-
* <p>It's highly recommended us use a shared {@code JsonFactory} where possible, so they should be stored statically:
183+
* <p>It's highly recommended to use a shared {@code JsonFactory} where possible, so they should be stored statically:
183184
* http://wiki.fasterxml.com/JacksonBestPracticesPerformance
184185
*
185186
* <p>By default, this is {@link JsonNodeParser#DEFAULT_JSON_FACTORY}.
187+
*
188+
* <p>Setting this value will also override any values set via {@link #jsonGeneratorFactory}.
186189
*/
187190
public JsonWriter.Builder jsonFactory(JsonFactory jsonFactory) {
188-
this.jsonFactory = jsonFactory;
191+
jsonGeneratorFactory(jsonFactory::createGenerator);
192+
return this;
193+
}
194+
195+
/**
196+
* A factory for {@link JsonGenerator}s based on an {@link OutputStream}. This allows custom JSON generator
197+
* configuration, like pretty-printing output.
198+
*
199+
* <p>It's highly recommended to use a shared {@code JsonFactory} within this generator factory, where possible, so they
200+
* should be stored statically: http://wiki.fasterxml.com/JacksonBestPracticesPerformance
201+
*
202+
* <p>By default, this delegates to {@link JsonNodeParser#DEFAULT_JSON_FACTORY} to create the generator.
203+
*
204+
* <p>Setting this value will also override any values set via {@link #jsonFactory}.
205+
*/
206+
public JsonWriter.Builder jsonGeneratorFactory(JsonGeneratorFactory jsonGeneratorFactory) {
207+
this.jsonGeneratorFactory = jsonGeneratorFactory;
189208
return this;
190209
}
191210

@@ -197,6 +216,14 @@ public JsonWriter build() {
197216
}
198217
}
199218

219+
/**
220+
* Generate a {@link JsonGenerator} for a {@link OutputStream}. This will get called once for each "write" call.
221+
*/
222+
@FunctionalInterface
223+
public interface JsonGeneratorFactory {
224+
JsonGenerator createGenerator(OutputStream outputStream) throws IOException;
225+
}
226+
200227
/**
201228
* Indicates an issue writing JSON content.
202229
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
18+
xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>aws-sdk-java-pom</artifactId>
24+
<version>2.20.104-SNAPSHOT</version>
25+
<relativePath>../../pom.xml</relativePath>
26+
</parent>
27+
<artifactId>iam-policy-builder</artifactId>
28+
<version>${awsjavasdk.version}</version>
29+
<name>AWS Java SDK :: IAM :: Policy Builder</name>
30+
<description>
31+
Library simplifying the building, marshalling and unmarshalling of IAM Policies.
32+
</description>
33+
<url>https://aws.amazon.com/sdkforjava</url>
34+
35+
<properties>
36+
<jre.version>1.8</jre.version>
37+
<awsjavasdk.version>${project.parent.version}</awsjavasdk.version>
38+
</properties>
39+
40+
<dependencyManagement>
41+
<dependencies>
42+
<dependency>
43+
<groupId>software.amazon.awssdk</groupId>
44+
<artifactId>bom-internal</artifactId>
45+
<version>${awsjavasdk.version}</version>
46+
<type>pom</type>
47+
<scope>import</scope>
48+
</dependency>
49+
</dependencies>
50+
</dependencyManagement>
51+
52+
<dependencies>
53+
<dependency>
54+
<groupId>software.amazon.awssdk</groupId>
55+
<artifactId>utils</artifactId>
56+
<version>${awsjavasdk.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>software.amazon.awssdk</groupId>
60+
<artifactId>annotations</artifactId>
61+
<version>${awsjavasdk.version}</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>software.amazon.awssdk</groupId>
65+
<artifactId>json-utils</artifactId>
66+
<version>${awsjavasdk.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>software.amazon.awssdk</groupId>
70+
<artifactId>third-party-jackson-core</artifactId>
71+
<version>${awsjavasdk.version}</version>
72+
</dependency>
73+
74+
75+
<dependency>
76+
<groupId>org.junit.jupiter</groupId>
77+
<artifactId>junit-jupiter</artifactId>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.junit.jupiter</groupId>
82+
<artifactId>junit-jupiter-engine</artifactId>
83+
<version>${junit5.version}</version>
84+
<scope>test</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.assertj</groupId>
88+
<artifactId>assertj-core</artifactId>
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>org.mockito</groupId>
93+
<artifactId>mockito-core</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.apache.logging.log4j</groupId>
98+
<artifactId>log4j-api</artifactId>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.apache.logging.log4j</groupId>
103+
<artifactId>log4j-core</artifactId>
104+
<scope>test</scope>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.apache.logging.log4j</groupId>
108+
<artifactId>log4j-slf4j-impl</artifactId>
109+
<scope>test</scope>
110+
</dependency>
111+
<dependency>
112+
<groupId>nl.jqno.equalsverifier</groupId>
113+
<artifactId>equalsverifier</artifactId>
114+
<scope>test</scope>
115+
</dependency>
116+
</dependencies>
117+
118+
<build>
119+
<plugins>
120+
<plugin>
121+
<groupId>org.apache.maven.plugins</groupId>
122+
<artifactId>maven-jar-plugin</artifactId>
123+
<configuration>
124+
<archive>
125+
<manifestEntries>
126+
<Automatic-Module-Name>software.amazon.awssdk.policybuilder.iam</Automatic-Module-Name>
127+
</manifestEntries>
128+
</archive>
129+
</configuration>
130+
</plugin>
131+
</plugins>
132+
</build>
133+
134+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.policybuilder.iam;
17+
18+
import software.amazon.awssdk.annotations.SdkPublicApi;
19+
import software.amazon.awssdk.annotations.ThreadSafe;
20+
import software.amazon.awssdk.policybuilder.iam.internal.DefaultIamAction;
21+
22+
/**
23+
* The {@code Action} element of a {@link IamStatement}, specifying which service actions the statement applies to.
24+
*
25+
* @see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_action.html">Action user guide</a>
26+
*/
27+
@SdkPublicApi
28+
@ThreadSafe
29+
public interface IamAction extends IamValue {
30+
/**
31+
* An {@link IamAction} representing ALL actions. When used on a statement, it means the policy should apply to
32+
* every action.
33+
*/
34+
IamAction ALL = create("*");
35+
36+
/**
37+
* Create a new {@code IamAction} element with the provided {@link #value()}.
38+
*/
39+
static IamAction create(String value) {
40+
return new DefaultIamAction(value);
41+
}
42+
}

0 commit comments

Comments
 (0)