Skip to content

Commit

Permalink
fix(core): add error metadata indicating clock skew correction
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Feb 27, 2024
1 parent e1ba507 commit aea33cb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/core/src/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts
Expand Up @@ -45,6 +45,9 @@ interface AwsSdkSigV4AuthSigningProperties {
*/
interface AwsSdkSigV4Exception extends ServiceException {
ServerTime?: string;
$metadata: ServiceException["$metadata"] & {
clockSkewCorrected?: boolean;
};
}

/**
Expand Down Expand Up @@ -104,11 +107,13 @@ export class AwsSdkSigV4Signer implements HttpSigner {
const serverTime: string | undefined =
(error as AwsSdkSigV4Exception).ServerTime ?? getDateHeader((error as AwsSdkSigV4Exception).$response);
if (serverTime) {
const config = throwSigningPropertyError(
"config",
signingProperties.config as AwsSdkSigV4Config | undefined
);
const config = throwSigningPropertyError("config", signingProperties.config as AwsSdkSigV4Config | undefined);
const initialSystemClockOffset = config.systemClockOffset;
config.systemClockOffset = getUpdatedSystemClockOffset(serverTime, config.systemClockOffset);
const clockSkewCorrected = config.systemClockOffset !== initialSystemClockOffset;
if (clockSkewCorrected) {
(error as AwsSdkSigV4Exception).$metadata.clockSkewCorrected = true;
}
}
throw error;
};
Expand All @@ -117,10 +122,7 @@ export class AwsSdkSigV4Signer implements HttpSigner {
successHandler(httpResponse: HttpResponse | unknown, signingProperties: Record<string, unknown>): void {
const dateHeader = getDateHeader(httpResponse);
if (dateHeader) {
const config = throwSigningPropertyError(
"config",
signingProperties.config as AwsSdkSigV4Config | undefined
);
const config = throwSigningPropertyError("config", signingProperties.config as AwsSdkSigV4Config | undefined);
config.systemClockOffset = getUpdatedSystemClockOffset(dateHeader, config.systemClockOffset);
}
}
Expand Down

0 comments on commit aea33cb

Please sign in to comment.