Skip to content

Commit

Permalink
Improve logger types after rebase
Browse files Browse the repository at this point in the history
Issue: ARSN-462
  • Loading branch information
williamlardier committed Mar 5, 2025
1 parent af5e4e3 commit 9925cc3
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 31 deletions.
13 changes: 6 additions & 7 deletions lib/auth/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export type AuthV2RequestParams = {
version: 2;
log: RequestLogger;
data: {
securityToken: string;
accessKey: string;
signatureFromRequest: string;
stringToSign: string;
algo: string;
authType: 'query' | 'header' | 'REST-HEADER' | 'REST-QUERY-STRING';
signatureVersion: string;
securityToken: string;
signatureAge?: number;
signatureFromRequest: string;
signatureVersion: string;
stringToSign: string;
};
};

Expand All @@ -85,7 +85,6 @@ export type AuthV4RequestParams = {
algo?: string;
authType?: 'query' | 'header' | 'REST-HEADER' | 'REST-QUERY-STRING';
credentialScope?: string;
log: RequestLogger;
region: string;
scopeDate: string;
securityToken?: string;
Expand All @@ -94,7 +93,7 @@ export type AuthV4RequestParams = {
signatureAge?: number;
signatureFromRequest: string;
stringToSign: string;
timestamp: number;
timestamp?: string;
};
};

Expand Down Expand Up @@ -141,7 +140,7 @@ export default class Vault {
*/
authenticateV2Request(
params: AuthV2RequestParams,
requestContexts: any[],
requestContexts: any[] | null,
callback: (err: Error | null, data?: any) => void
) {
params.log.debug('authenticating V2 request');
Expand Down
6 changes: 3 additions & 3 deletions lib/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from 'crypto';
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import errors, { ArsenalError } from '../errors';
import * as queryString from 'querystring';
import AuthInfo from './AuthInfo';
Expand Down Expand Up @@ -61,7 +61,7 @@ function setAuthHandler(handler: Vault) {
*/
function extractParams(
request: any,
log: Logger,
log: RequestLogger,
awsService: string,
data: { [key: string]: string }
): AuthResult<AuthV2RequestParams | AuthV4RequestParams | AuthInfo> {
Expand Down Expand Up @@ -121,7 +121,7 @@ function extractParams(
*/
function doAuth(
request: any,
log: Logger,
log: RequestLogger,
cb: (err: Error | null, data?: any) => void,
awsService: string,
requestContexts: any[] | null,
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v2/checkRequestExpiry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import errors from '../../errors';

const epochTime = new Date('1970-01-01').getTime();

export default function checkRequestExpiry(timestamp: number, log: Logger) {
export default function checkRequestExpiry(timestamp: number, log: RequestLogger) {
// If timestamp is before epochTime, the request is invalid and return
// errors.AccessDenied
if (timestamp < epochTime) {
Expand Down
6 changes: 3 additions & 3 deletions lib/auth/v2/constructStringToSign.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import utf8 from 'utf8';
import getCanonicalizedAmzHeaders from './getCanonicalizedAmzHeaders';
import getCanonicalizedResource from './getCanonicalizedResource';

export default function constructStringToSign(
request: any,
data: { [key: string]: string },
log: Logger,
clientType?: any
log: RequestLogger,
clientType?: any,
) {
/*
Build signature per AWS requirements:
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v2/headerAuthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import errors from '../../errors';
import * as constants from '../../constants';
import constructStringToSign from './constructStringToSign';
Expand All @@ -9,7 +9,7 @@ import { AuthResult } from '../auth';

export function check(
request: any,
log: Logger,
log: RequestLogger,
data: { [key: string]: string },
): AuthResult<AuthV2RequestParams> {
log.trace('running header auth check');
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v2/queryAuthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import errors from '../../errors';
import * as constants from '../../constants';
import algoCheck from './algoCheck';
Expand All @@ -12,7 +12,7 @@ export const PRE_SIGN_URL_EXPIRY = process.env.PRE_SIGN_URL_EXPIRY ?

export function check(
request: any,
log: Logger,
log: RequestLogger,
data: { [key: string]: string },
): AuthResult<AuthV2RequestParams> {
log.trace('running query auth check');
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v4/constructStringToSign.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from 'crypto';
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import createCanonicalRequest from './createCanonicalRequest';

/**
Expand All @@ -14,7 +14,7 @@ export default function constructStringToSign(params: {
credentialScope: string;
timestamp: string;
query: { [key: string]: string };
log?: Logger;
log?: RequestLogger;
proxyPath?: string;
awsService: string;
}): string {
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v4/headerAuthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import errors, { ArsenalError } from '../../../lib/errors';
import * as constants from '../../constants';
import constructStringToSign from './constructStringToSign';
Expand All @@ -25,7 +25,7 @@ import { AuthResult } from '../auth';
*/
export function check(
request: any,
log: Logger,
log: RequestLogger,
data: { [key: string]: string },
awsService: string
): AuthResult<AuthV4RequestParams> {
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v4/queryAuthCheck.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import * as constants from '../../constants';
import errors, { ArsenalError } from '../../errors';
import constructStringToSign from './constructStringToSign';
Expand All @@ -16,7 +16,7 @@ import { AuthResult } from '../auth';
*/
export function check(
request: any,
log: Logger,
log: RequestLogger,
data: { [key: string]: string },
): AuthResult<AuthV4RequestParams> {
const authParams = extractQueryParams(data, log);
Expand Down
4 changes: 2 additions & 2 deletions lib/auth/v4/timeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';

/**
* Convert timestamp to milliseconds since Unix Epoch
Expand Down Expand Up @@ -34,7 +34,7 @@ export function convertUTCtoISO8601(timestamp: string | number) {
* @param log - log for request
* @return true if there is a time problem
*/
export function checkTimeSkew(timestamp: string, expiry: number, log: Logger) {
export function checkTimeSkew(timestamp: string, expiry: number, log: RequestLogger) {
const currentTime = Date.now();
const fifteenMinutes = (15 * 60 * 1000);
const parsedTimestamp = convertAmzTimeToMs(timestamp);
Expand Down
8 changes: 4 additions & 4 deletions lib/auth/v4/validateInputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'werelogs';
import { RequestLogger } from 'werelogs';
import errors, { ArsenalError } from '../../../lib/errors';

/**
Expand All @@ -12,7 +12,7 @@ import errors, { ArsenalError } from '../../../lib/errors';
export function validateCredentials(
credentials: [string, string, string, string, string],
timestamp: string,
log: Logger
log: RequestLogger,
): ArsenalError | {} {
if (!Array.isArray(credentials) || credentials.length !== 5) {
log.warn('credentials in improper format', { credentials });
Expand Down Expand Up @@ -66,7 +66,7 @@ export function validateCredentials(
*/
export function extractQueryParams(
queryObj: { [key: string]: string | undefined },
log: Logger
log: RequestLogger,
) {
const authParams: {
signedHeaders?: string;
Expand Down Expand Up @@ -137,7 +137,7 @@ export function extractQueryParams(
* @param log - logging object
* @return object containing extracted auth header items for authV4
*/
export function extractAuthItems(authHeader: string, log: Logger) {
export function extractAuthItems(authHeader: string, log: RequestLogger) {
const authItems: {
credentialsArr?: [string, string, string, string, string];
signedHeaders?: string;
Expand Down

0 comments on commit 9925cc3

Please sign in to comment.