-
Notifications
You must be signed in to change notification settings - Fork 614
Support generating non-AWS client #2222
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
Changes from 5 commits
b8de38b
24937b2
a141f92
c3a3c65
b3cfe4e
9dc7ef5
f2ba23a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isAwsService; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -33,12 +35,15 @@ | |
/** | ||
* Add client plubins and configs to support injecting user agent. | ||
*/ | ||
// TODO: Looks to add this back for non-AWS service clients, by fixing the dependency on ClientSharedValues.serviceId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be fairly easy to just write out the service shape name / id. This is what Go does |
||
public class AddUserAgentDependency implements TypeScriptIntegration { | ||
@Override | ||
public List<RuntimeClientPlugin> getClientPlugins() { | ||
return ListUtils.of( | ||
RuntimeClientPlugin.builder() | ||
.withConventions(AwsDependency.MIDDLEWARE_USER_AGENT.dependency, "UserAgent").build()); | ||
.withConventions(AwsDependency.MIDDLEWARE_USER_AGENT.dependency, "UserAgent") | ||
.servicePredicate((m, s) -> isAwsService(s)) | ||
.build()); | ||
} | ||
|
||
@Override | ||
|
@@ -48,6 +53,9 @@ public void addConfigInterfaceFields( | |
SymbolProvider symbolProvider, | ||
TypeScriptWriter writer | ||
) { | ||
if (!isAwsService(settings, model)) { | ||
return; | ||
} | ||
writer.addImport("Provider", "Provider", TypeScriptDependency.AWS_SDK_TYPES.packageName); | ||
writer.addImport("UserAgent", "__UserAgent", TypeScriptDependency.AWS_SDK_TYPES.packageName); | ||
writer.writeDocs("The provider populating default tracking information to be sent with `user-agent`, " | ||
|
@@ -62,6 +70,9 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters( | |
SymbolProvider symbolProvider, | ||
LanguageTarget target | ||
) { | ||
if (!isAwsService(settings, model)) { | ||
return Collections.emptyMap(); | ||
} | ||
switch (target) { | ||
case NODE: | ||
return MapUtils.of( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import software.amazon.smithy.aws.traits.ServiceTrait; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.shapes.ServiceShape; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
|
||
/** | ||
* Utility methods related to AWS traits. | ||
*/ | ||
final class AwsTraitsUtils { | ||
|
||
private AwsTraitsUtils() {} | ||
|
||
static boolean isAwsService(TypeScriptSettings settings, Model model) { | ||
return isAwsService(settings.getService(model)); | ||
} | ||
|
||
static boolean isAwsService(ServiceShape serviceShape) { | ||
return serviceShape.hasTrait(ServiceTrait.class); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the service has an auth trait you need to add the mechanics needed to support that regardless of what the default is (where
@auth([])
is no auth by default). Since theauth
trait can only reference auth traits on the service, you don't have to worry about a single operation introducing its own auth. I'm pretty sure the current setup already handles operations with disabled auth.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put this TODO to think more deeply about different cases when I handle supporting SigV4 for non-AWS clients.