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

chore: Java CMC Example via Guava #822

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 58 additions & 0 deletions .github/workflows/library_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved."
# "SPDX-License-Identifier: CC-BY-SA-4.0"
# This workflow runs any examples.
name: Library Examples
on:
workflow_call:
inputs:
dafny:
description: "The Dafny version to run"
required: true
type: string

jobs:
java:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
defaults:
run:
shell: bash
steps:
- name: Support longpaths on Git checkout
run: |
git config --global core.longpaths true
- name: Configure AWS Credentials for Tests
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-MPL-Dafny-Role-us-west-2
role-session-name: JavaExampleTests

- uses: actions/checkout@v4
- run: git submodule update --init libraries
- run: git submodule update --init smithy-dafny

- name: Setup Dafny
uses: dafny-lang/[email protected]
with:
dafny-version: ${{ inputs.dafny }}

- name: Setup Java 8
uses: actions/setup-java@v3
with:
distribution: "corretto"
java-version: 8

- name: Build AwsCryptographicMaterialProviders Java implementation
working-directory: ./AwsCryptographicMaterialProviders
run: |
# This works because `node` is installed by default on GHA runners
CORES=$(node -e 'console.log(os.cpus().length)')
make build_java CORES=$CORES

- name: Test AwsCryptographicMaterialProviders Java Examples
working-directory: ./AwsCryptographicMaterialProviders
run: |
make test_example_java
6 changes: 6 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ jobs:
uses: ./.github/workflows/library_python_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
pr-ci-examples:
needs: getVersion
uses: ./.github/workflows/library_examples.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
pr-interop-test:
needs: getVersion
uses: ./.github/workflows/library_interop_tests.yml
Expand All @@ -55,6 +60,7 @@ jobs:
- pr-ci-java
- pr-ci-net
- pr-interop-test
- pr-ci-examples
runs-on: ubuntu-latest
steps:
- name: Verify all required jobs passed
Expand Down
5 changes: 4 additions & 1 deletion AwsCryptographicMaterialProviders/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ PYTHON_DEPENDENCY_MODULE_NAMES := \
--dependency-library-name=com.amazonaws.kms=aws_cryptography_internal_kms \
--dependency-library-name=com.amazonaws.dynamodb=aws_cryptography_internal_dynamodb \
--dependency-library-name=aws.cryptography.materialProviders=aws_cryptographic_material_providers \
--dependency-library-name=aws.cryptography.keyStore=aws_cryptographic_material_providers \
--dependency-library-name=aws.cryptography.keyStore=aws_cryptographic_material_providers \

