Skip to content

Commit 1a0af79

Browse files
fix lint
1 parent 202fda1 commit 1a0af79

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

.evergreen/run-kerberos-tests.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ set -o xtrace
2424
npm install kerberos@">=2.0.0-beta.0"
2525
npm run check:kerberos
2626

27-
if [ "$NODE_LTS_VERSION" != "latest" ] && [ $NODE_LTS_VERSION -lt 20 ]; then
28-
npm install kerberos@"^1.1.7"
29-
npm run check:kerberos
30-
fi
31-
3227
set +o xtrace
3328

3429
# destroy ticket

src/client-side-encryption/errors.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import { type Document } from '../bson';
55
* An error indicating that something went wrong specifically with MongoDB Client Encryption
66
*/
77
export class MongoCryptError extends Error {
8-
cause?: Error | string;
9-
constructor(message: string, options: { cause?: Error | string } = {}) {
10-
super(message);
11-
if (options.cause != null) {
12-
this.cause = options.cause;
13-
}
8+
constructor(message: string, options: { cause?: Error } = {}) {
9+
super(message, options);
1410
}
1511

1612
override get name() {
@@ -24,7 +20,7 @@ export class MongoCryptError extends Error {
2420
*/
2521
export class MongoCryptCreateDataKeyError extends MongoCryptError {
2622
encryptedFields: Document;
27-
constructor({encryptedFields, cause}: { encryptedFields: Document, cause: Error }) {
23+
constructor({ encryptedFields, cause }: { encryptedFields: Document; cause: Error }) {
2824
super(`Unable to complete creating data keys: ${cause.message}`, { cause });
2925
this.encryptedFields = encryptedFields;
3026
}
@@ -40,7 +36,7 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError {
4036
*/
4137
export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError {
4238
encryptedFields: Document;
43-
constructor({encryptedFields, cause}: { encryptedFields: Document, cause: Error }) {
39+
constructor({ encryptedFields, cause }: { encryptedFields: Document; cause: Error }) {
4440
super(`Unable to create collection: ${cause.message}`, { cause });
4541
this.encryptedFields = encryptedFields;
4642
}

src/client-side-encryption/providers/azure.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,61 @@ import * as utils from './utils';
66

77
const MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS = 6000;
88

9+
/**
10+
* The access token that libmongocrypt expects for Azure kms.
11+
*/
912
interface AccessToken {
1013
accessToken: string;
14+
}
15+
16+
/**
17+
* The response from the azure idms endpoint, including the `expiresOnTimestamp`.
18+
* `expiresOnTimestamp` is needed for caching.
19+
*/
20+
interface AzureTokenCacheEntry extends AccessToken {
21+
accessToken: string;
1122
expiresOnTimestamp: number;
1223
}
24+
1325
/**
1426
* @internal
1527
*/
1628
export class AzureCredentialCache {
17-
/** @internal */
18-
cachedToken: AccessToken | null = null;
29+
cachedToken: AzureTokenCacheEntry | null = null;
1930

2031
async getToken(): Promise<AccessToken> {
21-
if (this.needsRefresh(this.cachedToken)) {
32+
if (this.cachedToken == null || this.needsRefresh(this.cachedToken)) {
2233
this.cachedToken = await this._getToken();
2334
}
2435

25-
return { ...this.cachedToken! };
36+
return { accessToken: this.cachedToken.accessToken };
2637
}
2738

28-
needsRefresh(token: typeof this.cachedToken): boolean {
29-
if (token == null) {
30-
return true;
31-
}
39+
needsRefresh(token: AzureTokenCacheEntry): boolean {
3240
const timeUntilExpirationMS = token.expiresOnTimestamp - Date.now();
3341
return timeUntilExpirationMS <= MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS;
3442
}
3543

3644
/**
3745
* exposed for testing
38-
* @internal
3946
*/
4047
resetCache() {
4148
this.cachedToken = null;
4249
}
4350

4451
/**
4552
* exposed for testing
46-
* @internal
4753
*/
48-
_getToken(): Promise<typeof this.cachedToken> {
54+
_getToken(): Promise<AzureTokenCacheEntry> {
4955
return fetchAzureKMSToken();
5056
}
5157
}
5258

5359
/** @internal */
5460
export const tokenCache = new AzureCredentialCache();
5561

56-
async function parseResponse(response: { body: string; status?: number }): Promise<AccessToken> {
62+
/** @internal */
63+
async function parseResponse(response: { body: string; status?: number }): Promise<AzureTokenCacheEntry> {
5764
const { status, body: rawBody } = response;
5865

5966
const body: { expires_in?: number; access_token?: string } = (() => {
@@ -120,7 +127,7 @@ export function prepareRequest(options: AzureKMSRequestOptions): {
120127
: // The Node URL constructor technically supports "any object that converts to a valid URL string",
121128
// but Node types doesn't support this. See the Node docs for new URL().
122129
// https://nodejs.org/api/url.html#new-urlinput-base
123-
// @ts-ignore
130+
// @ts-expect-error URL constructor typings incorrect
124131
new URL(options.url);
125132

126133
url.searchParams.append('api-version', '2018-02-01');
@@ -140,7 +147,9 @@ export function prepareRequest(options: AzureKMSRequestOptions): {
140147
* exposed for CSFLE
141148
* [prose test 18](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#azure-imds-credentials)
142149
*/
143-
export async function fetchAzureKMSToken(options: AzureKMSRequestOptions = {}) {
150+
export async function fetchAzureKMSToken(
151+
options: AzureKMSRequestOptions = {}
152+
): Promise<AzureTokenCacheEntry> {
144153
const { headers, url } = prepareRequest(options);
145154
const response = await utils.get(url, { headers }).catch(error => {
146155
if (error instanceof MongoCryptKMSRequestNetworkTimeoutError) {

src/deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function getZstdLibrary(): typeof ZStandard | { kModuleError: MongoMissin
7777

7878
/**
7979
* @internal
80-
* Copy of the AwsCredentialIdentityProvider interface from [`@smithy/types`](https://socket.dev/npm/package/@smithy/types/files/1.1.1/dist-types/identity/awsCredentialIdentity.d.ts),
80+
* Copy of the AwsCredentialIdentityProvider interface from [`smithy/types`](https://socket.dev/npm/package/\@smithy/types/files/1.1.1/dist-types/identity/awsCredentialIdentity.d.ts),
8181
* the return type of the aws-sdk's `fromNodeProviderChain().provider()`.
8282
*/
8383
export interface AWSCredentials {

test/unit/client-side-encryption/requirements.helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {getGcpMetadata , getAwsCredentialProvider} from '../../../src/deps';
1+
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
2+
import { getAwsCredentialProvider, getGcpMetadata } from '../../../src/deps';
23

34
// Data Key Stuff
45
export const AWS_ACCESS_KEY_ID = process.env.AWS_ACCESS_KEY_ID;

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"moduleResolution": "node",
1010
"skipLibCheck": true,
1111
"lib": [
12-
"es2021"
12+
"es2021",
13+
"ES2022.Error"
1314
],
1415
// We don't make use of tslib helpers, all syntax used is supported by target engine
1516
"importHelpers": false,

0 commit comments

Comments
 (0)