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

feat(experimentalIdentityAndAuth): add codegen for HttpAuthExtensionConfiguration #910

Merged
merged 1 commit into from
Sep 7, 2023

Conversation

syall
Copy link
Contributor

@syall syall commented Sep 6, 2023

Issue #, if available:

N/A.

Description of changes:

Add code-generation for HttpAuthExtensionConfiguration, which allows
configuring:

  • httpAuthSchemes
  • httpAuthSchemeProvider
  • Any ConfigField registered by HttpAuthSchemes

Also, add relative import dependencies for:

  • httpAuthSchemeProvider
  • httpAuthExtensionConfiguration

Dependent on: #907

Testing:

Everything is gated by experimentalIdentityAndAuth.

Codegen diff in smithy-typescript-codegen-test: https://gist.github.com/syall/34efebcfb7ffa41dcebd0a40fdd30cf7#file-pr-910-diff

auth/httpAuthExtensionConfiguration.ts

The HttpAuthExtensionConfiguration specific for a service looks like this:

diff --color -Nur smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthExtensionConfiguration.ts smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthExtensionConfiguration.ts
--- smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthExtensionConfiguration.ts	1969-12-31 16:00:00
+++ smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/auth/httpAuthExtensionConfiguration.ts	2023-09-07 09:13:01
@@ -0,0 +1,96 @@
+// smithy-typescript generated code
+import { WeatherHttpAuthSchemeProvider } from "./httpAuthSchemeProvider";
+import {
+  ApiKeyIdentity,
+  ApiKeyIdentityProvider,
+  HttpAuthScheme,
+  TokenIdentity,
+  TokenIdentityProvider,
+} from "@smithy/experimental-identity-and-auth";
+import {
+  AwsCredentialIdentity,
+  AwsCredentialIdentityProvider,
+} from "@smithy/types";
+
+/**
+ * @internal
+ */
+export interface HttpAuthExtensionConfiguration {
+  setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void;
+  httpAuthSchemes(): HttpAuthScheme[];
+  setHttpAuthSchemeProvider(httpAuthSchemeProvider: WeatherHttpAuthSchemeProvider): void;
+  httpAuthSchemeProvider(): WeatherHttpAuthSchemeProvider;
+  setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void;
+  credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined;
+  setApiKey(apiKey: ApiKeyIdentity | ApiKeyIdentityProvider): void;
+  apiKey(): ApiKeyIdentity | ApiKeyIdentityProvider | undefined;
+  setToken(token: TokenIdentity | TokenIdentityProvider): void;
+  token(): TokenIdentity | TokenIdentityProvider | undefined;
+}
+
+/**
+ * @internal
+ */
+export type HttpAuthRuntimeConfig = Partial<{
+  httpAuthSchemes: HttpAuthScheme[];
+  httpAuthSchemeProvider: WeatherHttpAuthSchemeProvider;
+  credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
+  apiKey: ApiKeyIdentity | ApiKeyIdentityProvider;
+  token: TokenIdentity | TokenIdentityProvider;
+}>;
+
+/**
+ * @internal
+ */
+export const getHttpAuthExtensionConfiguration = (runtimeConfig: HttpAuthRuntimeConfig): HttpAuthExtensionConfiguration => {
+  let _httpAuthSchemes = runtimeConfig.httpAuthSchemes!;
+  let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!;
+  let _credentials = runtimeConfig.credentials;
+  let _apiKey = runtimeConfig.apiKey;
+  let _token = runtimeConfig.token;
+  return {
+    setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void {
+      _httpAuthSchemes.push(httpAuthScheme);
+    },
+    httpAuthSchemes(): HttpAuthScheme[] {
+      return _httpAuthSchemes;
+    },
+    setHttpAuthSchemeProvider(httpAuthSchemeProvider: WeatherHttpAuthSchemeProvider): void {
+      _httpAuthSchemeProvider = httpAuthSchemeProvider;
+    },
+    httpAuthSchemeProvider(): WeatherHttpAuthSchemeProvider {
+      return _httpAuthSchemeProvider;
+    },
+    setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void {
+      _credentials = credentials;
+    },
+    credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined {
+      return _credentials;
+    },
+    setApiKey(apiKey: ApiKeyIdentity | ApiKeyIdentityProvider): void {
+      _apiKey = apiKey;
+    },
+    apiKey(): ApiKeyIdentity | ApiKeyIdentityProvider | undefined {
+      return _apiKey;
+    },
+    setToken(token: TokenIdentity | TokenIdentityProvider): void {
+      _token = token;
+    },
+    token(): TokenIdentity | TokenIdentityProvider | undefined {
+      return _token;
+    },
+  }
+};
+
+/**
+ * @internal
+ */
+export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfiguration): HttpAuthRuntimeConfig => {
+  return {
+    httpAuthSchemes: config.httpAuthSchemes(),
+    httpAuthSchemeProvider: config.httpAuthSchemeProvider(),
+    credentials: config.credentials(),
+    apiKey: config.apiKey(),
+    token: config.token(),
+  };
+};

