Skip to content

Commit 4c1e3f6

Browse files
authored
[Bug bash] Include sso and ssooidc dependencies in maven archetype (#3767)
Include sso and ssoidc dependencies in maven archetype
1 parent 3e0fcd4 commit 4c1e3f6

File tree

16 files changed

+330
-17
lines changed

16 files changed

+330
-17
lines changed

archetypes/archetype-app-quickstart/README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ a dependency of [AWS Java SDK 2.x][aws-java-sdk-v2].
88

99
The generated application has the following features:
1010

11-
- Uses [Bill of Materials](BOM) to manage SDK dependencies
11+
- Uses [Bill of Materials][BOM] to manage SDK dependencies
1212
- Contains the code to create the SDK client
1313
- Out-of-box support of GraalVM Native Image when `nativeImage` is enabled
1414

@@ -37,25 +37,27 @@ mvn archetype:generate \
3737
-DhttpClient=apache-client \
3838
-DartifactId=sample-project \
3939
-Dservice=s3 \
40-
-DinteractiveMode=false
40+
-DinteractiveMode=false \
41+
-DcredentialProvider=default
4142
```
4243

4344
### Parameters
4445
45-
Parameter Name | Default Value | Description
46-
---|---|---
47-
`service` (required) | n/a | Specifies the service client to be used in the application, eg: s3, dynamodb. Only one service should be provided. You can find available services [here][java-sdk-v2-services].
48-
`groupId`(required) | n/a | Specifies the group ID of the project
49-
`artifactId`(required) | n/a | Specifies the artifact ID of the project
50-
`nativeImage`(required) | n/a | Specifies whether GraalVM Native Image configuration should be included
51-
`httpClient`(required) | n/a | Specifies the http client to be used by the SDK client. Available options are `url-connection-client` (sync), `apache-client` (sync), `netty-nio-client` (async). See [http clients][sdk-http-clients]
52-
`javaSdkVersion` | Same version as the archetype version | Specifies the version of the AWS Java SDK 2.x to be used
53-
`version` | 1.0-SNAPSHOT | Specifies the version of the project
54-
`package` | ${groupId} | Specifies the package name for the classes
55-
46+
| Parameter Name | Default Value | Description |
47+
|-------------------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
48+
| `service` (required) | n/a | Specifies the service client to be used in the application, eg: s3, dynamodb. Only one service should be provided. You can find available services [here][java-sdk-v2-services]. |
49+
| `groupId`(required) | n/a | Specifies the group ID of the project |
50+
| `artifactId`(required) | n/a | Specifies the artifact ID of the project |
51+
| `nativeImage`(required) | n/a | Specifies whether GraalVM Native Image configuration should be included |
52+
| `httpClient`(required) | n/a | Specifies the http client to be used by the SDK client. Available options are `url-connection-client` (sync), `apache-client` (sync), `netty-nio-client` (async). See [http clients][sdk-http-clients] |
53+
| `credentialProvider` | default | Specify the credential-provider to be used by the SDK client and imports relevant dependencies. Available options are `default` which uses the [default credential provider chain](https://docs.aws.amazon.com/sdkref/latest/guide/standardized-credentials.html), or `identity-center` whi uses [IAM Identity Center](https://docs.aws.amazon.com/sdkref/latest/guide/feature-sso-credentials.html) |
54+
| `javaSdkVersion` | Same version as the archetype version | Specifies the version of the AWS Java SDK 2.x to be used |
55+
| `version` | 1.0-SNAPSHOT | Specifies the version of the project |
56+
| `package` | ${groupId} | Specifies the package name for the classes |
5657

5758
[aws-java-sdk-v2]: https://github.com/aws/aws-sdk-java-v2
5859
[java-sdk-v2-services]: https://github.com/aws/aws-sdk-java-v2/tree/master/services
5960
[sdk-http-clients]: https://github.com/aws/aws-sdk-java-v2/tree/master/http-clients
6061
[maven-archetype-usage]: https://maven.apache.org/archetype/maven-archetype-plugin/usage.html
6162
[graalvm]: https://www.graalvm.org/docs/getting-started/#native-images
63+
[bom]: https://github.com/aws/aws-sdk-java-v2/blob/master/bom

archetypes/archetype-app-quickstart/src/main/resources/META-INF/maven/archetype-metadata.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@
4242
<requiredProperty key="nativeImage">
4343
<validationRegex>(true|false)</validationRegex>
4444
</requiredProperty>
45+
<requiredProperty key="credentialProvider">
46+
<validationRegex>(default|identity-center)</validationRegex>
47+
</requiredProperty>
4548
</requiredProperties>
4649
</archetype-descriptor>

archetypes/archetype-app-quickstart/src/main/resources/archetype-resources/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@
5050
</exclusions>
5151
</dependency>
5252

53+
#if( $credentialProvider == 'identity-center')
54+
<dependency>
55+
<groupId>software.amazon.awssdk</groupId>
56+
<artifactId>sso</artifactId>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>software.amazon.awssdk</groupId>
61+
<artifactId>ssooidc</artifactId>
62+
</dependency>
63+
64+
#end
5365
<dependency>
5466
<groupId>software.amazon.awssdk</groupId>
5567
<artifactId>${httpClient}</artifactId>

archetypes/archetype-app-quickstart/src/test/resources/projects/apachehttpclient/archetype.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ package=software.amazonaws.test
55
service=s3
66
httpClient=apache-client
77
javaSdkVersion=2.11.0
8-
nativeImage=true
8+
nativeImage=true
9+
credentialProvider=default

archetypes/archetype-app-quickstart/src/test/resources/projects/apachehttpclientwithoutnativeimage/archetype.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ package=software.amazonaws.test
55
service=s3
66
httpClient=apache-client
77
javaSdkVersion=2.11.0
8-
nativeImage=false
8+
nativeImage=false
9+
credentialProvider=default
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
groupId=software.amazonaws.test
2+
artifactId=test-apache-artifact
3+
version=1.0-SNAPSHOT
4+
package=software.amazonaws.test
5+
service=s3
6+
httpClient=apache-client
7+
javaSdkVersion=2.11.0
8+
nativeImage=true
9+
credentialProvider=identity-center
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
verify
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# App
2+
3+
This project contains a maven application with [AWS Java SDK 2.x](https://github.com/aws/aws-sdk-java-v2) dependencies.
4+
5+
## Prerequisites
6+
- Java 1.8+
7+
- Apache Maven
8+
- GraalVM Native Image (optional)
9+
10+
## Development
11+
12+
Below is the structure of the generated project.
13+
14+
```
15+
├── src
16+
│   ├── main
17+
│   │   ├── java
18+
│   │   │   └── package
19+
│   │   │   ├── App.java
20+
│   │   │   ├── DependencyFactory.java
21+
│   │   │   └── Handler.java
22+
│   │   └── resources
23+
│   │   └── simplelogger.properties
24+
│   └── test
25+
│   └── java
26+
│   └── package
27+
│   └── HandlerTest.java
28+
```
29+
30+
- `App.java`: main entry of the application
31+
- `DependencyFactory.java`: creates the SDK client
32+
- `Handler.java`: you can invoke the api calls using the SDK client here.
33+
34+
#### Building the project
35+
```
36+
mvn clean package
37+
```
38+
39+
#### Building the native image
40+
41+
Note that it requires `native-image` installed in your environment
42+
43+
```
44+
mvn clean package -P native-image
45+
```
46+
After it finishes, you can find the generated native image in the `target
47+
` folder.
48+
49+
You can run the following command to execute it.
50+
51+
```
52+
target/test-apache-artifact
53+
```
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>software.amazonaws.test</groupId>
6+
<artifactId>test-apache-artifact</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
<properties>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
<maven.compiler.source>1.8</maven.compiler.source>
12+
<maven.compiler.target>1.8</maven.compiler.target>
13+
<maven.shade.plugin.version>3.2.1</maven.shade.plugin.version>
14+
<maven.compiler.plugin.version>3.6.1</maven.compiler.plugin.version>
15+
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
16+
<aws.java.sdk.version>2.11.0</aws.java.sdk.version>
17+
<slf4j.version>1.7.28</slf4j.version>
18+
<graalvm.native.maven.plugin.version>0.9.6</graalvm.native.maven.plugin.version>
19+
<junit5.version>5.8.1</junit5.version>
20+
</properties>
21+
22+
<dependencyManagement>
23+
<dependencies>
24+
<dependency>
25+
<groupId>software.amazon.awssdk</groupId>
26+
<artifactId>bom</artifactId>
27+
<version>${aws.java.sdk.version}</version>
28+
<type>pom</type>
29+
<scope>import</scope>
30+
</dependency>
31+
</dependencies>
32+
</dependencyManagement>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>software.amazon.awssdk</groupId>
37+
<artifactId>s3</artifactId>
38+
<exclusions>
39+
<exclusion>
40+
<groupId>software.amazon.awssdk</groupId>
41+
<artifactId>netty-nio-client</artifactId>
42+
</exclusion>
43+
<exclusion>
44+
<groupId>software.amazon.awssdk</groupId>
45+
<artifactId>apache-client</artifactId>
46+
</exclusion>
47+
</exclusions>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>software.amazon.awssdk</groupId>
52+
<artifactId>sso</artifactId>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>software.amazon.awssdk</groupId>
57+
<artifactId>ssooidc</artifactId>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>software.amazon.awssdk</groupId>
62+
<artifactId>apache-client</artifactId>
63+
<exclusions>
64+
<exclusion>
65+
<groupId>commons-logging</groupId>
66+
<artifactId>commons-logging</artifactId>
67+
</exclusion>
68+
</exclusions>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>org.slf4j</groupId>
73+
<artifactId>slf4j-api</artifactId>
74+
<version>${slf4j.version}</version>
75+
</dependency>
76+
77+
<dependency>
78+
<groupId>org.slf4j</groupId>
79+
<artifactId>slf4j-simple</artifactId>
80+
<version>${slf4j.version}</version>
81+
</dependency>
82+
83+
<!-- Needed to adapt Apache Commons Logging used by Apache HTTP Client to Slf4j to avoid
84+
ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl during runtime -->
85+
<dependency>
86+
<groupId>org.slf4j</groupId>
87+
<artifactId>jcl-over-slf4j</artifactId>
88+
<version>${slf4j.version}</version>
89+
</dependency>
90+
91+
<!-- Test Dependencies -->
92+
<dependency>
93+
<groupId>org.junit.jupiter</groupId>
94+
<artifactId>junit-jupiter</artifactId>
95+
<version>${junit5.version}</version>
96+
<scope>test</scope>
97+
</dependency>
98+
</dependencies>
99+
100+
<build>
101+
<plugins>
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-compiler-plugin</artifactId>
105+
<version>${maven.compiler.plugin.version}</version>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
110+
<profiles>
111+
<profile>
112+
<id>native-image</id>
113+
<build>
114+
<plugins>
115+
<plugin>
116+
<groupId>org.graalvm.buildtools</groupId>
117+
<artifactId>native-maven-plugin</artifactId>
118+
<version>${graalvm.native.maven.plugin.version}</version>
119+
<executions>
120+
<execution>
121+
<id>build-native</id>
122+
<goals>
123+
<goal>build</goal>
124+
</goals>
125+
<phase>package</phase>
126+
</execution>
127+
</executions>
128+
<configuration>
129+
<imageName>test-apache-artifact</imageName>
130+
<mainClass>software.amazonaws.test.App</mainClass>
131+
<buildArgs combine.children="append">
132+
<buildArgs>
133+
--verbose
134+
--no-fallback
135+
--initialize-at-build-time=org.slf4j
136+
</buildArgs>
137+
</buildArgs>
138+
</configuration>
139+
</plugin>
140+
</plugins>
141+
</build>
142+
</profile>
143+
</profiles>
144+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package software.amazonaws.test;
2+
import org.slf4j.Logger;
3+
import org.slf4j.LoggerFactory;
4+
5+
public class App {
6+
private static final Logger logger = LoggerFactory.getLogger(App.class);
7+
8+
public static void main(String... args) {
9+
logger.info("Application starts");
10+
11+
Handler handler = new Handler();
12+
handler.sendRequest();
13+
14+
logger.info("Application ends");
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
package software.amazonaws.test;
3+
4+
import software.amazon.awssdk.http.apache.ApacheHttpClient;
5+
import software.amazon.awssdk.services.s3.S3Client;
6+
7+
/**
8+
* The module containing all dependencies required by the {@link Handler}.
9+
*/
10+
public class DependencyFactory {
11+
12+
private DependencyFactory() {}
13+
14+
/**
15+
* @return an instance of S3Client
16+
*/
17+
public static S3Client s3Client() {
18+
return S3Client.builder()
19+
.httpClientBuilder(ApacheHttpClient.builder())
20+
.build();
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package software.amazonaws.test;
2+
3+
import software.amazon.awssdk.services.s3.S3Client;
4+
5+
6+
public class Handler {
7+
private final S3Client s3Client;
8+
9+
public Handler() {
10+
s3Client = DependencyFactory.s3Client();
11+
}
12+
13+
public void sendRequest() {
14+
// TODO: invoking the api calls using s3Client.
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SLF4J's SimpleLogger configuration file
2+
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
3+
4+
# Default logging detail level for all instances of SimpleLogger.
5+
# Must be one of ("trace", "debug", "info", "warn", or "error").
6+
# If not specified, defaults to "info".
7+
org.slf4j.simpleLogger.defaultLogLevel=info
8+
9+
# Log SDK requests
10+
org.slf4j.simpleLogger.log.software.amazon.awssdk.request=debug
11+
org.slf4j.simpleLogger.showDateTime=true
12+
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
13+
14+
# Set to true if you want to output the current thread name.
15+
# Defaults to true.
16+
org.slf4j.simpleLogger.showThreadName=true
17+
18+
# Set to true if you want the Logger instance name to be included in output messages.
19+
# Defaults to true.
20+
#org.slf4j.simpleLogger.showLogName=true
21+
22+
# Set to true if you want the last component of the name to be included in output messages.
23+
# Defaults to false.
24+
org.slf4j.simpleLogger.showShortLogName=false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package software.amazonaws.test;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
public class HandlerTest {
6+
//TODO add tests here
7+
}

0 commit comments

Comments
 (0)