9
9
RequestSigningArguments ,
10
10
} from "@smithy/types" ;
11
11
12
- import { OptionalSigV4aSigner , signatureV4aContainer } from "./signature-v4a-container" ;
13
12
import { OptionalCrtSignerV4 , signatureV4CrtContainer } from "./signature-v4-crt-container" ;
13
+ import { OptionalSigV4aSigner , signatureV4aContainer } from "./signature-v4a-container" ;
14
14
15
15
/**
16
16
* @internal
@@ -39,8 +39,7 @@ export class SignatureV4MultiRegion implements RequestPresigner, RequestSigner {
39
39
40
40
public async sign ( requestToSign : HttpRequest , options : RequestSigningArguments = { } ) : Promise < HttpRequest > {
41
41
if ( options . signingRegion === "*" ) {
42
- const signer = await this . getSigv4aSigner ( ) ;
43
- return signer . sign ( requestToSign , options ) ;
42
+ return this . getSigv4aSigner ( ) . sign ( requestToSign , options ) ;
44
43
}
45
44
return this . sigv4Signer . sign ( requestToSign , options ) ;
46
45
}
@@ -54,16 +53,14 @@ export class SignatureV4MultiRegion implements RequestPresigner, RequestSigner {
54
53
options : RequestSigningArguments = { }
55
54
) : Promise < HttpRequest > {
56
55
if ( options . signingRegion === "*" ) {
57
- const signer = await this . getSigv4aSigner ( ) ;
58
- return signer . signWithCredentials ( requestToSign , credentials , options ) ;
56
+ return this . getSigv4aSigner ( ) . signWithCredentials ( requestToSign , credentials , options ) ;
59
57
}
60
58
return this . sigv4Signer . signWithCredentials ( requestToSign , credentials , options ) ;
61
59
}
62
60
63
61
public async presign ( originalRequest : HttpRequest , options : RequestPresigningArguments = { } ) : Promise < HttpRequest > {
64
62
if ( options . signingRegion === "*" ) {
65
- const signer = await this . getSigv4aSigner ( ) ;
66
- return signer . presign ( originalRequest , options ) ;
63
+ return this . getSigv4aSigner ( ) . presign ( originalRequest , options ) ;
67
64
}
68
65
return this . sigv4Signer . presign ( originalRequest , options ) ;
69
66
}
@@ -79,17 +76,44 @@ export class SignatureV4MultiRegion implements RequestPresigner, RequestSigner {
79
76
return this . sigv4Signer . presignWithCredentials ( originalRequest , credentials , options ) ;
80
77
}
81
78
82
- private async getSigv4aSigner ( ) : Promise < InstanceType < OptionalCrtSignerV4 > | InstanceType < OptionalSigV4aSigner > > {
79
+ private getSigv4aSigner ( ) : InstanceType < OptionalCrtSignerV4 > | InstanceType < OptionalSigV4aSigner > {
83
80
if ( ! this . sigv4aSigner ) {
81
+ let CrtSignerV4 : OptionalCrtSignerV4 | null = null ;
82
+ let JsSigV4a : OptionalSigV4aSigner | null = null ;
83
+
84
84
if ( signatureV4CrtContainer . CrtSignerV4 ) {
85
- // CRT implementation
86
- this . sigv4aSigner = new signatureV4CrtContainer . CrtSignerV4 ( {
85
+ try {
86
+ CrtSignerV4 = signatureV4CrtContainer . CrtSignerV4 ;
87
+ if ( typeof CrtSignerV4 !== "function" ) throw new Error ( ) ;
88
+ } catch ( e ) {
89
+ e . message =
90
+ `${ e . message } \n` +
91
+ `Please check whether you have installed the "@aws-sdk/signature-v4-crt" package explicitly. \n` +
92
+ `You must also register the package by calling [require("@aws-sdk/signature-v4-crt");] ` +
93
+ `or an ESM equivalent such as [import "@aws-sdk/signature-v4-crt";]. \n` +
94
+ "For more information please go to " +
95
+ "https://github.com/aws/aws-sdk-js-v3#functionality-requiring-aws-common-runtime-crt" ;
96
+ throw e ;
97
+ }
98
+
99
+ this . sigv4aSigner = new CrtSignerV4 ( {
87
100
...this . signerOptions ,
88
101
signingAlgorithm : 1 ,
89
102
} ) ;
90
103
} else if ( signatureV4aContainer . SignatureV4a ) {
91
- // SigV4a JS implementation
92
- this . sigv4aSigner = new signatureV4aContainer . SignatureV4a ( {
104
+ try {
105
+ JsSigV4a = signatureV4aContainer . SignatureV4a ;
106
+ if ( typeof JsSigV4a !== "function" ) throw new Error ( ) ;
107
+ } catch ( e ) {
108
+ e . message =
109
+ `${ e . message } \n` +
110
+ `Please check whether you have installed the "@smithy/signature-v4a" package explicitly. \n` +
111
+ `You must also register the package by calling [require("@smithy/signature-v4a");] ` +
112
+ `or an ESM equivalent such as [import "@smithy/signature-v4a";]. \n` ;
113
+ throw e ;
114
+ }
115
+
116
+ this . sigv4aSigner = new JsSigV4a ( {
93
117
...this . signerOptions ,
94
118
} ) ;
95
119
} else {
0 commit comments