@@ -32,6 +32,29 @@ export interface AwsAuthInputConfig {
32
32
*/
33
33
signingRegion ?: string ;
34
34
}
35
+
36
+ export interface CustomAwsAuthInputConfig {
37
+ /**
38
+ * The credentials used to sign requests.
39
+ */
40
+ credentials ?: Credentials | Provider < Credentials > ;
41
+
42
+ /**
43
+ * The signer to use when signing requests.
44
+ */
45
+ signer ?: RequestSigner | Provider < RequestSigner > ;
46
+
47
+ /**
48
+ * Whether to escape request path when signing the request.
49
+ */
50
+ signingEscapePath ?: boolean ;
51
+
52
+ /**
53
+ * An offset value in milliseconds to apply to all signing times.
54
+ */
55
+ systemClockOffset ?: number ;
56
+ }
57
+
35
58
interface PreviouslyResolved {
36
59
credentialDefaultProvider : ( input : any ) => Provider < Credentials > ;
37
60
region : string | Provider < string > ;
@@ -40,13 +63,23 @@ interface PreviouslyResolved {
40
63
serviceId : string ;
41
64
sha256 : HashConstructor ;
42
65
}
66
+
67
+ interface CustomPreviouslyResolved {
68
+ credentialDefaultProvider : ( input : any ) => Provider < Credentials > ;
69
+ region : string | Provider < string > ;
70
+ signingName : string ;
71
+ sha256 : HashConstructor ;
72
+ }
73
+
43
74
export interface AwsAuthResolvedConfig {
44
75
credentials : Provider < Credentials > ;
45
76
signer : Provider < RequestSigner > ;
46
77
signingEscapePath : boolean ;
47
78
systemClockOffset : number ;
48
79
}
49
80
81
+ export interface CustomAwsAuthResolvedConfig extends AwsAuthResolvedConfig { }
82
+
50
83
export const resolveAwsAuthConfig = < T > (
51
84
input : T & AwsAuthInputConfig & PreviouslyResolved
52
85
) : T & AwsAuthResolvedConfig => {
@@ -91,6 +124,37 @@ export const resolveAwsAuthConfig = <T>(
91
124
} ;
92
125
} ;
93
126
127
+ // TODO: reduce code duplication
128
+ export const resolveCustomAwsAuthConfig = < T > (
129
+ input : T & CustomAwsAuthInputConfig & CustomPreviouslyResolved
130
+ ) : T & CustomAwsAuthResolvedConfig => {
131
+ const normalizedCreds = input . credentials
132
+ ? normalizeCredentialProvider ( input . credentials )
133
+ : input . credentialDefaultProvider ( input as any ) ;
134
+ const { signingEscapePath = true , systemClockOffset = input . systemClockOffset || 0 , sha256 } = input ;
135
+ let signer : Provider < RequestSigner > ;
136
+ if ( input . signer ) {
137
+ //if signer is supplied by user, normalize it to a function returning a promise for signer.
138
+ signer = normalizeProvider ( input . signer ) ;
139
+ } else {
140
+ signer = normalizeProvider ( new SignatureV4 ( {
141
+ credentials : normalizedCreds ,
142
+ region : input . region ,
143
+ service : input . signingName ,
144
+ sha256,
145
+ uriEscapePath : signingEscapePath ,
146
+ } ) ) ;
147
+ }
148
+
149
+ return {
150
+ ...input ,
151
+ systemClockOffset,
152
+ signingEscapePath,
153
+ credentials : normalizedCreds ,
154
+ signer,
155
+ } ;
156
+ } ;
157
+
94
158
const normalizeProvider = < T > ( input : T | Provider < T > ) : Provider < T > => {
95
159
if ( typeof input === "object" ) {
96
160
const promisified = Promise . resolve ( input ) ;
0 commit comments