@vizamodo/aws-sts-core 0.4.12 → 0.4.15
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/sts/issue.js +10 -19
- package/package.json +1 -1
package/dist/sts/issue.js
CHANGED
|
@@ -131,19 +131,11 @@ async function fetchCredentials(input) {
|
|
|
131
131
|
"X-Amz-X509": normalizedCert,
|
|
132
132
|
"Authorization": `${ALGORITHM} Credential=${certSerialDec}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signatureHex}`,
|
|
133
133
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
headers: finalHeaders,
|
|
140
|
-
body,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
console.warn("[aws-unreachable]", { region, err });
|
|
145
|
-
throw new InternalError("aws_unreachable");
|
|
146
|
-
}
|
|
134
|
+
const res = await fetch(`https://${host}${PATH}`, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: finalHeaders,
|
|
137
|
+
body,
|
|
138
|
+
});
|
|
147
139
|
if (!res.ok) {
|
|
148
140
|
console.warn("[aws-rejected]", { status: res.status, region });
|
|
149
141
|
throw new InternalError("aws_rejected");
|
|
@@ -160,14 +152,13 @@ async function fetchCredentials(input) {
|
|
|
160
152
|
sessionToken: creds.sessionToken,
|
|
161
153
|
expiration: creds.expiration,
|
|
162
154
|
};
|
|
163
|
-
|
|
164
|
-
const receivedAt = Date.now();
|
|
155
|
+
const issuedAt = Date.now();
|
|
165
156
|
const expiresAtMs = Date.parse(creds.expiration);
|
|
166
|
-
const credLifetimeSec = Math.floor((expiresAtMs -
|
|
157
|
+
const credLifetimeSec = Math.floor((expiresAtMs - issuedAt) / 1000);
|
|
167
158
|
if (Number.isFinite(expiresAtMs) && credLifetimeSec > 0) {
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
return wrapResult(value,
|
|
159
|
+
const edgeCacheTtlSec = Math.floor(credLifetimeSec / 3);
|
|
160
|
+
const edgeCacheExpiry = new Date(issuedAt + edgeCacheTtlSec * 1000).toISOString();
|
|
161
|
+
return wrapResult(value, edgeCacheExpiry);
|
|
171
162
|
}
|
|
172
163
|
return value;
|
|
173
164
|
}
|