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

Add HttpAuthScheme interfaces for auth scheme resolution #928

Merged
merged 2 commits into from
Sep 14, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/gorgeous-rabbits-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/experimental-identity-and-auth": patch
---

Add additional `HttpAuthScheme` interfaces for auth scheme resolution
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ export interface HttpAuthOption {
identityProperties?: Record<string, unknown>;
signingProperties?: Record<string, unknown>;
}

/**
* @internal
*/
export interface SelectedHttpAuthScheme {
httpAuthOption: HttpAuthOption;
identity: Identity;
signer: HttpSigner;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { HandlerExecutionContext } from "@smithy/types";

import { HttpAuthOption } from "./HttpAuthScheme";

/**
* @internal
*/
export interface HttpAuthSchemeParameters {
operation?: string;
}

/**
* @internal
*/
export interface HttpAuthSchemeProvider<TParameters extends HttpAuthSchemeParameters = HttpAuthSchemeParameters> {
(authParameters: TParameters): HttpAuthOption[];
}

/**
* @internal
*/
export interface HttpAuthSchemeParametersProvider<
C extends object = object,
T extends HttpAuthSchemeParameters = HttpAuthSchemeParameters
> {
(config: C, context: HandlerExecutionContext): Promise<T>;
}
1 change: 1 addition & 0 deletions packages/experimental-identity-and-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./HttpAuthScheme";
export * from "./HttpAuthSchemeProvider";
export * from "./HttpSigner";
export * from "./IdentityProviderConfig";
export * from "./SigV4Signer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,24 @@ public void run() {
}

/*
export interface WeatherHttpAuthSchemeParameters {
operation?: string;
import { HttpAuthSchemeParameters } from "@smithy/types";

// ...

export interface WeatherHttpAuthSchemeParameters extends HttpAuthSchemeParameters {
}
*/
private void generateHttpAuthSchemeParametersInterface() {
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
w.addImport("HttpAuthSchemeParameters", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
w.openBlock("""
/**
* @internal
*/
export interface $LHttpAuthSchemeParameters {""", "}",
export interface $LHttpAuthSchemeParameters extends HttpAuthSchemeParameters {""", "}",
serviceName,
() -> {
w.write("operation?: string;");
for (HttpAuthScheme authScheme : authIndex.getSupportedHttpAuthSchemes().values()) {
for (HttpAuthSchemeParameter parameter : authScheme.getHttpAuthSchemeParameters()) {
w.write("$L?: $C;", parameter.name(), parameter.type());
Expand All @@ -110,32 +114,31 @@ export interface $LHttpAuthSchemeParameters {""", "}",

/*
import { WeatherClientResolvedConfig } from "../WeatherClient";
import { HandlerExecutionContext } from "@smithy/types";
import { HttpAuthSchemeParametersProvider } from "@smithy/types";

// ...

export async function defaultWeatherHttpAuthSchemeParametersProvider(
config: WeatherClientResolvedConfig,
context: HandlerExecutionContext
): Promise<WeatherHttpAuthSchemeParameters> {
return {
operation: context.commandName,
};
export const defaultWeatherHttpAuthSchemeParametersProvider:
HttpAuthSchemeParametersProvider<WeatherClientResolvedConfig, WeatherHttpAuthSchemeParameters> =
async (config, context) => {
return {
operation: context.commandName,
};
};
*/
private void generateDefaultHttpAuthSchemeParametersProviderFunction() {
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
w.addRelativeImport(serviceSymbol.getName() + "ResolvedConfig", null,
Paths.get(".", serviceSymbol.getNamespace()));
w.addImport("HandlerExecutionContext", null, TypeScriptDependency.SMITHY_TYPES);
w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
w.addImport("HttpAuthSchemeParametersProvider", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
w.openBlock("""
/**
* @internal
*/
export async function default$LHttpAuthSchemeParametersProvider(
config: $LResolvedConfig,
context: HandlerExecutionContext
): Promise<$LHttpAuthSchemeParameters> {""", "};",
export const default$LHttpAuthSchemeParametersProvider: \
HttpAuthSchemeParametersProvider<$LResolvedConfig, $LHttpAuthSchemeParameters> = \
async (config, context) => {""", "};",
serviceName, serviceSymbol.getName(), serviceName,
() -> {
w.openBlock("return {", "};", () -> {
Expand Down Expand Up @@ -223,26 +226,28 @@ private static String normalizeAuthSchemeName(ShapeId shapeId) {
}

/*
export interface WeatherHttpAuthSchemeProvider {
(authParameters: WeatherHttpAuthSchemeParameters): HttpAuthOption[];
}
import { HttpAuthSchemeProvider } from "@smithy/types";

// ...

export interface WeatherHttpAuthSchemeProvider extends HttpAuthSchemeProvider<WeatherHttpAuthSchemeParameters> {}
*/
private void generateHttpAuthSchemeProviderInterface() {
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
w.addImport("HttpAuthSchemeProvider", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
w.write("""
/**
* @internal
*/
export interface $LHttpAuthSchemeProvider {
(authParameters: $LHttpAuthSchemeParameters): HttpAuthOption[];
}
export interface $LHttpAuthSchemeProvider extends HttpAuthSchemeProvider<$LHttpAuthSchemeParameters> {}
""", serviceName, serviceName);
});
}

/*
export function defaultWeatherHttpAuthSchemeProvider(authParameters: WeatherHttpAuthSchemeParameters):
HttpAuthOption[] {
export const defaultWeatherHttpAuthSchemeProvider: WeatherHttpAuthSchemeProvider =
(authParameters) => {
const options: HttpAuthOption[] = [];
switch (authParameters.operation) {
default: {
Expand All @@ -258,8 +263,9 @@ private void generateHttpAuthSchemeProviderDefaultFunction() {
/**
* @internal
*/
export function default$LHttpAuthSchemeProvider(authParameters: $LHttpAuthSchemeParameters): \
HttpAuthOption[] {""", "};", serviceName, serviceName, () -> {
export const default$LHttpAuthSchemeProvider: $LHttpAuthSchemeProvider = \
(authParameters) => {""", "};",
serviceName, serviceName, () -> {
w.write("const options: HttpAuthOption[] = [];");
w.openBlock("switch (authParameters.operation) {", "};", () -> {
var serviceAuthSchemes = serviceIndex.getEffectiveAuthSchemes(
Expand Down