Skip to content

smithy-call #620

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 77 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
28aeba7
Everything except for PicoCLI works
franco2002lu Feb 27, 2025
68f06d4
Working Gradle
franco2002lu Mar 18, 2025
a34fe97
Refactor CLI package
franco2002lu Mar 18, 2025
58ac69e
Initial input revamp
franco2002lu Mar 18, 2025
b7aac13
Support json file path as an input type
franco2002lu Mar 19, 2025
0371c98
add resource-config.json
franco2002lu Mar 19, 2025
be74a26
First attempt in addressing Protocol Trait Issue
franco2002lu Mar 20, 2025
43c1915
Support RestJson and RestXml protocols
franco2002lu Mar 20, 2025
eba7049
First working version of CLI (requires retrieving local resource files.
franco2002lu Mar 21, 2025
1b66de0
First working version of CLI (requires retrieving local resource files.
franco2002lu Mar 21, 2025
d9f31cb
Add endpoint url requirement for executing operations
franco2002lu Mar 21, 2025
c4107a0
Make protocol specification optional
franco2002lu Mar 21, 2025
bd3edfb
Improve getResourceFiles() and executeClientCall
franco2002lu Mar 24, 2025
b743017
Replace io.* import
franco2002lu Mar 24, 2025
8228a80
Improve model file retrieval
franco2002lu Mar 24, 2025
9e7262a
Have SigV4DSigner accommodate for custom ports
franco2002lu Mar 26, 2025
3b68e3c
First working SigV4 call
franco2002lu Mar 26, 2025
9d3ede0
Initial working CLI version with SigV4
franco2002lu Mar 26, 2025
51ab99d
Enhance auth input handling, make CLI flags more descriptive.
franco2002lu Mar 26, 2025
ba3ba69
clean-up build.gradle.kts
franco2002lu Mar 26, 2025
918231d
Remove unused reflect-config.json
franco2002lu Mar 26, 2025
787d9aa
Update error messages.
franco2002lu Mar 26, 2025
10160df
Merge branch 'main' into dynamic-client-cli
franco2002lu Mar 27, 2025
3053b90
Remove explicit transport configuration.
franco2002lu Mar 27, 2025
2b29df3
Rename CLI to smithy-call
franco2002lu Mar 27, 2025
2dbb7c3
Remove unnecessary include
franco2002lu Mar 27, 2025
dea93a1
Rename resource file list
franco2002lu Mar 27, 2025
6f581ef
Remove Smithy plugin
franco2002lu Mar 27, 2025
0940f73
Add README example
franco2002lu Mar 27, 2025
228c437
Merge branch 'main' into dynamic-client-cli
franco2002lu Mar 27, 2025
20b64ba
Merge branch 'main' into dynamic-client-cli
franco2002lu Mar 31, 2025
75961a9
Rename URI port check to uriUsingStandardPort.
franco2002lu Mar 28, 2025
51346b7
Update command descriptions
franco2002lu Mar 28, 2025
c63bf5f
Make SmithyCall and SmithyCallRunner final classes.
franco2002lu Mar 28, 2025
e834fd5
Move protocol types into an Enum.
franco2002lu Mar 28, 2025
3ced7ca
Remove redundant error handling
franco2002lu Mar 28, 2025
bc24cf8
Output machine-readable JSON from operation calls.
franco2002lu Mar 28, 2025
d02b0d7
Make --list-operations output more readable.
franco2002lu Mar 28, 2025
312c588
Correct document serialization to JSON.
franco2002lu Mar 28, 2025
1cdbb6e
Support multiple --model-path args.
franco2002lu Mar 31, 2025
83fb491
Group together auth-related options.
franco2002lu Mar 31, 2025
3dc2ab3
Implement SEVERE level logs
franco2002lu Mar 31, 2025
9282d99
Implement FINE level logs
franco2002lu Mar 31, 2025
b91dbaa
Improve cross-checking for service name in model.
franco2002lu Apr 1, 2025
7a206c9
Add basic tests.
franco2002lu Apr 1, 2025
a26e00c
Rename json payload input.
franco2002lu Apr 1, 2025
296d588
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 2, 2025
9514804
Rename aws-sigv4 implementation.
franco2002lu Apr 2, 2025
4dede25
Include ByteArrayOutputStream in try block
franco2002lu Apr 2, 2025
13d68d7
Revert "Include ByteArrayOutputStream in try block"
franco2002lu Apr 2, 2025
35c8122
Simplify exception handling in tests.
franco2002lu Apr 2, 2025
29e6d76
Simplify exception handling in tests.
franco2002lu Apr 2, 2025
0efd6ef
Add smithy aws traits as dependency
franco2002lu Apr 4, 2025
7f70a9c
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 4, 2025
8f52ce9
Update RPCV2 package naming
franco2002lu Apr 4, 2025
299c3ec
Add waiters dependency.
franco2002lu Apr 4, 2025
cb5a43b
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 7, 2025
40b81f5
Remove unused dep
adwsingh Apr 7, 2025
d6faba1
Improve ProtocolType enum handling.
franco2002lu Apr 8, 2025
fe50ee7
Add consistent dependency handling.
franco2002lu Apr 8, 2025
18c1a6b
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 8, 2025
7bac837
Improve command descriptions.
franco2002lu Apr 8, 2025
f838e1f
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 8, 2025
80845ce
Improve service name description.
franco2002lu Apr 9, 2025
62cbb25
Remove unused interceptor configuration.
franco2002lu Apr 9, 2025
6a10def
Simply auth type switch statement.
franco2002lu Apr 9, 2025
cc30c8c
Make out reading more efficient.
franco2002lu Apr 9, 2025
13826de
Remove stacktrace from input validation errors.
franco2002lu Apr 9, 2025
d168d80
Change SmithyCall class to package-private.
franco2002lu Apr 9, 2025
0bf5652
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 9, 2025
8cddc56
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 10, 2025
1997a2f
Improve arg descriptions and names.
franco2002lu Apr 10, 2025
5aa91be
Support relative shape IDs.
franco2002lu Apr 10, 2025
14253a6
Exclude non-service shape IDs while listing.
franco2002lu Apr 10, 2025
e42561b
Add tests for relative shape ID support.
franco2002lu Apr 10, 2025
be7c93f
Update cli/src/main/java/software/amazon/smithy/java/cli/SmithyCall.java
franco2002lu Apr 11, 2025
d4233ac
Merge branch 'main' into dynamic-client-cli
franco2002lu Apr 11, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private Map<String, List<String>> createSignedHeaders(
var headers = copyHeaders(httpHeaders);

// AWS4 requires a number of headers to be set before signing including 'Host' and 'X-Amz-Date'
var hostHeader = uriUsingNonStandardPort(uri) ? uri.getHost() + ':' + uri.getPort() : uri.getHost();
var hostHeader = uriUsingStandardPort(uri) ? uri.getHost() + ':' + uri.getPort() : uri.getHost();
headers.put("host", List.of(hostHeader));

var sb = signingResources.sb;
Expand Down Expand Up @@ -249,12 +249,11 @@ private static void appendTwoDigits(int value, StringBuilder sb) {
sb.append(value);
}

private static boolean uriUsingNonStandardPort(URI uri) {
private static boolean uriUsingStandardPort(URI uri) {
return switch (uri.getPort()) {
case -1 -> false;
case 80 -> uri.getScheme().equals("http");
case 443 -> uri.getScheme().equals("https");
default -> throw new IllegalStateException("Unexpected value for URI scheme: " + uri.getScheme());
default -> false;
};
}

Expand Down
17 changes: 17 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## smithy-call

This module contains the base-version of smithy-call: a CLI that uses ahead-of-time compilation and the dynamic client to make adhoc calls to services.


The functionality provided by this CLI includes:
1. Execute operations listed in a service model
2. List operations listed in a service model
3. SigV4 authentication
4. Multi-protocol support

### Example Call
1. Build the native binary for smithy-call: `./gradlew :cli:nativeCompile`
2. Start-up Cafe service from the end-to-end example: `./gradlew :examples:end-to-end:run`
3. Check the available operations: `./cli/build/native/nativeCompile/smithy-call com.example#CoffeeShop --list-operations -m /Users/fluu/workplace/smithy-java-cli/examples/end-to-end/model`
4. Send a test call to our Cafe service: `./cli/build/native/nativeCompile/smithy-call com.example#CoffeeShop GetMenu -m /Users/fluu/workplace/smithy-java-cli/examples/end-to-end/model --url http://localhost:8888`

102 changes: 102 additions & 0 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
plugins {
`java-library`
application
alias(libs.plugins.graalvm.native)
}

dependencies {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than ship the AWS protocol definitions and auth schemas and other Smithy models in these packages, can you instead add a dependency on them via Maven coordinates?

Copy link
Member

Choose a reason for hiding this comment

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

You need a waiters dependency too if this would ever work with AWS models.

You maybe want to add an --aut flag to the CLI to ignore unknown traits at some point. That can wait til later, but the CLI will fail right now if a trait isn't defined.

implementation(libs.picocli)
annotationProcessor(libs.picocli.codegen)

implementation(libs.smithy.aws.traits)
implementation(libs.smithy.waiters)

// Client dependencies
implementation(project(":aws:client:aws-client-restjson"))
implementation(project(":aws:client:aws-client-awsjson"))
implementation(project(":aws:client:aws-client-restxml"))
implementation(project(":client:client-rpcv2-cbor"))

implementation(project(":client:dynamic-client"))
implementation(project(":codecs:json-codec"))
implementation(project(":client:client-http"))
implementation(project(":aws:client:aws-client-core"))
implementation(project(":aws:aws-sigv4"))

testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.engine)
testImplementation(libs.junit.jupiter.params)
}

tasks.register<Copy>("copySmithyAwsTraits") {
from(zipTree(configurations.runtimeClasspath.get().filter { it.name.startsWith("smithy-aws-traits-") }.single())) {
include("**/*.smithy")
eachFile {
relativePath = RelativePath(true, name)
}
}
into(layout.buildDirectory.dir("smithy-aws-traits"))

includeEmptyDirs = false
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks.named("processResources") {
dependsOn("copySmithyAwsTraits")
}

sourceSets {
main {
resources {
srcDir(layout.buildDirectory.dir("smithy-aws-traits"))
}
}
}

tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}

application {
mainClass = "software.amazon.smithy.java.cli.SmithyCallRunner"
}

graalvmNative {
binaries.named("main") {
// Set up correct java JVM to use.
javaLauncher.set(
javaToolchains.launcherFor {
// Use oracle GraalVM JDK for build
languageVersion.set(JavaLanguageVersion.of(23))
vendor.set(JvmVendorSpec.matching("Oracle Corporation"))
},
)

// Ensure resources are detected
resources.autodetect()

buildArgs.addAll(listOf(
"-H:ResourceConfigurationFiles=${projectDir}/src/resource-config.json",
"--enable-url-protocols=http,https",
))

// Debug info
verbose.set(true)

// Image configuration
imageName.set("smithy-call")
mainClass.set(application.mainClass)

// Determines if image is a shared library [note: defaults to true if java-library plugin is applied]
sharedLibrary.set(false)
}
}

repositories {
mavenLocal()
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package software.amazon.smithy.java.cli;

public enum ProtocolType {
AWS_JSON,
RPC_V2_CBOR,
REST_JSON,
REST_XML
}
Loading