Skip to content

[Bug bash] Include sso and ssooidc dependencies in maven archetype #3767

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

Merged
merged 11 commits into from
Mar 27, 2023
3 changes: 2 additions & 1 deletion archetypes/archetype-app-quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ mvn archetype:generate \
### Parameters

Parameter Name | Default Value | Description
---|---|---
---|-----|---
`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].
`groupId`(required) | n/a | Specifies the group ID of the project
`artifactId`(required) | n/a | Specifies the artifact ID of the project
`nativeImage`(required) | n/a | Specifies whether GraalVM Native Image configuration should be included
`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]
`ssoIdc` (required) | n/a | Specify if the sso and ssoidc dependency should be include in the project. Include them to enabled the use of [IAM Identity center](https://aws.amazon.com/iam/identity-center/) for credentials.
`javaSdkVersion` | Same version as the archetype version | Specifies the version of the AWS Java SDK 2.x to be used
`version` | 1.0-SNAPSHOT | Specifies the version of the project
`package` | ${groupId} | Specifies the package name for the classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@
<requiredProperty key="nativeImage">
<validationRegex>(true|false)</validationRegex>
</requiredProperty>
<requiredProperty key="ssoIdc">
<validationRegex>(true|false)</validationRegex>
</requiredProperty>
</requiredProperties>
</archetype-descriptor>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
</exclusions>
</dependency>

#if( $ssoIdc == 'true')
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sso</artifactId>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssooidc</artifactId>
</dependency>

#end
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>${httpClient}</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package=software.amazonaws.test
service=s3
httpClient=apache-client
javaSdkVersion=2.11.0
nativeImage=true
nativeImage=true
ssoIdc=false
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package=software.amazonaws.test
service=s3
httpClient=apache-client
javaSdkVersion=2.11.0
nativeImage=false
nativeImage=false
ssoIdc=false
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package=software.amazonaws.test
service=s3
httpClient=netty-nio-client
javaSdkVersion=2.11.0
nativeImage=true
nativeImage=true
ssoIdc=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
groupId=software.amazonaws.test
artifactId=test-apache-artifact
version=1.0-SNAPSHOT
package=software.amazonaws.test
service=s3
httpClient=apache-client
javaSdkVersion=2.11.0
nativeImage=true
ssoIdc=true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
verify
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# App

This project contains a maven application with [AWS Java SDK 2.x](https://github.com/aws/aws-sdk-java-v2) dependencies.
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 say that it's using SSO/SSOOIDC or are the other projects also generic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't specify which individual dependencies that are included for other property of the archetype, so I think we should leave it as-is


## Prerequisites
- Java 1.8+
- Apache Maven
- GraalVM Native Image (optional)

## Development

Below is the structure of the generated project.

```
├── src
│   ├── main
│   │   ├── java
│   │   │   └── package
│   │   │   ├── App.java
│   │   │   ├── DependencyFactory.java
│   │   │   └── Handler.java
│   │   └── resources
│   │   └── simplelogger.properties
│   └── test
│   └── java
│   └── package
│   └── HandlerTest.java
```

- `App.java`: main entry of the application
- `DependencyFactory.java`: creates the SDK client
- `Handler.java`: you can invoke the api calls using the SDK client here.

#### Building the project
```
mvn clean package
```

#### Building the native image

Note that it requires `native-image` installed in your environment

```
mvn clean package -P native-image
```
After it finishes, you can find the generated native image in the `target
` folder.

You can run the following command to execute it.

```
target/test-apache-artifact
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>

<groupId>software.amazonaws.test</groupId>
<artifactId>test-apache-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.shade.plugin.version>3.2.1</maven.shade.plugin.version>
<maven.compiler.plugin.version>3.6.1</maven.compiler.plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<aws.java.sdk.version>2.11.0</aws.java.sdk.version>
<slf4j.version>1.7.28</slf4j.version>
<graalvm.native.maven.plugin.version>0.9.6</graalvm.native.maven.plugin.version>
<junit5.version>5.8.1</junit5.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>${aws.java.sdk.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<exclusions>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
</exclusion>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sso</artifactId>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssooidc</artifactId>
</dependency>

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Needed to adapt Apache Commons Logging used by Apache HTTP Client to Slf4j to avoid
ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl during runtime -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native-image</id>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<version>${graalvm.native.maven.plugin.version}</version>
<executions>
<execution>
<id>build-native</id>
<goals>
<goal>build</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<imageName>test-apache-artifact</imageName>
<mainClass>software.amazonaws.test.App</mainClass>
<buildArgs combine.children="append">
<buildArgs>
--verbose
--no-fallback
--initialize-at-build-time=org.slf4j
</buildArgs>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package software.amazonaws.test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class App {
private static final Logger logger = LoggerFactory.getLogger(App.class);

public static void main(String... args) {
logger.info("Application starts");

Handler handler = new Handler();
handler.sendRequest();

logger.info("Application ends");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

package software.amazonaws.test;

import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.services.s3.S3Client;

/**
* The module containing all dependencies required by the {@link Handler}.
*/
public class DependencyFactory {

private DependencyFactory() {}

/**
* @return an instance of S3Client
*/
public static S3Client s3Client() {
return S3Client.builder()
.httpClientBuilder(ApacheHttpClient.builder())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package software.amazonaws.test;

import software.amazon.awssdk.services.s3.S3Client;


public class Handler {
private final S3Client s3Client;

public Handler() {
s3Client = DependencyFactory.s3Client();
}

public void sendRequest() {
// TODO: invoking the api calls using s3Client.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.

# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=info

# Log SDK requests
org.slf4j.simpleLogger.log.software.amazon.awssdk.request=debug
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z

# Set to true if you want to output the current thread name.
# Defaults to true.
org.slf4j.simpleLogger.showThreadName=true

# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true

# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
org.slf4j.simpleLogger.showShortLogName=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package software.amazonaws.test;

import org.junit.jupiter.api.Test;

public class HandlerTest {
//TODO add tests here
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package=software.amazonaws.test
service=dynamodb
httpClient=url-connection-client
javaSdkVersion=2.11.0
nativeImage=true
nativeImage=true
ssoIdc=false