test_example_java:
$(GRADLEW) -p runtimes/java testExamples
79 changes: 67 additions & 12 deletions AwsCryptographicMaterialProviders/runtimes/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,33 @@ var props = Properties().apply {
var dafnyVersion = props.getProperty("dafnyVersion")

group = "software.amazon.cryptography"
// version = props.getProperty("mplVersion")
version = "1.7.3-SNAPSHOT"
description = "AWS Cryptographic Material Providers Library"

sourceSets {
create("examples") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
create("testExamples") {
compileClasspath += sourceSets.test.get().output + sourceSets["examples"].output + sourceSets.main.get().output
runtimeClasspath += sourceSets.test.get().output + sourceSets["examples"].output + sourceSets.main.get().output
}
}
val examplesImplementation: Configuration by configurations.getting{
extendsFrom(configurations.testImplementation.get())
}
configurations.add(examplesImplementation)
val examplesAnnotationProcessor: Configuration by configurations.getting{
extendsFrom(configurations.testAnnotationProcessor.get())
}
configurations.add(examplesAnnotationProcessor)
val testExamplesImplementation: Configuration by configurations.getting{
extendsFrom(configurations["examplesImplementation"])
}
configurations.add(testExamplesImplementation)

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
sourceSets["main"].java {
Expand All @@ -29,6 +53,12 @@ java {
sourceSets["test"].java {
srcDir("src/test")
}
sourceSets["examples"].java {
srcDir("src/examples")
}
sourceSets["testExamples"].java {
srcDir("src/testExamples")
}
withJavadocJar()
withSourcesJar()
}
Expand Down Expand Up @@ -83,6 +113,15 @@ dependencies {

// https://mvnrepository.com/artifact/org.testng/testng
testImplementation("org.testng:testng:7.5")

// Example Dependencies
examplesImplementation("software.amazon.awssdk:arns")
examplesImplementation("software.amazon.awssdk:auth")
examplesImplementation("software.amazon.awssdk:sts")
examplesImplementation("software.amazon.awssdk:utils")
examplesImplementation("software.amazon.awssdk:apache-client")
examplesImplementation("com.google.code.findbugs:jsr305:3.0.2")
examplesImplementation("com.google.guava:guava:33.3.1-jre")
}

publishing {
Expand Down Expand Up @@ -224,18 +263,18 @@ tasks.test {
// This will show System.out.println statements
testLogging.showStandardStreams = true

testLogging {
lifecycle {
events = mutableSetOf(org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED, org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED, org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
showStandardStreams = true
}
info.events = lifecycle.events
info.exceptionFormat = lifecycle.exceptionFormat
}
// testLogging {
// lifecycle {
// events = mutableSetOf(org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED, org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED, org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED)
// exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
// showExceptions = true
// showCauses = true
// showStackTraces = true
// showStandardStreams = true
// }
// info.events = lifecycle.events
// info.exceptionFormat = lifecycle.exceptionFormat
// }

// See https://github.com/gradle/kotlin-dsl/issues/836
addTestListener(object : TestListener {
Expand All @@ -256,6 +295,22 @@ tasks.test {
})
}

val testExamples = task<Test>("testExamples") {
description = "Runs examples tests."
group = "verification"

testClassesDirs = sourceSets["testExamples"].output.classesDirs
classpath = sourceSets["testExamples"].runtimeClasspath + sourceSets["examples"].output + sourceSets.main.get().output
shouldRunAfter("compileJava", "compileExamplesJava", "test")
// This will show System.out.println statements
testLogging.showStandardStreams = true
useTestNG()

testLogging {
events("passed")
}
}

fun buildPom(mavenPublication: MavenPublication) {
mavenPublication.pom.withXml {
var dependencyManagementNode = asNode().appendNode("dependencyManagement").appendNode("dependencies").appendNode("dependency")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[//]: # "Copyright Amazon.com Inc. or its affiliates. All Rights Reserved."
[//]: # "SPDX-License-Identifier: CC-BY-SA-4.0"

## Examples (Java)

This project contains examples demonstrating how to use the
AWS Cryptographic Material Providers Library (MPL) in Java.

```
├── ..
└── CMC: Example for implemeting a custom Concurrent Cryptographic Materials Cache (CMC)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package software.amazon.cryptography.example;

import javax.annotation.Nullable;

import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.kms.KmsClient;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.apache.ApacheHttpClient;

public class ClientProvider {
private static final AwsCredentialsProvider defaultCreds =
DefaultCredentialsProvider.create();
private static final SdkHttpClient httpClient = ApacheHttpClient.create();

public static DynamoDbClient dynamoDB(
@Nullable DynamoDbClient dynamoDbClient
) {
if (dynamoDbClient == null) {
//noinspection resource
dynamoDbClient = DynamoDbClient.builder()
.httpClient(httpClient)
.credentialsProvider(defaultCreds)
.build();
}
return dynamoDbClient;
}

public static KmsClient kms(
@Nullable KmsClient kmsClient
) {
if (kmsClient == null) {
//noinspection resource
kmsClient = KmsClient.builder()
.httpClient(httpClient)
.credentialsProvider(defaultCreds)
.build();
}
return kmsClient;
}
}
Loading
Loading