forked from aws/aws-sdk-js-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client-eventbridge): codegen EventBridge with `experimentalIdent…
…ityAndAuth`
- Loading branch information
Steven Yuan
committed
Sep 25, 2023
1 parent
e7c4d6f
commit 69775fe
Showing
9 changed files
with
269 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
clients/client-eventbridge/src/auth/httpAuthExtensionConfiguration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// smithy-typescript generated code | ||
import { HttpAuthScheme } from "@smithy/experimental-identity-and-auth"; | ||
import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from "@smithy/types"; | ||
|
||
import { EventBridgeHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthExtensionConfiguration { | ||
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; | ||
httpAuthSchemes(): HttpAuthScheme[]; | ||
setHttpAuthSchemeProvider(httpAuthSchemeProvider: EventBridgeHttpAuthSchemeProvider): void; | ||
httpAuthSchemeProvider(): EventBridgeHttpAuthSchemeProvider; | ||
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void; | ||
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type HttpAuthRuntimeConfig = Partial<{ | ||
httpAuthSchemes: HttpAuthScheme[]; | ||
httpAuthSchemeProvider: EventBridgeHttpAuthSchemeProvider; | ||
credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider; | ||
}>; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const getHttpAuthExtensionConfiguration = ( | ||
runtimeConfig: HttpAuthRuntimeConfig | ||
): HttpAuthExtensionConfiguration => { | ||
const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!; | ||
let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!; | ||
let _credentials = runtimeConfig.credentials; | ||
return { | ||
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void { | ||
_httpAuthSchemes.push(httpAuthScheme); | ||
}, | ||
httpAuthSchemes(): HttpAuthScheme[] { | ||
return _httpAuthSchemes; | ||
}, | ||
setHttpAuthSchemeProvider(httpAuthSchemeProvider: EventBridgeHttpAuthSchemeProvider): void { | ||
_httpAuthSchemeProvider = httpAuthSchemeProvider; | ||
}, | ||
httpAuthSchemeProvider(): EventBridgeHttpAuthSchemeProvider { | ||
return _httpAuthSchemeProvider; | ||
}, | ||
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void { | ||
_credentials = credentials; | ||
}, | ||
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined { | ||
return _credentials; | ||
}, | ||
}; | ||
}; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const resolveHttpAuthRuntimeConfig = (config: HttpAuthExtensionConfiguration): HttpAuthRuntimeConfig => { | ||
return { | ||
httpAuthSchemes: config.httpAuthSchemes(), | ||
httpAuthSchemeProvider: config.httpAuthSchemeProvider(), | ||
credentials: config.credentials(), | ||
}; | ||
}; |
131 changes: 131 additions & 0 deletions
131
clients/client-eventbridge/src/auth/httpAuthSchemeProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// smithy-typescript generated code | ||
import { | ||
DefaultIdentityProviderConfig, | ||
doesIdentityRequireRefresh, | ||
HttpAuthOption, | ||
HttpAuthSchemeParameters, | ||
HttpAuthSchemeParametersProvider, | ||
HttpAuthSchemeProvider, | ||
IdentityProviderConfig, | ||
isIdentityExpired, | ||
memoizeIdentityProvider, | ||
} from "@smithy/experimental-identity-and-auth"; | ||
import { AwsCredentialIdentity, AwsCredentialIdentityProvider, Provider as __Provider } from "@smithy/types"; | ||
import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware"; | ||
|
||
import { EventBridgeClientResolvedConfig } from "../EventBridgeClient"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface EventBridgeHttpAuthSchemeParameters extends HttpAuthSchemeParameters { | ||
region?: string; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface EventBridgeHttpAuthSchemeParametersProvider | ||
extends HttpAuthSchemeParametersProvider<EventBridgeClientResolvedConfig, EventBridgeHttpAuthSchemeParameters> {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defaultEventBridgeHttpAuthSchemeParametersProvider: EventBridgeHttpAuthSchemeParametersProvider = async ( | ||
config, | ||
context, | ||
input | ||
) => { | ||
return { | ||
operation: getSmithyContext(context).operation as string, | ||
region: | ||
(await normalizeProvider(config.region)()) || | ||
(() => { | ||
throw new Error("expected `region` to be configured for `aws.auth#sigv4`"); | ||
})(), | ||
}; | ||
}; | ||
|
||
function createAwsAuthSigv4HttpAuthOption(authParameters: EventBridgeHttpAuthSchemeParameters): HttpAuthOption { | ||
return { | ||
schemeId: "aws.auth#sigv4", | ||
signingProperties: { | ||
name: "events", | ||
region: authParameters.region, | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface EventBridgeHttpAuthSchemeProvider | ||
extends HttpAuthSchemeProvider<EventBridgeHttpAuthSchemeParameters> {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defaultEventBridgeHttpAuthSchemeProvider: EventBridgeHttpAuthSchemeProvider = (authParameters) => { | ||
const options: HttpAuthOption[] = []; | ||
switch (authParameters.operation) { | ||
default: { | ||
options.push(createAwsAuthSigv4HttpAuthOption(authParameters)); | ||
} | ||
} | ||
return options; | ||
}; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthSchemeInputConfig { | ||
/** | ||
* The credentials used to sign requests. | ||
*/ | ||
credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider; | ||
/** | ||
* The AWS region to which this client will send requests. | ||
*/ | ||
region?: string | __Provider<string>; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthSchemeResolvedConfig { | ||
/** | ||
* The credentials used to sign requests. | ||
*/ | ||
readonly credentials?: AwsCredentialIdentityProvider; | ||
/** | ||
* The AWS region to which this client will send requests. | ||
*/ | ||
readonly region?: __Provider<string>; | ||
/** | ||
* experimentalIdentityAndAuth: provides parameters for HttpAuthSchemeProvider. | ||
* @internal | ||
*/ | ||
readonly httpAuthSchemeParametersProvider: EventBridgeHttpAuthSchemeParametersProvider; | ||
/** | ||
* experimentalIdentityAndAuth: abstraction around identity configuration fields | ||
* @internal | ||
*/ | ||
readonly identityProviderConfig: IdentityProviderConfig; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const resolveHttpAuthSchemeConfig = (config: HttpAuthSchemeInputConfig): HttpAuthSchemeResolvedConfig => { | ||
const credentials = memoizeIdentityProvider(config.credentials, isIdentityExpired, doesIdentityRequireRefresh); | ||
const region = config.region ? normalizeProvider(config.region) : undefined; | ||
return { | ||
...config, | ||
credentials, | ||
region, | ||
httpAuthSchemeParametersProvider: defaultEventBridgeHttpAuthSchemeParametersProvider, | ||
identityProviderConfig: new DefaultIdentityProviderConfig({ | ||
"aws.auth#sigv4": credentials, | ||
}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.