@aws-sdk/rds-signer 3.1057.0 → 3.1058.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -5,6 +5,7 @@ var protocols = require('@smithy/core/protocols');
5
5
  var signatureV4 = require('@smithy/signature-v4');
6
6
  var runtimeConfig = require('./runtimeConfig');
7
7
 
8
+ const MINUTE_MS = 60_000;
8
9
  class Signer {
9
10
  credentials;
10
11
  hostname;
@@ -16,7 +17,8 @@ class Signer {
16
17
  username;
17
18
  constructor(configuration) {
18
19
  const runtimeConfiguration = runtimeConfig.getRuntimeConfig(configuration);
19
- this.credentials = runtimeConfiguration.credentials;
20
+ const creds = runtimeConfiguration.credentials;
21
+ this.credentials = typeof creds === "function" ? this.createCredentialsWrapper(creds) : creds;
20
22
  this.hostname = runtimeConfiguration.hostname;
21
23
  this.port = runtimeConfiguration.port;
22
24
  this.region = runtimeConfiguration.region;
@@ -48,6 +50,21 @@ class Signer {
48
50
  });
49
51
  return util.formatUrl(presigned).replace(`${this.protocol}//`, "");
50
52
  }
53
+ createCredentialsWrapper(provider) {
54
+ return async (identityProperties) => {
55
+ const credentials = await provider(identityProperties);
56
+ if (credentials.expiration && credentials.expiration.getTime() - Date.now() < 15 * MINUTE_MS) {
57
+ try {
58
+ const refreshed = await provider({ ...identityProperties, forceRefresh: true });
59
+ if (!refreshed.expiration || refreshed.expiration.getTime() - Date.now() >= 15 * MINUTE_MS) {
60
+ return refreshed;
61
+ }
62
+ }
63
+ catch { }
64
+ }
65
+ return credentials;
66
+ };
67
+ }
51
68
  }
52
69
 
53
70
  exports.Signer = Signer;
package/dist-es/Signer.js CHANGED
@@ -2,6 +2,7 @@ import { formatUrl } from "@aws-sdk/core/util";
2
2
  import { HttpRequest } from "@smithy/core/protocols";
3
3
  import { SignatureV4 } from "@smithy/signature-v4";
4
4
  import { getRuntimeConfig as __getRuntimeConfig } from "./runtimeConfig";
5
+ const MINUTE_MS = 60_000;
5
6
  export class Signer {
6
7
  credentials;
7
8
  hostname;
@@ -13,7 +14,8 @@ export class Signer {
13
14
  username;
14
15
  constructor(configuration) {
15
16
  const runtimeConfiguration = __getRuntimeConfig(configuration);
16
- this.credentials = runtimeConfiguration.credentials;
17
+ const creds = runtimeConfiguration.credentials;
18
+ this.credentials = typeof creds === "function" ? this.createCredentialsWrapper(creds) : creds;
17
19
  this.hostname = runtimeConfiguration.hostname;
18
20
  this.port = runtimeConfiguration.port;
19
21
  this.region = runtimeConfiguration.region;
@@ -45,4 +47,19 @@ export class Signer {
45
47
  });
46
48
  return formatUrl(presigned).replace(`${this.protocol}//`, "");
47
49
  }
50
+ createCredentialsWrapper(provider) {
51
+ return async (identityProperties) => {
52
+ const credentials = await provider(identityProperties);
53
+ if (credentials.expiration && credentials.expiration.getTime() - Date.now() < 15 * MINUTE_MS) {
54
+ try {
55
+ const refreshed = await provider({ ...identityProperties, forceRefresh: true });
56
+ if (!refreshed.expiration || refreshed.expiration.getTime() - Date.now() >= 15 * MINUTE_MS) {
57
+ return refreshed;
58
+ }
59
+ }
60
+ catch { }
61
+ }
62
+ return credentials;
63
+ };
64
+ }
48
65
  }
@@ -51,4 +51,10 @@ export declare class Signer {
51
51
  private readonly username;
52
52
  constructor(configuration: SignerConfig);
53
53
  getAuthToken(): Promise<string>;
54
+ /**
55
+ * Wraps a credential provider to force refresh when the resolved credentials
56
+ * expire within 15 minutes. A presigned URL cannot outlive the credentials
57
+ * used to sign it, so near-expiry credentials would produce a short-lived token.
58
+ */
59
+ private createCredentialsWrapper;
54
60
  }
@@ -24,4 +24,5 @@ export declare class Signer {
24
24
  private readonly username;
25
25
  constructor(configuration: SignerConfig);
26
26
  getAuthToken(): Promise<string>;
27
+ private createCredentialsWrapper;
27
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/rds-signer",
3
- "version": "3.1057.0",
3
+ "version": "3.1058.0",
4
4
  "description": "RDS utility for generating a password that can be used for IAM authentication to an RDS DB.",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -32,7 +32,7 @@
32
32
  "@aws-crypto/sha256-browser": "5.2.0",
33
33
  "@aws-crypto/sha256-js": "5.2.0",
34
34
  "@aws-sdk/core": "^3.974.15",
35
- "@aws-sdk/credential-providers": "3.1057.0",
35
+ "@aws-sdk/credential-providers": "3.1058.0",
36
36
  "@smithy/core": "^3.24.5",
37
37
  "@smithy/signature-v4": "^5.4.5",
38
38
  "@smithy/types": "^4.14.2",