Skip to content

Commit

Permalink
feat(experimentalIdentityAndAuth): add different `httpAuthSchemeMiddl…
Browse files Browse the repository at this point in the history
…eware` plugins depending on `@endpointRuleSet` (#1004)
  • Loading branch information
Steven Yuan authored Oct 10, 2023
1 parent 58824d8 commit 6c53a93
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-cycles-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/experimental-identity-and-auth": patch
---

Add different `httpAuthSchemeMiddleware` plugins depending on `@endpointRuleSet`
1 change: 1 addition & 0 deletions packages/experimental-identity-and-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@smithy/middleware-endpoint": "workspace:^",
"@smithy/middleware-retry": "workspace:^",
"@smithy/middleware-serde": "workspace:^",
"@smithy/protocol-http": "workspace:^",
"@smithy/signature-v4": "workspace:^",
"@smithy/types": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { endpointMiddlewareOptions } from "@smithy/middleware-endpoint";
import { HandlerExecutionContext, Pluggable, RelativeMiddlewareOptions, SerializeHandlerOptions } from "@smithy/types";

import { HttpAuthSchemeParameters } from "../HttpAuthSchemeProvider";
import { httpAuthSchemeMiddleware, PreviouslyResolved } from "./httpAuthSchemeMiddleware";

/**
* @internal
*/
export const httpAuthSchemeEndpointRuleSetMiddlewareOptions: SerializeHandlerOptions & RelativeMiddlewareOptions = {
step: "serialize",
tags: ["HTTP_AUTH_SCHEME"],
name: "httpAuthSchemeMiddleware",
override: true,
relation: "before",
toMiddleware: endpointMiddlewareOptions.name!,
};

/**
* @internal
*/
export const getHttpAuthSchemeEndpointRuleSetPlugin = <
TConfig extends object,
TContext extends HandlerExecutionContext,
TParameters extends HttpAuthSchemeParameters,
TInput extends object
>(
config: TConfig & PreviouslyResolved<TConfig, TContext, TParameters, TInput>
): Pluggable<any, any> => ({
applyToStack: (clientStack) => {
clientStack.addRelativeTo(httpAuthSchemeMiddleware(config), httpAuthSchemeEndpointRuleSetMiddlewareOptions);
},
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { endpointMiddlewareOptions } from "@smithy/middleware-endpoint";
import { serializerMiddlewareOption } from "@smithy/middleware-serde";
import { HandlerExecutionContext, Pluggable, RelativeMiddlewareOptions, SerializeHandlerOptions } from "@smithy/types";

import { HttpAuthSchemeParameters } from "../HttpAuthSchemeProvider";
Expand All @@ -13,7 +13,7 @@ export const httpAuthSchemeMiddlewareOptions: SerializeHandlerOptions & Relative
name: "httpAuthSchemeMiddleware",
override: true,
relation: "before",
toMiddleware: endpointMiddlewareOptions.name!,
toMiddleware: serializerMiddlewareOption.name!,
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./httpAuthSchemeMiddleware";
export * from "./getHttpAuthSchemeEndpointRuleSetPlugin";
export * from "./getHttpAuthSchemePlugin";
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package software.amazon.smithy.typescript.codegen.auth.http.integration;

import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -17,6 +15,7 @@
import software.amazon.smithy.model.knowledge.ServiceIndex;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.ConfigField;
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenContext;
Expand All @@ -27,6 +26,7 @@
import software.amazon.smithy.typescript.codegen.auth.http.HttpAuthScheme;
import software.amazon.smithy.typescript.codegen.auth.http.SupportedHttpAuthSchemesIndex;
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
Expand All @@ -46,10 +46,18 @@ public boolean matchesSettings(TypeScriptSettings settings) {
public List<RuntimeClientPlugin> getClientPlugins() {
return List.of(
RuntimeClientPlugin.builder()
.servicePredicate((m, s) -> s.hasTrait(EndpointRuleSetTrait.ID))
.withConventions(
TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH.dependency,
"HttpAuthSchemeEndpointRuleSet",
Convention.HAS_MIDDLEWARE)
.build(),
RuntimeClientPlugin.builder()
.servicePredicate((m, s) -> !s.hasTrait(EndpointRuleSetTrait.ID))
.withConventions(
TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH.dependency,
"HttpAuthScheme",
HAS_MIDDLEWARE)
Convention.HAS_MIDDLEWARE)
.build(),
RuntimeClientPlugin.builder()
.inputConfig(Symbol.builder()
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,7 @@ __metadata:
dependencies:
"@smithy/middleware-endpoint": "workspace:^"
"@smithy/middleware-retry": "workspace:^"
"@smithy/middleware-serde": "workspace:^"
"@smithy/protocol-http": "workspace:^"
"@smithy/signature-v4": "workspace:^"
"@smithy/types": "workspace:^"
Expand Down

0 comments on commit 6c53a93

Please sign in to comment.