extensionConfiguration.ts

HttpAuthExtensionConfiguration is added to the service extension configuration interface:

diff --color -Nur smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/extensionConfiguration.ts smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/extensionConfiguration.ts
--- smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/extensionConfiguration.ts	2023-09-07 09:13:01
+++ smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/extensionConfiguration.ts	2023-09-07 09:13:01
@@ -1,7 +1,8 @@
 // smithy-typescript generated code
+import { HttpAuthExtensionConfiguration } from "./auth/httpAuthExtensionConfiguration";
 import { DefaultExtensionConfiguration } from "@smithy/types";
 
 /**
  * @internal
  */
-export interface WeatherExtensionConfiguration extends DefaultExtensionConfiguration {}
+export interface WeatherExtensionConfiguration extends DefaultExtensionConfiguration, HttpAuthExtensionConfiguration {}

runtimeExtensions.ts

getHttpAuthExtensionConfiguration and resolveHttpAuthRuntimeConfig are added to the resolveRuntimeExtensions stack:

diff --color -Nur smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/runtimeExtensions.ts smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/runtimeExtensions.ts
--- smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/control-experimental-identity-and-auth/typescript-codegen/src/runtimeExtensions.ts	2023-09-07 09:13:01
+++ smithy-typescript-codegen-test/build/smithyprojections/smithy-typescript-codegen-test/client-experimental-identity-and-auth/typescript-codegen/src/runtimeExtensions.ts	2023-09-07 09:13:01
@@ -1,5 +1,9 @@
 // smithy-typescript generated code
 import {
+  getHttpAuthExtensionConfiguration,
+  resolveHttpAuthRuntimeConfig,
+} from "./auth/httpAuthExtensionConfiguration";
+import {
   getDefaultExtensionConfiguration,
   resolveDefaultRuntimeConfig,
 } from "@smithy/smithy-client";
@@ -30,6 +34,7 @@
 ) => {
   const extensionConfiguration: WeatherExtensionConfiguration = {
     ...asPartial(getDefaultExtensionConfiguration(runtimeConfig)),
+    ...asPartial(getHttpAuthExtensionConfiguration(runtimeConfig)),
   };
 
   extensions.forEach(extension => extension.configure(extensionConfiguration));
@@ -37,5 +42,6 @@
   return {
     ...runtimeConfig,
     ...resolveDefaultRuntimeConfig(extensionConfiguration),
+    ...resolveHttpAuthRuntimeConfig(extensionConfiguration),
   };
 }

If one or more of the packages in the /packages directory has been modified, be sure yarn changeset add has been run and its output has
been committed and included in this pull request. See CONTRIBUTING.md.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@syall syall force-pushed the ts-ia-runtime-extension-config branch 6 times, most recently from 7758b2a to c507cd1 Compare September 7, 2023 16:12
@syall syall changed the title feat(experimentalIdentityAndAuth): add HttpAuthExtensionConfiguration feat(experimentalIdentityAndAuth): add codegen for HttpAuthExtensionConfiguration Sep 7, 2023
@syall syall force-pushed the ts-ia-runtime-extension-config branch 2 times, most recently from 1f1b128 to 7a5ba72 Compare September 7, 2023 16:28
@syall syall marked this pull request as ready for review September 7, 2023 16:29
@syall syall requested review from a team as code owners September 7, 2023 16:29
…Configuration`

Add code-generation for `HttpAuthExtensionConfiguration`, which allows
configuring:

- `httpAuthSchemes`
- `httpAuthSchemeProvider`
- Any `ConfigField` registered by `HttpAuthScheme`s

Also, add relative import dependencies for:

- `httpAuthSchemeProvider`
- `httpAuthExtensionConfiguration`
@syall syall force-pushed the ts-ia-runtime-extension-config branch from 7a5ba72 to 8b147a5 Compare September 7, 2023 16:31
@syall syall merged commit b5ae5e4 into smithy-lang:main Sep 7, 2023
7 checks passed
@syall syall deleted the ts-ia-runtime-extension-config branch September 7, 2023 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants