-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(codegen): generate client-codecatalyst
- Loading branch information
Steven Yuan
committed
Nov 14, 2023
1 parent
a24144b
commit 9eac44a
Showing
9 changed files
with
285 additions
and
8 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
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
72 changes: 72 additions & 0 deletions
72
clients/client-codecatalyst/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,72 @@ | ||
// smithy-typescript generated code | ||
import { HttpAuthScheme, TokenIdentity, TokenIdentityProvider } from "@smithy/types"; | ||
|
||
import { CodeCatalystHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthExtensionConfiguration { | ||
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; | ||
httpAuthSchemes(): HttpAuthScheme[]; | ||
setHttpAuthSchemeProvider(httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider): void; | ||
httpAuthSchemeProvider(): CodeCatalystHttpAuthSchemeProvider; | ||
setToken(token: TokenIdentity | TokenIdentityProvider): void; | ||
token(): TokenIdentity | TokenIdentityProvider | undefined; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type HttpAuthRuntimeConfig = Partial<{ | ||
httpAuthSchemes: HttpAuthScheme[]; | ||
httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider; | ||
token: TokenIdentity | TokenIdentityProvider; | ||
}>; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const getHttpAuthExtensionConfiguration = ( | ||
runtimeConfig: HttpAuthRuntimeConfig | ||
): HttpAuthExtensionConfiguration => { | ||
const _httpAuthSchemes = runtimeConfig.httpAuthSchemes!; | ||
let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider!; | ||
let _token = runtimeConfig.token; | ||
return { | ||
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void { | ||
const index = _httpAuthSchemes.findIndex((scheme) => scheme.schemeId === httpAuthScheme.schemeId); | ||
if (index === -1) { | ||
_httpAuthSchemes.push(httpAuthScheme); | ||
} else { | ||
_httpAuthSchemes.splice(index, 1, httpAuthScheme); | ||
} | ||
}, | ||
httpAuthSchemes(): HttpAuthScheme[] { | ||
return _httpAuthSchemes; | ||
}, | ||
setHttpAuthSchemeProvider(httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider): void { | ||
_httpAuthSchemeProvider = httpAuthSchemeProvider; | ||
}, | ||
httpAuthSchemeProvider(): CodeCatalystHttpAuthSchemeProvider { | ||
return _httpAuthSchemeProvider; | ||
}, | ||
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(), | ||
token: config.token(), | ||
}; | ||
}; |
134 changes: 134 additions & 0 deletions
134
clients/client-codecatalyst/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,134 @@ | ||
// smithy-typescript generated code | ||
import { doesIdentityRequireRefresh, isIdentityExpired, memoizeIdentityProvider } from "@smithy/core"; | ||
import { | ||
HandlerExecutionContext, | ||
HttpAuthOption, | ||
HttpAuthScheme, | ||
HttpAuthSchemeParameters, | ||
HttpAuthSchemeParametersProvider, | ||
HttpAuthSchemeProvider, | ||
TokenIdentity, | ||
TokenIdentityProvider, | ||
} from "@smithy/types"; | ||
import { getSmithyContext } from "@smithy/util-middleware"; | ||
|
||
import { CodeCatalystClientResolvedConfig } from "../CodeCatalystClient"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface CodeCatalystHttpAuthSchemeParameters extends HttpAuthSchemeParameters {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface CodeCatalystHttpAuthSchemeParametersProvider | ||
extends HttpAuthSchemeParametersProvider< | ||
CodeCatalystClientResolvedConfig, | ||
HandlerExecutionContext, | ||
CodeCatalystHttpAuthSchemeParameters, | ||
object | ||
> {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defaultCodeCatalystHttpAuthSchemeParametersProvider = async ( | ||
config: CodeCatalystClientResolvedConfig, | ||
context: HandlerExecutionContext, | ||
input: object | ||
): Promise<CodeCatalystHttpAuthSchemeParameters> => { | ||
return { | ||
operation: getSmithyContext(context).operation as string, | ||
}; | ||
}; | ||
|
||
function createSmithyApiHttpBearerAuthHttpAuthOption( | ||
authParameters: CodeCatalystHttpAuthSchemeParameters | ||
): HttpAuthOption { | ||
return { | ||
schemeId: "smithy.api#httpBearerAuth", | ||
propertiesExtractor: (__config, context) => ({ | ||
/** | ||
* @internal | ||
*/ | ||
identityProperties: { | ||
__config, | ||
}, | ||
}), | ||
}; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface CodeCatalystHttpAuthSchemeProvider | ||
extends HttpAuthSchemeProvider<CodeCatalystHttpAuthSchemeParameters> {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defaultCodeCatalystHttpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider = (authParameters) => { | ||
const options: HttpAuthOption[] = []; | ||
switch (authParameters.operation) { | ||
default: { | ||
options.push(createSmithyApiHttpBearerAuthHttpAuthOption(authParameters)); | ||
} | ||
} | ||
return options; | ||
}; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthSchemeInputConfig { | ||
/** | ||
* experimentalIdentityAndAuth: Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. | ||
* @internal | ||
*/ | ||
httpAuthSchemes?: HttpAuthScheme[]; | ||
|
||
/** | ||
* experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. | ||
* @internal | ||
*/ | ||
httpAuthSchemeProvider?: CodeCatalystHttpAuthSchemeProvider; | ||
|
||
/** | ||
* The token used to authenticate requests. | ||
*/ | ||
token?: TokenIdentity | TokenIdentityProvider; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthSchemeResolvedConfig { | ||
/** | ||
* experimentalIdentityAndAuth: Configuration of HttpAuthSchemes for a client which provides default identity providers and signers per auth scheme. | ||
* @internal | ||
*/ | ||
readonly httpAuthSchemes: HttpAuthScheme[]; | ||
|
||
/** | ||
* experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which resolves which HttpAuthScheme to use. | ||
* @internal | ||
*/ | ||
readonly httpAuthSchemeProvider: CodeCatalystHttpAuthSchemeProvider; | ||
|
||
/** | ||
* The token used to authenticate requests. | ||
*/ | ||
readonly token?: TokenIdentityProvider; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const resolveHttpAuthSchemeConfig = (config: HttpAuthSchemeInputConfig): HttpAuthSchemeResolvedConfig => { | ||
const token = memoizeIdentityProvider(config.token, isIdentityExpired, doesIdentityRequireRefresh); | ||
return { | ||
...config, | ||
token, | ||
} as HttpAuthSchemeResolvedConfig; | ||
}; |
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.