-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experimentalIdentityAndAuth): release phase for SQS and DynamoDB (…
…#5284) * feat(experimentalIdentityAndAuth): enable `experimentalIdentityAndAuth` for SQS * feat(experimentalIdentityAndAuth): enable `experimentalIdentityAndAuth` for DynamoDB
- Loading branch information
Steven Yuan
authored
Dec 18, 2023
1 parent
3ed7c81
commit b3d1497
Showing
15 changed files
with
553 additions
and
51 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-dynamodb/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 { AwsCredentialIdentity, AwsCredentialIdentityProvider, HttpAuthScheme } from "@smithy/types"; | ||
|
||
import { DynamoDBHttpAuthSchemeProvider } from "./httpAuthSchemeProvider"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthExtensionConfiguration { | ||
setHttpAuthScheme(httpAuthScheme: HttpAuthScheme): void; | ||
httpAuthSchemes(): HttpAuthScheme[]; | ||
setHttpAuthSchemeProvider(httpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider): void; | ||
httpAuthSchemeProvider(): DynamoDBHttpAuthSchemeProvider; | ||
setCredentials(credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider): void; | ||
credentials(): AwsCredentialIdentity | AwsCredentialIdentityProvider | undefined; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export type HttpAuthRuntimeConfig = Partial<{ | ||
httpAuthSchemes: HttpAuthScheme[]; | ||
httpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider; | ||
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 { | ||
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: DynamoDBHttpAuthSchemeProvider): void { | ||
_httpAuthSchemeProvider = httpAuthSchemeProvider; | ||
}, | ||
httpAuthSchemeProvider(): DynamoDBHttpAuthSchemeProvider { | ||
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(), | ||
}; | ||
}; |
137 changes: 137 additions & 0 deletions
137
clients/client-dynamodb/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,137 @@ | ||
// smithy-typescript generated code | ||
import { | ||
AWSSDKSigV4AuthInputConfig, | ||
AWSSDKSigV4AuthResolvedConfig, | ||
AWSSDKSigV4PreviouslyResolved, | ||
resolveAWSSDKSigV4Config, | ||
} from "@aws-sdk/core"; | ||
import { | ||
HandlerExecutionContext, | ||
HttpAuthOption, | ||
HttpAuthScheme, | ||
HttpAuthSchemeParameters, | ||
HttpAuthSchemeParametersProvider, | ||
HttpAuthSchemeProvider, | ||
} from "@smithy/types"; | ||
import { getSmithyContext, normalizeProvider } from "@smithy/util-middleware"; | ||
|
||
import { DynamoDBClientConfig, DynamoDBClientResolvedConfig } from "../DynamoDBClient"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface DynamoDBHttpAuthSchemeParameters extends HttpAuthSchemeParameters { | ||
region?: string; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface DynamoDBHttpAuthSchemeParametersProvider | ||
extends HttpAuthSchemeParametersProvider< | ||
DynamoDBClientResolvedConfig, | ||
HandlerExecutionContext, | ||
DynamoDBHttpAuthSchemeParameters, | ||
object | ||
> {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defaultDynamoDBHttpAuthSchemeParametersProvider = async ( | ||
config: DynamoDBClientResolvedConfig, | ||
context: HandlerExecutionContext, | ||
input: object | ||
): Promise<DynamoDBHttpAuthSchemeParameters> => { | ||
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: DynamoDBHttpAuthSchemeParameters): HttpAuthOption { | ||
return { | ||
schemeId: "aws.auth#sigv4", | ||
signingProperties: { | ||
name: "dynamodb", | ||
region: authParameters.region, | ||
}, | ||
propertiesExtractor: (config: DynamoDBClientConfig, context) => ({ | ||
/** | ||
* @internal | ||
*/ | ||
signingProperties: { | ||
config, | ||
context, | ||
}, | ||
}), | ||
}; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface DynamoDBHttpAuthSchemeProvider extends HttpAuthSchemeProvider<DynamoDBHttpAuthSchemeParameters> {} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const defaultDynamoDBHttpAuthSchemeProvider: DynamoDBHttpAuthSchemeProvider = (authParameters) => { | ||
const options: HttpAuthOption[] = []; | ||
switch (authParameters.operation) { | ||
default: { | ||
options.push(createAwsAuthSigv4HttpAuthOption(authParameters)); | ||
} | ||
} | ||
return options; | ||
}; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthSchemeInputConfig extends AWSSDKSigV4AuthInputConfig { | ||
/** | ||
* 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?: DynamoDBHttpAuthSchemeProvider; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export interface HttpAuthSchemeResolvedConfig extends AWSSDKSigV4AuthResolvedConfig { | ||
/** | ||
* 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: DynamoDBHttpAuthSchemeProvider; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const resolveHttpAuthSchemeConfig = <T>( | ||
config: T & HttpAuthSchemeInputConfig & AWSSDKSigV4PreviouslyResolved | ||
): T & HttpAuthSchemeResolvedConfig => { | ||
const config_0 = resolveAWSSDKSigV4Config(config); | ||
return { | ||
...config_0, | ||
} as T & HttpAuthSchemeResolvedConfig; | ||
}; |
Oops, something went wrong.