Skip to content

Commit afe441c

Browse files
franco2002luadwsinghmtdowling
authored
smithy-call (#620)
* Everything except for PicoCLI works * Working Gradle * Refactor CLI package * Initial input revamp * Support json file path as an input type * add resource-config.json * First attempt in addressing Protocol Trait Issue * Support RestJson and RestXml protocols * First working version of CLI (requires retrieving local resource files. * First working version of CLI (requires retrieving local resource files. * Add endpoint url requirement for executing operations * Make protocol specification optional * Improve getResourceFiles() and executeClientCall * Replace io.* import * Improve model file retrieval * Have SigV4DSigner accommodate for custom ports * First working SigV4 call * Initial working CLI version with SigV4 * Enhance auth input handling, make CLI flags more descriptive. * clean-up build.gradle.kts * Remove unused reflect-config.json * Update error messages. * Remove explicit transport configuration. * Rename CLI to smithy-call * Remove unnecessary include * Rename resource file list * Remove Smithy plugin * Add README example * Rename URI port check to uriUsingStandardPort. * Update command descriptions * Make SmithyCall and SmithyCallRunner final classes. * Move protocol types into an Enum. * Remove redundant error handling * Output machine-readable JSON from operation calls. * Make --list-operations output more readable. * Correct document serialization to JSON. * Support multiple --model-path args. * Group together auth-related options. * Implement SEVERE level logs * Implement FINE level logs * Improve cross-checking for service name in model. * Add basic tests. * Rename json payload input. * Rename aws-sigv4 implementation. * Include ByteArrayOutputStream in try block * Revert "Include ByteArrayOutputStream in try block" This reverts commit 4dede25. * Simplify exception handling in tests. * Simplify exception handling in tests. * Add smithy aws traits as dependency * Update RPCV2 package naming * Add waiters dependency. * Remove unused dep * Improve ProtocolType enum handling. * Add consistent dependency handling. * Improve command descriptions. * Improve service name description. * Remove unused interceptor configuration. * Simply auth type switch statement. * Make out reading more efficient. * Remove stacktrace from input validation errors. * Change SmithyCall class to package-private. * Improve arg descriptions and names. * Support relative shape IDs. * Exclude non-service shape IDs while listing. * Add tests for relative shape ID support. * Update cli/src/main/java/software/amazon/smithy/java/cli/SmithyCall.java Improve --model-path description Co-authored-by: Michael Dowling <[email protected]> --------- Co-authored-by: Adwait Kumar Singh <[email protected]> Co-authored-by: Michael Dowling <[email protected]>
1 parent 67a5cd1 commit afe441c

File tree

11 files changed

+860
-4
lines changed

11 files changed

+860
-4
lines changed

aws/aws-sigv4/src/main/java/software/amazon/smithy/java/aws/client/auth/scheme/sigv4/SigV4Signer.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private Map<String, List<String>> createSignedHeaders(
159159
var headers = copyHeaders(httpHeaders);
160160

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

165165
var sb = signingResources.sb;
@@ -249,12 +249,11 @@ private static void appendTwoDigits(int value, StringBuilder sb) {
249249
sb.append(value);
250250
}
251251

252-
private static boolean uriUsingNonStandardPort(URI uri) {
252+
private static boolean uriUsingStandardPort(URI uri) {
253253
return switch (uri.getPort()) {
254-
case -1 -> false;
255254
case 80 -> uri.getScheme().equals("http");
256255
case 443 -> uri.getScheme().equals("https");
257-
default -> throw new IllegalStateException("Unexpected value for URI scheme: " + uri.getScheme());
256+
default -> false;
258257
};
259258
}
260259

cli/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## smithy-call
2+
3+
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.
4+
5+
6+
The functionality provided by this CLI includes:
7+
1. Execute operations listed in a service model
8+
2. List operations listed in a service model
9+
3. SigV4 authentication
10+
4. Multi-protocol support
11+
12+
### Example Call
13+
1. Build the native binary for smithy-call: `./gradlew :cli:nativeCompile`
14+
2. Start-up Cafe service from the end-to-end example: `./gradlew :examples:end-to-end:run`
15+
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`
16+
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`
17+

cli/build.gradle.kts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
plugins {
2+
`java-library`
3+
application
4+
alias(libs.plugins.graalvm.native)
5+
}
6+
7+
dependencies {
8+
implementation(libs.picocli)
9+
annotationProcessor(libs.picocli.codegen)
10+
11+
implementation(libs.smithy.aws.traits)
12+
implementation(libs.smithy.waiters)
13+
14+
// Client dependencies
15+
implementation(project(":aws:client:aws-client-restjson"))
16+
implementation(project(":aws:client:aws-client-awsjson"))
17+
implementation(project(":aws:client:aws-client-restxml"))
18+
implementation(project(":client:client-rpcv2-cbor"))
19+
20+
implementation(project(":client:dynamic-client"))
21+
implementation(project(":codecs:json-codec"))
22+
implementation(project(":client:client-http"))
23+
implementation(project(":aws:client:aws-client-core"))
24+
implementation(project(":aws:aws-sigv4"))
25+
26+
testImplementation(platform(libs.junit.bom))
27+
testImplementation(libs.junit.jupiter.api)
28+
testImplementation(libs.junit.jupiter.engine)
29+
testImplementation(libs.junit.jupiter.params)
30+
}
31+
32+
tasks.register<Copy>("copySmithyAwsTraits") {
33+
from(zipTree(configurations.runtimeClasspath.get().filter { it.name.startsWith("smithy-aws-traits-") }.single())) {
34+
include("**/*.smithy")
35+
eachFile {
36+
relativePath = RelativePath(true, name)
37+
}
38+
}
39+
into(layout.buildDirectory.dir("smithy-aws-traits"))
40+
41+
includeEmptyDirs = false
42+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
43+
}
44+
45+
tasks.named("processResources") {
46+
dependsOn("copySmithyAwsTraits")
47+
}
48+
49+
sourceSets {
50+
main {
51+
resources {
52+
srcDir(layout.buildDirectory.dir("smithy-aws-traits"))
53+
}
54+
}
55+
}
56+
57+
tasks.test {
58+
useJUnitPlatform()
59+
testLogging {
60+
events("passed", "skipped", "failed")
61+
}
62+
}
63+
64+
application {
65+
mainClass = "software.amazon.smithy.java.cli.SmithyCallRunner"
66+
}
67+
68+
graalvmNative {
69+
binaries.named("main") {
70+
// Set up correct java JVM to use.
71+
javaLauncher.set(
72+
javaToolchains.launcherFor {
73+
// Use oracle GraalVM JDK for build
74+
languageVersion.set(JavaLanguageVersion.of(23))
75+
vendor.set(JvmVendorSpec.matching("Oracle Corporation"))
76+
},
77+
)
78+
79+
// Ensure resources are detected
80+
resources.autodetect()
81+
82+
buildArgs.addAll(listOf(
83+
"-H:ResourceConfigurationFiles=${projectDir}/src/resource-config.json",
84+
"--enable-url-protocols=http,https",
85+
))
86+
87+
// Debug info
88+
verbose.set(true)
89+
90+
// Image configuration
91+
imageName.set("smithy-call")
92+
mainClass.set(application.mainClass)
93+
94+
// Determines if image is a shared library [note: defaults to true if java-library plugin is applied]
95+
sharedLibrary.set(false)
96+
}
97+
}
98+
99+
repositories {
100+
mavenLocal()
101+
mavenCentral()
102+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package software.amazon.smithy.java.cli;
2+
3+
public enum ProtocolType {
4+
AWS_JSON,
5+
RPC_V2_CBOR,
6+
REST_JSON,
7+
REST_XML
8+
}

0 commit comments

Comments
 (0)