-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
getCredentialsForIdentity.ts
67 lines (61 loc) · 1.85 KB
/
getCredentialsForIdentity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
buildHttpRpcRequest,
cognitoIdentityTransferHandler,
defaultConfig,
getSharedHeaders,
} from './base';
import {
Endpoint,
HttpRequest,
HttpResponse,
parseJsonBody,
parseJsonError,
parseMetadata,
} from '../../clients';
import { composeServiceApi } from '../../clients/internal';
import type {
GetCredentialsForIdentityCommandInput as GetCredentialsForIdentityInput,
GetCredentialsForIdentityCommandOutput as GetCredentialsForIdentityOutput,
Credentials,
} from './types';
export type { GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput };
const getCredentialsForIdentitySerializer = (
input: GetCredentialsForIdentityInput,
endpoint: Endpoint
): HttpRequest => {
const headers = getSharedHeaders('GetCredentialsForIdentity');
const body = JSON.stringify(input);
return buildHttpRpcRequest(endpoint, headers, body);
};
const getCredentialsForIdentityDeserializer = async (
response: HttpResponse
): Promise<GetCredentialsForIdentityOutput> => {
if (response.statusCode >= 300) {
const error = await parseJsonError(response);
throw error;
} else {
const body = await parseJsonBody(response);
return {
IdentityId: body.IdentityId,
Credentials: deserializeCredentials(body.Credentials),
$metadata: parseMetadata(response),
};
}
};
const deserializeCredentials = (output: unknown = {}): Credentials => ({
AccessKeyId: output['AccessKeyId'] as string,
SecretKey: output['SecretKey'] as string,
SessionToken: output['SessionToken'] as string,
Expiration: new Date((output['Expiration'] as number) * 1000),
});
/**
* @internal
*/
export const getCredentialsForIdentity = composeServiceApi(
cognitoIdentityTransferHandler,
getCredentialsForIdentitySerializer,
getCredentialsForIdentityDeserializer,
defaultConfig
);