Skip to content

feat(experimentalIdentityAndAuth): update HttpAuthOption and HttpAuthScheme codegen #907

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 3 commits into from
Sep 6, 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/grumpy-turtles-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/experimental-identity-and-auth": patch
---

INTERNAL USE ONLY: Update `HttpAuthScheme` and `IdentityProviderConfig` interfaces
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Identity, IdentityProvider } from "@smithy/types";

import { HttpSigner } from "./HttpSigner";
import { IdentityProviderConfig } from "./IdentityProviderConfig";

/**
* ID for {@link HttpAuthScheme}
Expand All @@ -18,9 +19,9 @@ export interface HttpAuthScheme {
*/
schemeId: HttpAuthSchemeId;
/**
* IdentityProvider corresponding to an HttpAuthScheme.
* Gets the IdentityProvider corresponding to an HttpAuthScheme.
*/
identityProvider: IdentityProvider<Identity>;
identityProvider(config: IdentityProviderConfig): IdentityProvider<Identity> | undefined;
/**
* HttpSigner corresponding to an HttpAuthScheme.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Identity, IdentityProvider } from "@smithy/types";

import { HttpAuthSchemeId } from "./HttpAuthScheme";

/**
* Interface to get an IdentityProvider for a specified HttpAuthScheme
* @internal
*/
export interface IdentityProviderConfig {
/**
* Get the IdentityProvider for a specified HttpAuthScheme.
* @param schemeId schemeId of the HttpAuthScheme
* @returns IdentityProvider or undefined if HttpAuthScheme is not found
*/
getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
}

/**
* Default implementation of IddentityProviderConfig
* @internal
*/
export class DefaultIdentityProviderConfig implements IdentityProviderConfig {
private authSchemes: Map<HttpAuthSchemeId, IdentityProvider<Identity>> = new Map();

/**
* Creates an IdentityProviderConfig with a record of scheme IDs to identity providers.
*
* @param config scheme IDs and identity providers to configure
*/
constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity>>) {
for (const [key, value] of Object.entries(config)) {
this.authSchemes.set(key, value);
}
}

public getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined {
return this.authSchemes.get(schemeId);
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion packages/experimental-identity-and-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./IdentityProviderConfiguration";
export * from "./HttpAuthScheme";
export * from "./HttpSigner";
export * from "./IdentityProviderConfig";
export * from "./SigV4Signer";
export * from "./apiKeyIdentity";
export * from "./httpApiKeyAuth";
Expand Down
16 changes: 16 additions & 0 deletions smithy-typescript-codegen-test/model/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ use smithy.test#httpRequestTests
use smithy.test#httpResponseTests
use smithy.waiters#waitable

@authDefinition
@trait
structure customAuth {}

/// Provides weather forecasts.
@fakeProtocol
@httpApiKeyAuth(name: "X-Api-Key", in: "header")
@httpBearerAuth
@sigv4(name: "weather")
@customAuth
@auth([sigv4])
@paginated(inputToken: "nextToken", outputToken: "nextToken", pageSize: "pageSize")
service Weather {
Expand All @@ -30,6 +35,8 @@ service Weather {
OnlyHttpApiKeyAndBearerAuthReversed
OnlySigv4Auth
OnlySigv4AuthOptional
OnlyCustomAuth
OnlyCustomAuthOptional
SameAsService
]
}
Expand Down Expand Up @@ -69,6 +76,15 @@ operation OnlyHttpBearerAuthOptional {}
@optionalAuth
operation OnlySigv4AuthOptional {}

@http(method: "GET", uri: "/OnlyCustomAuth")
@auth([customAuth])
operation OnlyCustomAuth {}

@http(method: "GET", uri: "/OnlyCustomAuthOptional")
@auth([customAuth])
@optionalAuth
operation OnlyCustomAuthOptional {}

@http(method: "GET", uri: "/SameAsService")
operation SameAsService {}

Expand Down
14 changes: 14 additions & 0 deletions smithy-typescript-codegen-test/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@
"experimentalIdentityAndAuth": true
}
}
},
"control-experimental-identity-and-auth": {
"plugins": {
"typescript-codegen": {
"service": "example.weather#Weather",
"targetNamespace": "Weather",
"package": "weather",
"packageVersion": "0.0.1",
"packageJson": {
"license": "Apache-2.0",
"private": true
}
}
}
}
},
"plugins": {
Expand Down
Loading