@rushstack/rush-amazon-s3-build-cache-plugin
Advanced tools
| /// <reference types="node" /> | ||
| import * as fetch from 'node-fetch'; | ||
| import type { IRushPlugin } from '@rushstack/rush-sdk'; | ||
@@ -8,2 +7,3 @@ import { ITerminal } from '@rushstack/terminal'; | ||
| import type { RushSession } from '@rushstack/rush-sdk'; | ||
| import { WebClient } from '@rushstack/rush-sdk/lib/utilities/WebClient'; | ||
@@ -80,34 +80,4 @@ /** | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare interface IGetFetchOptions extends IWebFetchOptionsBase { | ||
| verb: 'GET' | never; | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare interface IPutFetchOptions extends IWebFetchOptionsBase { | ||
| verb: 'PUT'; | ||
| body?: Buffer; | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| declare interface IWebFetchOptionsBase { | ||
| timeoutMs?: number; | ||
| verb?: 'GET' | 'PUT'; | ||
| headers?: fetch.Headers; | ||
| } | ||
| /** | ||
| * @public | ||
| */ | ||
| declare class RushAmazonS3BuildCachePlugin implements IRushPlugin { | ||
@@ -119,35 +89,2 @@ pluginName: string; | ||
| /** | ||
| * A helper for issuing HTTP requests. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare class WebClient { | ||
| readonly standardHeaders: fetch.Headers; | ||
| accept: string | undefined; | ||
| userAgent: string | undefined; | ||
| proxy: WebClientProxy; | ||
| constructor(); | ||
| static mergeHeaders(target: fetch.Headers, source: fetch.Headers): void; | ||
| addBasicAuthHeader(userName: string, password: string): void; | ||
| fetchAsync(url: string, options?: IGetFetchOptions | IPutFetchOptions): Promise<WebClientResponse>; | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * @public | ||
| */ | ||
| declare enum WebClientProxy { | ||
| None = 0, | ||
| Detect = 1, | ||
| Fiddler = 2 | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare type WebClientResponse = fetch.Response; | ||
| export { } |
@@ -7,4 +7,4 @@ "use strict"; | ||
| const rush_sdk_1 = require("@rushstack/rush-sdk"); | ||
| const WebClient_1 = require("@rushstack/rush-sdk/lib/utilities/WebClient"); | ||
| const AmazonS3Client_1 = require("./AmazonS3Client"); | ||
| const WebClient_1 = require("./WebClient"); | ||
| const AmazonS3Credentials_1 = require("./AmazonS3Credentials"); | ||
@@ -11,0 +11,0 @@ const DEFAULT_S3_REGION = 'us-east-1'; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"AmazonS3BuildCacheProvider.js","sourceRoot":"","sources":["../src/AmazonS3BuildCacheProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAQ6B;AAE7B,qDAAkD;AAClD,2CAAwC;AACxC,+DAA8F;AA0B9F,MAAM,iBAAiB,GAAgB,WAAW,CAAC;AACnD,MAAa,0BAA0B;IASrC,IAAW,mBAAmB;;QAC5B,OAAO,MAAA,mCAAwB,CAAC,sBAAsB,mCAAI,IAAI,CAAC,mCAAmC,CAAC;IACrG,CAAC;IAID,YACE,OAA8F,EAC9F,WAAwB;QAExB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,mCAAmC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IACzE,CAAC;IAED,IAAY,WAAW;QACrB,MAAM,OAAO,GACX,IAAI,CAAC,QAAQ,CAAC;QAChB,IAAI,UAAU,IAAI,OAAO,EAAE,CAAC;YAC1B,oDAAoD;YACpD,MAAM,MAAM,GAAW,OAAO,CAAC,QAAQ,CAAC;YACxC,IAAI,OAAO,CAAC,QAAQ,KAAK,iBAAiB,EAAE,CAAC;gBAC3C,O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;QAC3D,MAAM,0BAAe,CAAC,UAAU,CAC9B;YACE,cAAc,EAAE,IAAI;SACrB,EACD,KAAK,EAAE,gBAAiC,EAAE,EAAE;YAC1C,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC3D,MAAM,gBAAgB,CAAC,mBAAmB,EAAE,CAAC;QAC/C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA9KD,gEA8KC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ITerminal } from '@rushstack/terminal';\nimport {\n type ICloudBuildCacheProvider,\n type ICredentialCacheEntry,\n CredentialCache,\n type RushSession,\n RushConstants,\n EnvironmentVariableNames,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\n\nimport { AmazonS3Client } from './AmazonS3Client';\nimport { WebClient } from './WebClient';\nimport { type IAmazonS3Credentials, fromAmazonEnv, fromRushEnv } from './AmazonS3Credentials';\n\n/**\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsBase {\n s3Region: string;\n s3Prefix: string | undefined;\n isCacheWriteAllowed: boolean;\n}\n\n/**\n * Advanced options where user has the specify the full http endpoint\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsAdvanced extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Endpoint: string;\n}\n/**\n * Simple options where user only provides the bucket and the endpoint is automatically built\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsSimple extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Bucket: string;\n}\n\nconst DEFAULT_S3_REGION: 'us-east-1' = 'us-east-1';\nexport class AmazonS3BuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _options:\n | IAmazonS3BuildCacheProviderOptionsSimple\n | IAmazonS3BuildCacheProviderOptionsAdvanced;\n private readonly _s3Prefix: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private __credentialCacheId: string | undefined;\n private _rushSession: RushSession;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n private __s3Client: AmazonS3Client | undefined;\n\n public constructor(\n options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced,\n rushSession: RushSession\n ) {\n this._rushSession = rushSession;\n this._options = options;\n this._s3Prefix = options.s3Prefix;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n }\n\n private get _s3Endpoint(): string {\n const options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced =\n this._options;\n if ('s3Bucket' in options) {\n // options: IAmazonS3BuildCacheProviderOptionsSimple\n const bucket: string = options.s3Bucket;\n if (options.s3Region === DEFAULT_S3_REGION) {\n return `https://${bucket}.s3.amazonaws.com`;\n } else {\n return `https://${bucket}.s3-${options.s3Region}.amazonaws.com`;\n }\n }\n // options: IAmazonS3BuildCacheProviderOptionsAdvanced\n return options.s3Endpoint;\n }\n\n private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = ['aws-s3', this._options.s3Region, this._s3Endpoint];\n\n if (this._isCacheWriteAllowedByConfiguration) {\n cacheIdParts.push('cacheWriteAllowed');\n }\n\n this.__credentialCacheId = cacheIdParts.join('|');\n }\n\n return this.__credentialCacheId;\n }\n\n private async _getS3ClientAsync(terminal: ITerminal): Promise<AmazonS3Client> {\n if (!this.__s3Client) {\n let credentials: IAmazonS3Credentials | undefined = fromRushEnv() ?? fromAmazonEnv();\n\n if (!credentials) {\n terminal.writeDebugLine('No credentials found in env. Trying cloud credentials.');\n\n let cacheEntry: ICredentialCacheEntry | undefined;\n await CredentialCache.usingAsync(\n {\n supportEditing: false\n },\n (credentialsCache: CredentialCache) => {\n cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);\n }\n );\n\n if (cacheEntry) {\n const expirationTime: number | undefined = cacheEntry.expires?.getTime();\n if (expirationTime && expirationTime < Date.now()) {\n throw new Error(\n 'Cached Amazon S3 credentials have expired. ' +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\".`\n );\n } else {\n credentials = fromRushEnv(cacheEntry?.credential);\n }\n } else if (this._isCacheWriteAllowedByConfiguration) {\n throw new Error(\n \"An Amazon S3 credential hasn't been provided, or has expired. \" +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\", ` +\n `or provide an <AccessKeyId>:<SecretAccessKey> pair in the ` +\n `${EnvironmentVariableNames.RUSH_BUILD_CACHE_CREDENTIAL} environment variable`\n );\n }\n }\n\n this.__s3Client = new AmazonS3Client(\n credentials,\n {\n ...this._options,\n // advanced options\n s3Endpoint: this._s3Endpoint\n },\n new WebClient(),\n terminal\n );\n }\n\n return this.__s3Client;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n return await client.getObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId);\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry from S3: ${e}`);\n return undefined;\n }\n }\n\n public async trySetCacheEntryBufferAsync(\n terminal: ITerminal,\n cacheId: string,\n objectBuffer: Buffer\n ): Promise<boolean> {\n if (!this.isCacheWriteAllowed) {\n terminal.writeErrorLine('Writing to S3 cache is not allowed in the current configuration.');\n return false;\n }\n\n terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);\n\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n await client.uploadObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId, objectBuffer);\n return true;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry to S3: ${e}`);\n return false;\n }\n }\n\n public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.setCacheEntry(this._credentialCacheId, { credential });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n throw new Error(\n 'The interactive cloud credentials flow is not supported for Amazon S3.\\n' +\n 'Provide your credentials to rush using the --credential flag instead. Credentials must be ' +\n 'in the form of <ACCESS KEY ID>:<SECRET ACCESS KEY> or ' +\n '<ACCESS KEY ID>:<SECRET ACCESS KEY>:<SESSION TOKEN>.'\n );\n }\n\n public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.deleteCacheEntry(this._credentialCacheId);\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n}\n"]} | ||
| {"version":3,"file":"AmazonS3BuildCacheProvider.js","sourceRoot":"","sources":["../src/AmazonS3BuildCacheProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAQ6B;AAC7B,2EAAwE;AAExE,qDAAkD;AAClD,+DAA8F;AA0B9F,MAAM,iBAAiB,GAAgB,WAAW,CAAC;AACnD,MAAa,0BAA0B;IASrC,IAAW,mBAAmB;;QAC5B,OAAO,MAAA,mCAAwB,CAAC,sBAAsB,mCAAI,IAAI,CAAC,mCAAmC,CAAC;IACrG,CAAC;IAID,YACE,OAA8F,EAC9F,WAAwB;QAExB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,mCAAmC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IACzE,CAAC;IAED,IAAY,WAAW;QACrB,MAAM,OAAO,GACX,IAAI,CAAC,QAAQ,CAAC;Q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,CAAC,sCAAsC,CAAC,QAAmB;QACrE,MAAM,IAAI,KAAK,CACb,0EAA0E;YACxE,4FAA4F;YAC5F,wDAAwD;YACxD,sDAAsD,CACzD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,4BAA4B,CAAC,QAAmB;QAC3D,MAAM,0BAAe,CAAC,UAAU,CAC9B;YACE,cAAc,EAAE,IAAI;SACrB,EACD,KAAK,EAAE,gBAAiC,EAAE,EAAE;YAC1C,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC3D,MAAM,gBAAgB,CAAC,mBAAmB,EAAE,CAAC;QAC/C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AA9KD,gEA8KC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ITerminal } from '@rushstack/terminal';\nimport {\n type ICloudBuildCacheProvider,\n type ICredentialCacheEntry,\n CredentialCache,\n type RushSession,\n RushConstants,\n EnvironmentVariableNames,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\nimport { WebClient } from '@rushstack/rush-sdk/lib/utilities/WebClient';\n\nimport { AmazonS3Client } from './AmazonS3Client';\nimport { type IAmazonS3Credentials, fromAmazonEnv, fromRushEnv } from './AmazonS3Credentials';\n\n/**\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsBase {\n s3Region: string;\n s3Prefix: string | undefined;\n isCacheWriteAllowed: boolean;\n}\n\n/**\n * Advanced options where user has the specify the full http endpoint\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsAdvanced extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Endpoint: string;\n}\n/**\n * Simple options where user only provides the bucket and the endpoint is automatically built\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsSimple extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Bucket: string;\n}\n\nconst DEFAULT_S3_REGION: 'us-east-1' = 'us-east-1';\nexport class AmazonS3BuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _options:\n | IAmazonS3BuildCacheProviderOptionsSimple\n | IAmazonS3BuildCacheProviderOptionsAdvanced;\n private readonly _s3Prefix: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private __credentialCacheId: string | undefined;\n private _rushSession: RushSession;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n private __s3Client: AmazonS3Client | undefined;\n\n public constructor(\n options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced,\n rushSession: RushSession\n ) {\n this._rushSession = rushSession;\n this._options = options;\n this._s3Prefix = options.s3Prefix;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n }\n\n private get _s3Endpoint(): string {\n const options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced =\n this._options;\n if ('s3Bucket' in options) {\n // options: IAmazonS3BuildCacheProviderOptionsSimple\n const bucket: string = options.s3Bucket;\n if (options.s3Region === DEFAULT_S3_REGION) {\n return `https://${bucket}.s3.amazonaws.com`;\n } else {\n return `https://${bucket}.s3-${options.s3Region}.amazonaws.com`;\n }\n }\n // options: IAmazonS3BuildCacheProviderOptionsAdvanced\n return options.s3Endpoint;\n }\n\n private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = ['aws-s3', this._options.s3Region, this._s3Endpoint];\n\n if (this._isCacheWriteAllowedByConfiguration) {\n cacheIdParts.push('cacheWriteAllowed');\n }\n\n this.__credentialCacheId = cacheIdParts.join('|');\n }\n\n return this.__credentialCacheId;\n }\n\n private async _getS3ClientAsync(terminal: ITerminal): Promise<AmazonS3Client> {\n if (!this.__s3Client) {\n let credentials: IAmazonS3Credentials | undefined = fromRushEnv() ?? fromAmazonEnv();\n\n if (!credentials) {\n terminal.writeDebugLine('No credentials found in env. Trying cloud credentials.');\n\n let cacheEntry: ICredentialCacheEntry | undefined;\n await CredentialCache.usingAsync(\n {\n supportEditing: false\n },\n (credentialsCache: CredentialCache) => {\n cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);\n }\n );\n\n if (cacheEntry) {\n const expirationTime: number | undefined = cacheEntry.expires?.getTime();\n if (expirationTime && expirationTime < Date.now()) {\n throw new Error(\n 'Cached Amazon S3 credentials have expired. ' +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\".`\n );\n } else {\n credentials = fromRushEnv(cacheEntry?.credential);\n }\n } else if (this._isCacheWriteAllowedByConfiguration) {\n throw new Error(\n \"An Amazon S3 credential hasn't been provided, or has expired. \" +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\", ` +\n `or provide an <AccessKeyId>:<SecretAccessKey> pair in the ` +\n `${EnvironmentVariableNames.RUSH_BUILD_CACHE_CREDENTIAL} environment variable`\n );\n }\n }\n\n this.__s3Client = new AmazonS3Client(\n credentials,\n {\n ...this._options,\n // advanced options\n s3Endpoint: this._s3Endpoint\n },\n new WebClient(),\n terminal\n );\n }\n\n return this.__s3Client;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n return await client.getObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId);\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry from S3: ${e}`);\n return undefined;\n }\n }\n\n public async trySetCacheEntryBufferAsync(\n terminal: ITerminal,\n cacheId: string,\n objectBuffer: Buffer\n ): Promise<boolean> {\n if (!this.isCacheWriteAllowed) {\n terminal.writeErrorLine('Writing to S3 cache is not allowed in the current configuration.');\n return false;\n }\n\n terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);\n\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n await client.uploadObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId, objectBuffer);\n return true;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry to S3: ${e}`);\n return false;\n }\n }\n\n public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.setCacheEntry(this._credentialCacheId, { credential });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n throw new Error(\n 'The interactive cloud credentials flow is not supported for Amazon S3.\\n' +\n 'Provide your credentials to rush using the --credential flag instead. Credentials must be ' +\n 'in the form of <ACCESS KEY ID>:<SECRET ACCESS KEY> or ' +\n '<ACCESS KEY ID>:<SECRET ACCESS KEY>:<SESSION TOKEN>.'\n );\n }\n\n public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.deleteCacheEntry(this._credentialCacheId);\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n}\n"]} |
| /// <reference types="node" /> | ||
| import { type ITerminal } from '@rushstack/terminal'; | ||
| import { type WebClient } from '@rushstack/rush-sdk/lib/utilities/WebClient'; | ||
| import type { IAmazonS3BuildCacheProviderOptionsAdvanced } from './AmazonS3BuildCacheProvider'; | ||
| import type { WebClient } from './WebClient'; | ||
| import { type IAmazonS3Credentials } from './AmazonS3Credentials'; | ||
@@ -6,0 +6,0 @@ /** |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"AmazonS3Client.d.ts","sourceRoot":"","sources":["../src/AmazonS3Client.ts"],"names":[],"mappings":";AAIA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAI/D,OAAO,KAAK,EAAE,0CAA0C,EAAE,MAAM,8BAA8B,CAA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;IAWlF,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,iBAAiB;YAaX,0BAA0B;YAS1B,gBAAgB;IAS9B;;;OAGG;IACH,OAAO,CAAC,iBAAiB;YAuDX,iCAAiC;CA2ChD"} |
@@ -32,3 +32,3 @@ "use strict"; | ||
| const crypto = __importStar(require("crypto")); | ||
| const fetch = __importStar(require("node-fetch")); | ||
| const WebClient_1 = require("@rushstack/rush-sdk/lib/utilities/WebClient"); | ||
| const AmazonS3Credentials_1 = require("./AmazonS3Credentials"); | ||
@@ -167,3 +167,3 @@ const CONTENT_HASH_HEADER_NAME = 'x-amz-content-sha256'; | ||
| const bodyHash = this._getSha256(body); | ||
| const headers = new fetch.Headers(); | ||
| const headers = new WebClient_1.WebClientHeaders(); | ||
| headers.set(DATE_HEADER_NAME, isoDateString.dateTime); | ||
@@ -170,0 +170,0 @@ headers.set(CONTENT_HASH_HEADER_NAME, bodyHash); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"AmazonS3Client.js","sourceRoot":"","sources":["../src/AmazonS3Client.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAAqD;AACrD,kDAA+D;AAC/D,+CAAiC;AACjC,kDAAoC;AAIpC,+DAA+E;AAE/E,MAAM,wBAAwB,GAA2B,sBAAsB,CAAC;AAChF,MAAM,gBAAgB,GAAiB,YAAY,CAAC;AACpD,MAAM,gBAAgB,GAAW,MAAM,CAAC;AACxC,MAAM,0BAA0B,GAA2B,sBAAsB,CAAC;AAiBlF,MAAM,aAAa,GAAW,cAAc,CAAC;AAC7C,MAAM,SAAS,GAAW,aAAa,CAAC;AAExC,+HAA+H;AAC/H,IAAK,sBAGJ;AAHD,WAAK,sBAAsB;IACzB,iFAAe,CAAA;IACf,qEAAS,CAAA;AACX,CAAC,EAHI,sBAAsB,KAAtB,sBAAsB,QAG1B;AAUD,MAAM,mBAAmB,GAAyB;IAChD,iBAAi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AAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;wBACjC,CAAC;6BAAM,CAAC;4BACN,GAAG,CAAC,+DAA+D,CAAC,CAAC;4BACrE,MAAM,aAAa,CAAC,KAAK,CAAC;wBAC5B,CAAC;oBACH,CAAC;oBAED,OAAO,aAAa,CAAC,QAAQ,CAAC;gBAChC,CAAC;gBACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACN,GAAG,CAAC,iEAAiE,CAAC,CAAC;gBACvE,MAAM,QAAQ,CAAC,KAAK,CAAC;YACvB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;CACF;AA5ZD,wCA4ZC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { Async } from '@rushstack/node-core-library';\nimport { Colorize, type ITerminal } from '@rushstack/terminal';\nimport * as crypto from 'crypto';\nimport * as fetch from 'node-fetch';\n\nimport type { IAmazonS3BuildCacheProviderOptionsAdvanced } from './AmazonS3BuildCacheProvider';\nimport type { IGetFetchOptions, IPutFetchOptions, WebClient } from './WebClient';\nimport { type IAmazonS3Credentials, fromRushEnv } from './AmazonS3Credentials';\n\nconst CONTENT_HASH_HEADER_NAME: 'x-amz-content-sha256' = 'x-amz-content-sha256';\nconst DATE_HEADER_NAME: 'x-amz-date' = 'x-amz-date';\nconst HOST_HEADER_NAME: 'host' = 'host';\nconst SECURITY_TOKEN_HEADER_NAME: 'x-amz-security-token' = 'x-amz-security-token';\n\ninterface IIsoDateString {\n date: string;\n dateTime: string;\n}\n\ntype RetryableRequestResponse<T> =\n | {\n hasNetworkError: true;\n error: Error;\n }\n | {\n hasNetworkError: false;\n response: T;\n };\n\nconst protocolRegex: RegExp = /^https?:\\/\\//;\nconst portRegex: RegExp = /:(\\d{1,5})$/;\n\n// Similar to https://docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/storageretrypolicytype?view=azure-node-latest\nenum StorageRetryPolicyType {\n EXPONENTIAL = 0,\n FIXED = 1\n}\n\n// Similar to https://docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/storageretryoptions?view=azure-node-latest\ninterface IStorageRetryOptions {\n maxRetryDelayInMs: number;\n maxTries: number;\n retryDelayInMs: number;\n retryPolicyType: StorageRetryPolicyType;\n}\n\nconst storageRetryOptions: IStorageRetryOptions = {\n maxRetryDelayInMs: 120 * 1000,\n maxTries: 4,\n retryDelayInMs: 4 * 1000,\n retryPolicyType: StorageRetryPolicyType.EXPONENTIAL\n};\n\n/**\n * A helper for reading and updating objects on Amazon S3\n *\n * @public\n */\nexport class AmazonS3Client {\n private readonly _credentials: IAmazonS3Credentials | undefined;\n private readonly _s3Endpoint: string;\n private readonly _s3Region: string;\n\n private readonly _webClient: WebClient;\n\n private readonly _terminal: ITerminal;\n\n public constructor(\n credentials: IAmazonS3Credentials | undefined,\n options: IAmazonS3BuildCacheProviderOptionsAdvanced,\n webClient: WebClient,\n terminal: ITerminal\n ) {\n this._credentials = credentials;\n this._terminal = terminal;\n\n this._validateEndpoint(options.s3Endpoint);\n\n this._s3Endpoint = options.s3Endpoint;\n this._s3Region = options.s3Region;\n\n this._webClient = webClient;\n }\n\n // https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html#create-signature-presign-entire-payload\n // We want to keep all slashes non encoded\n public static UriEncode(input: string): string {\n let output: string = '';\n for (let i: number = 0; i < input.length; i += 1) {\n const ch: string = input[i];\n if (ch.match(/[A-Za-z0-9~._-]|\\//)) {\n output += ch;\n } else {\n if (ch === ' ') {\n output += '%20';\n } else {\n output += `%${ch.charCodeAt(0).toString(16).toUpperCase()}`;\n }\n }\n }\n return output;\n }\n\n public static tryDeserializeCredentials(\n credentialString: string | undefined\n ): IAmazonS3Credentials | undefined {\n return fromRushEnv(credentialString);\n }\n\n public async getObjectAsync(objectName: string): Promise<Buffer | undefined> {\n this._writeDebugLine('Reading object from S3');\n return await this._sendCacheRequestWithRetriesAsync(async () => {\n const response: fetch.Response = await this._makeRequestAsync('GET', objectName);\n if (response.ok) {\n return {\n hasNetworkError: false,\n response: await response.buffer()\n };\n } else if (response.status === 404) {\n return {\n hasNetworkError: false,\n response: undefined\n };\n } else if (\n (response.status === 400 || response.status === 401 || response.status === 403) &&\n !this._credentials\n ) {\n // unauthorized due to not providing credentials,\n // silence error for better DX when e.g. running locally without credentials\n this._writeWarningLine(\n `No credentials found and received a ${response.status}`,\n ' response code from the cloud storage.',\n ' Maybe run rush update-cloud-credentials',\n ' or set the RUSH_BUILD_CACHE_CREDENTIAL env'\n );\n return {\n hasNetworkError: false,\n response: undefined\n };\n } else if (response.status === 400 || response.status === 401 || response.status === 403) {\n throw await this._getS3ErrorAsync(response);\n } else {\n const error: Error = await this._getS3ErrorAsync(response);\n return {\n hasNetworkError: true,\n error\n };\n }\n });\n }\n\n public async uploadObjectAsync(objectName: string, objectBuffer: Buffer): Promise<void> {\n if (!this._credentials) {\n throw new Error('Credentials are required to upload objects to S3.');\n }\n\n await this._sendCacheRequestWithRetriesAsync(async () => {\n const response: fetch.Response = await this._makeRequestAsync('PUT', objectName, objectBuffer);\n if (!response.ok) {\n return {\n hasNetworkError: true,\n error: await this._getS3ErrorAsync(response)\n };\n }\n return {\n hasNetworkError: false,\n response: undefined\n };\n });\n }\n\n private _writeDebugLine(...messageParts: string[]): void {\n // if the terminal has been closed then don't bother sending a debug message\n try {\n this._terminal.writeDebugLine(...messageParts);\n } catch (err) {\n // ignore error\n }\n }\n\n private _writeWarningLine(...messageParts: string[]): void {\n // if the terminal has been closed then don't bother sending a warning message\n try {\n this._terminal.writeWarningLine(...messageParts);\n } catch (err) {\n // ignore error\n }\n }\n\n private async _makeRequestAsync(\n verb: 'GET' | 'PUT',\n objectName: string,\n body?: Buffer\n ): Promise<fetch.Response> {\n const isoDateString: IIsoDateString = this._getIsoDateString();\n const bodyHash: string = this._getSha256(body);\n const headers: fetch.Headers = new fetch.Headers();\n headers.set(DATE_HEADER_NAME, isoDateString.dateTime);\n headers.set(CONTENT_HASH_HEADER_NAME, bodyHash);\n\n // the host can be e.g. https://s3.aws.com or http://localhost:9000\n const host: string = this._s3Endpoint.replace(protocolRegex, '');\n const canonicalUri: string = AmazonS3Client.UriEncode(`/${objectName}`);\n this._writeDebugLine(Colorize.bold('Canonical URI: '), canonicalUri);\n\n if (this._credentials) {\n // Compute the authorization header. See https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html\n const canonicalHeaders: string[] = [\n `${HOST_HEADER_NAME}:${host}`,\n `${CONTENT_HASH_HEADER_NAME}:${bodyHash}`,\n `${DATE_HEADER_NAME}:${isoDateString.dateTime}`\n ];\n\n // Handle signing with temporary credentials (via sts:assume-role)\n if (this._credentials.sessionToken) {\n canonicalHeaders.push(`${SECURITY_TOKEN_HEADER_NAME}:${this._credentials.sessionToken}`);\n }\n\n // the canonical headers must be sorted by header name\n canonicalHeaders.sort((aHeader, bHeader) => {\n const aHeaderName: string = aHeader.split(':')[0];\n const bHeaderName: string = bHeader.split(':')[0];\n if (aHeaderName < bHeaderName) {\n return -1;\n }\n if (aHeaderName > bHeaderName) {\n return 1;\n }\n return 0;\n });\n\n // the singed header names are derived from the canonicalHeaders\n const signedHeaderNamesString: string = canonicalHeaders\n .map((header) => {\n const headerName: string = header.split(':')[0];\n return headerName;\n })\n .join(';');\n\n // The canonical request looks like this:\n // GET\n // /test.txt\n //\n // host:examplebucket.s3.amazonaws.com\n // range:bytes=0-9\n // x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n // x-amz-date:20130524T000000Z\n //\n // host;range;x-amz-content-sha256;x-amz-date\n // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n const canonicalRequest: string = [\n verb,\n canonicalUri,\n '', // we don't use query strings for these requests\n ...canonicalHeaders,\n '',\n signedHeaderNamesString,\n bodyHash\n ].join('\\n');\n const canonicalRequestHash: string = this._getSha256(canonicalRequest);\n\n const scope: string = `${isoDateString.date}/${this._s3Region}/s3/aws4_request`;\n // The string to sign looks like this:\n // AWS4-HMAC-SHA256\n // 20130524T423589Z\n // 20130524/us-east-1/s3/aws4_request\n // 7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972\n const stringToSign: string = [\n 'AWS4-HMAC-SHA256',\n isoDateString.dateTime,\n scope,\n canonicalRequestHash\n ].join('\\n');\n\n const dateKey: Buffer = this._getSha256Hmac(\n `AWS4${this._credentials.secretAccessKey}`,\n isoDateString.date\n );\n const dateRegionKey: Buffer = this._getSha256Hmac(dateKey, this._s3Region);\n const dateRegionServiceKey: Buffer = this._getSha256Hmac(dateRegionKey, 's3');\n const signingKey: Buffer = this._getSha256Hmac(dateRegionServiceKey, 'aws4_request');\n const signature: string = this._getSha256Hmac(signingKey, stringToSign, 'hex');\n\n const authorizationHeader: string = `AWS4-HMAC-SHA256 Credential=${this._credentials.accessKeyId}/${scope},SignedHeaders=${signedHeaderNamesString},Signature=${signature}`;\n\n headers.set('Authorization', authorizationHeader);\n if (this._credentials.sessionToken) {\n // Handle signing with temporary credentials (via sts:assume-role)\n headers.set('X-Amz-Security-Token', this._credentials.sessionToken);\n }\n }\n\n const webFetchOptions: IGetFetchOptions | IPutFetchOptions = {\n verb,\n headers\n };\n if (verb === 'PUT') {\n (webFetchOptions as IPutFetchOptions).body = body;\n }\n\n const url: string = `${this._s3Endpoint}${canonicalUri}`;\n\n this._writeDebugLine(Colorize.bold(Colorize.underline('Sending request to S3')));\n this._writeDebugLine(Colorize.bold('HOST: '), url);\n this._writeDebugLine(Colorize.bold('Headers: '));\n headers.forEach((value, name) => {\n this._writeDebugLine(Colorize.cyan(`\\t${name}: ${value}`));\n });\n\n const response: fetch.Response = await this._webClient.fetchAsync(url, webFetchOptions);\n\n return response;\n }\n\n public _getSha256Hmac(key: string | Buffer, data: string): Buffer;\n public _getSha256Hmac(key: string | Buffer, data: string, encoding: 'hex'): string;\n public _getSha256Hmac(key: string | Buffer, data: string, encoding?: 'hex'): Buffer | string {\n const hash: crypto.Hmac = crypto.createHmac('sha256', key);\n hash.update(data);\n if (encoding) {\n return hash.digest(encoding);\n } else {\n return hash.digest();\n }\n }\n\n private _getSha256(data?: string | Buffer): string {\n if (data) {\n const hash: crypto.Hash = crypto.createHash('sha256');\n hash.update(data);\n return hash.digest('hex');\n } else {\n // This is the null SHA256 hash\n return 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';\n }\n }\n\n private _getIsoDateString(date: Date = new Date()): IIsoDateString {\n let dateString: string = date.toISOString();\n dateString = dateString.replace(/[-:]/g, ''); // Remove separator characters\n dateString = dateString.substring(0, 15); // Drop milliseconds\n\n // dateTime is an ISO8601 date. It looks like \"20130524T423589\"\n // date is an ISO date. It looks like \"20130524\"\n return {\n dateTime: `${dateString}Z`,\n date: dateString.substring(0, 8)\n };\n }\n\n private async _safeReadResponseTextAsync(response: fetch.Response): Promise<string | undefined> {\n try {\n return await response.text();\n } catch (err) {\n // ignore the error\n }\n return undefined;\n }\n\n private async _getS3ErrorAsync(response: fetch.Response): Promise<Error> {\n const text: string | undefined = await this._safeReadResponseTextAsync(response);\n return new Error(\n `Amazon S3 responded with status code ${response.status} (${response.statusText})${\n text ? `\\n${text}` : ''\n }`\n );\n }\n\n /**\n * Validates a S3 endpoint which is http(s):// + hostname + port. Hostname validated according to RFC 1123\n * {@link https://docs.aws.amazon.com/general/latest/gr/s3.html}\n */\n private _validateEndpoint(s3Endpoint: string): void {\n let host: string = s3Endpoint;\n\n if (!s3Endpoint) {\n throw new Error('A S3 endpoint must be provided');\n }\n\n if (!s3Endpoint.match(protocolRegex)) {\n throw new Error('The S3 endpoint must start with https:// or http://');\n }\n\n host = host.replace(protocolRegex, '');\n\n if (host.match(/\\//)) {\n throw new Error('The path should be omitted from the endpoint. Use s3Prefix to specify a path');\n }\n\n const portMatch: RegExpMatchArray | null = s3Endpoint.match(portRegex);\n if (portMatch) {\n const port: number = Number(portMatch[1]);\n if (Number.isNaN(port) || port > 65535) {\n throw new Error(`Port: ${port} is an invalid port number`);\n }\n host = host.replace(portRegex, '');\n }\n\n if (host.endsWith('.')) {\n host = host.slice(0, host.length - 1);\n }\n\n if (host.length > 253) {\n throw new Error(\n 'The S3 endpoint is too long. RFC 1123 specifies a hostname should be no longer than 253 characters.'\n );\n }\n\n const subDomains: string[] = host.split('.');\n\n const subDomainRegex: RegExp = /^[a-zA-Z0-9-]+$/;\n const isValid: boolean = subDomains.every((subDomain) => {\n return (\n subDomainRegex.test(subDomain) &&\n subDomain.length < 64 &&\n !subDomain.startsWith('-') &&\n !subDomain.endsWith('-')\n );\n });\n\n if (!isValid) {\n throw new Error(\n 'Invalid S3 endpoint. Some part of the hostname contains invalid characters or is too long'\n );\n }\n }\n\n private async _sendCacheRequestWithRetriesAsync<T>(\n sendRequest: () => Promise<RetryableRequestResponse<T>>\n ): Promise<T> {\n const response: RetryableRequestResponse<T> = await sendRequest();\n\n const log: (...messageParts: string[]) => void = this._writeDebugLine.bind(this);\n\n if (response.hasNetworkError) {\n if (storageRetryOptions && storageRetryOptions.maxTries > 1) {\n log('Network request failed. Will retry request as specified in storageRetryOptions');\n async function retry(retryAttempt: number): Promise<T> {\n const { retryDelayInMs, retryPolicyType, maxTries, maxRetryDelayInMs } = storageRetryOptions;\n let delay: number = retryDelayInMs;\n if (retryPolicyType === StorageRetryPolicyType.EXPONENTIAL) {\n delay = retryDelayInMs * Math.pow(2, retryAttempt - 1);\n }\n delay = Math.min(maxRetryDelayInMs, delay);\n\n log(`Will retry request in ${delay}s...`);\n await Async.sleepAsync(delay);\n const retryResponse: RetryableRequestResponse<T> = await sendRequest();\n\n if (retryResponse.hasNetworkError) {\n if (retryAttempt < maxTries - 1) {\n log('The retried request failed, will try again');\n return retry(retryAttempt + 1);\n } else {\n log('The retried request failed and has reached the maxTries limit');\n throw retryResponse.error;\n }\n }\n\n return retryResponse.response;\n }\n return retry(1);\n } else {\n log('Network request failed and storageRetryOptions is not specified');\n throw response.error;\n }\n }\n\n return response.response;\n }\n}\n"]} | ||
| {"version":3,"file":"AmazonS3Client.js","sourceRoot":"","sources":["../src/AmazonS3Client.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAAqD;AACrD,kDAA+D;AAC/D,+CAAiC;AACjC,2EAMqD;AAGrD,+DAA+E;AAE/E,MAAM,wBAAwB,GAA2B,sBAAsB,CAAC;AAChF,MAAM,gBAAgB,GAAiB,YAAY,CAAC;AACpD,MAAM,gBAAgB,GAAW,MAAM,CAAC;AACxC,MAAM,0BAA0B,GAA2B,sBAAsB,CAAC;AAiBlF,MAAM,aAAa,GAAW,cAAc,CAAC;AAC7C,MAAM,SAAS,GAAW,aAAa,CAAC;AAExC,+HAA+H;AAC/H,IAAK,sBAGJ;AAHD,WAAK,sBAAsB;IACzB,iFAAe,CAAA;IACf,qEAAS,CAAA;AACX,CAAC,EAHI,sBAAsB,KAAtB,sBAAsB,QAG1B;AAUD,MAAM,mBAAmB,GAAyB;IAChD,iBAAiB,EAAE,GAAG,GAAG,IAAI;IAC7B,QAAQ,EAAE,CAAC;IACX,cAAc,EAAE,CAAC,GAAG,IAAI;IACxB,eAAe,EAAE,sBAAsB,CAAC,WAAW;CACpD,CAAC;AAEF;;;;GAIG;AACH,MAAa,cAAc;IASzB,YACE,WAA6C,EAC7C,OAAmD,EACnD,SAAoB,EACpB,QAAmB;QAEnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAE1B,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAE3C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;QAElC,IAAI,CAA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LICENSE in the project root for license information.\n\nimport { Async } from '@rushstack/node-core-library';\nimport { Colorize, type ITerminal } from '@rushstack/terminal';\nimport * as crypto from 'crypto';\nimport {\n type IGetFetchOptions,\n type IFetchOptionsWithBody,\n type WebClientResponse,\n type WebClient,\n WebClientHeaders\n} from '@rushstack/rush-sdk/lib/utilities/WebClient';\n\nimport type { IAmazonS3BuildCacheProviderOptionsAdvanced } from './AmazonS3BuildCacheProvider';\nimport { type IAmazonS3Credentials, fromRushEnv } from './AmazonS3Credentials';\n\nconst CONTENT_HASH_HEADER_NAME: 'x-amz-content-sha256' = 'x-amz-content-sha256';\nconst DATE_HEADER_NAME: 'x-amz-date' = 'x-amz-date';\nconst HOST_HEADER_NAME: 'host' = 'host';\nconst SECURITY_TOKEN_HEADER_NAME: 'x-amz-security-token' = 'x-amz-security-token';\n\ninterface IIsoDateString {\n date: string;\n dateTime: string;\n}\n\ntype RetryableRequestResponse<T> =\n | {\n hasNetworkError: true;\n error: Error;\n }\n | {\n hasNetworkError: false;\n response: T;\n };\n\nconst protocolRegex: RegExp = /^https?:\\/\\//;\nconst portRegex: RegExp = /:(\\d{1,5})$/;\n\n// Similar to https://docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/storageretrypolicytype?view=azure-node-latest\nenum StorageRetryPolicyType {\n EXPONENTIAL = 0,\n FIXED = 1\n}\n\n// Similar to https://docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/storageretryoptions?view=azure-node-latest\ninterface IStorageRetryOptions {\n maxRetryDelayInMs: number;\n maxTries: number;\n retryDelayInMs: number;\n retryPolicyType: StorageRetryPolicyType;\n}\n\nconst storageRetryOptions: IStorageRetryOptions = {\n maxRetryDelayInMs: 120 * 1000,\n maxTries: 4,\n retryDelayInMs: 4 * 1000,\n retryPolicyType: StorageRetryPolicyType.EXPONENTIAL\n};\n\n/**\n * A helper for reading and updating objects on Amazon S3\n *\n * @public\n */\nexport class AmazonS3Client {\n private readonly _credentials: IAmazonS3Credentials | undefined;\n private readonly _s3Endpoint: string;\n private readonly _s3Region: string;\n\n private readonly _webClient: WebClient;\n\n private readonly _terminal: ITerminal;\n\n public constructor(\n credentials: IAmazonS3Credentials | undefined,\n options: IAmazonS3BuildCacheProviderOptionsAdvanced,\n webClient: WebClient,\n terminal: ITerminal\n ) {\n this._credentials = credentials;\n this._terminal = terminal;\n\n this._validateEndpoint(options.s3Endpoint);\n\n this._s3Endpoint = options.s3Endpoint;\n this._s3Region = options.s3Region;\n\n this._webClient = webClient;\n }\n\n // https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html#create-signature-presign-entire-payload\n // We want to keep all slashes non encoded\n public static UriEncode(input: string): string {\n let output: string = '';\n for (let i: number = 0; i < input.length; i += 1) {\n const ch: string = input[i];\n if (ch.match(/[A-Za-z0-9~._-]|\\//)) {\n output += ch;\n } else {\n if (ch === ' ') {\n output += '%20';\n } else {\n output += `%${ch.charCodeAt(0).toString(16).toUpperCase()}`;\n }\n }\n }\n return output;\n }\n\n public static tryDeserializeCredentials(\n credentialString: string | undefined\n ): IAmazonS3Credentials | undefined {\n return fromRushEnv(credentialString);\n }\n\n public async getObjectAsync(objectName: string): Promise<Buffer | undefined> {\n this._writeDebugLine('Reading object from S3');\n return await this._sendCacheRequestWithRetriesAsync(async () => {\n const response: WebClientResponse = await this._makeRequestAsync('GET', objectName);\n if (response.ok) {\n return {\n hasNetworkError: false,\n response: await response.buffer()\n };\n } else if (response.status === 404) {\n return {\n hasNetworkError: false,\n response: undefined\n };\n } else if (\n (response.status === 400 || response.status === 401 || response.status === 403) &&\n !this._credentials\n ) {\n // unauthorized due to not providing credentials,\n // silence error for better DX when e.g. running locally without credentials\n this._writeWarningLine(\n `No credentials found and received a ${response.status}`,\n ' response code from the cloud storage.',\n ' Maybe run rush update-cloud-credentials',\n ' or set the RUSH_BUILD_CACHE_CREDENTIAL env'\n );\n return {\n hasNetworkError: false,\n response: undefined\n };\n } else if (response.status === 400 || response.status === 401 || response.status === 403) {\n throw await this._getS3ErrorAsync(response);\n } else {\n const error: Error = await this._getS3ErrorAsync(response);\n return {\n hasNetworkError: true,\n error\n };\n }\n });\n }\n\n public async uploadObjectAsync(objectName: string, objectBuffer: Buffer): Promise<void> {\n if (!this._credentials) {\n throw new Error('Credentials are required to upload objects to S3.');\n }\n\n await this._sendCacheRequestWithRetriesAsync(async () => {\n const response: WebClientResponse = await this._makeRequestAsync('PUT', objectName, objectBuffer);\n if (!response.ok) {\n return {\n hasNetworkError: true,\n error: await this._getS3ErrorAsync(response)\n };\n }\n return {\n hasNetworkError: false,\n response: undefined\n };\n });\n }\n\n private _writeDebugLine(...messageParts: string[]): void {\n // if the terminal has been closed then don't bother sending a debug message\n try {\n this._terminal.writeDebugLine(...messageParts);\n } catch (err) {\n // ignore error\n }\n }\n\n private _writeWarningLine(...messageParts: string[]): void {\n // if the terminal has been closed then don't bother sending a warning message\n try {\n this._terminal.writeWarningLine(...messageParts);\n } catch (err) {\n // ignore error\n }\n }\n\n private async _makeRequestAsync(\n verb: 'GET' | 'PUT',\n objectName: string,\n body?: Buffer\n ): Promise<WebClientResponse> {\n const isoDateString: IIsoDateString = this._getIsoDateString();\n const bodyHash: string = this._getSha256(body);\n const headers: WebClientHeaders = new WebClientHeaders();\n headers.set(DATE_HEADER_NAME, isoDateString.dateTime);\n headers.set(CONTENT_HASH_HEADER_NAME, bodyHash);\n\n // the host can be e.g. https://s3.aws.com or http://localhost:9000\n const host: string = this._s3Endpoint.replace(protocolRegex, '');\n const canonicalUri: string = AmazonS3Client.UriEncode(`/${objectName}`);\n this._writeDebugLine(Colorize.bold('Canonical URI: '), canonicalUri);\n\n if (this._credentials) {\n // Compute the authorization header. See https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html\n const canonicalHeaders: string[] = [\n `${HOST_HEADER_NAME}:${host}`,\n `${CONTENT_HASH_HEADER_NAME}:${bodyHash}`,\n `${DATE_HEADER_NAME}:${isoDateString.dateTime}`\n ];\n\n // Handle signing with temporary credentials (via sts:assume-role)\n if (this._credentials.sessionToken) {\n canonicalHeaders.push(`${SECURITY_TOKEN_HEADER_NAME}:${this._credentials.sessionToken}`);\n }\n\n // the canonical headers must be sorted by header name\n canonicalHeaders.sort((aHeader, bHeader) => {\n const aHeaderName: string = aHeader.split(':')[0];\n const bHeaderName: string = bHeader.split(':')[0];\n if (aHeaderName < bHeaderName) {\n return -1;\n }\n if (aHeaderName > bHeaderName) {\n return 1;\n }\n return 0;\n });\n\n // the singed header names are derived from the canonicalHeaders\n const signedHeaderNamesString: string = canonicalHeaders\n .map((header) => {\n const headerName: string = header.split(':')[0];\n return headerName;\n })\n .join(';');\n\n // The canonical request looks like this:\n // GET\n // /test.txt\n //\n // host:examplebucket.s3.amazonaws.com\n // range:bytes=0-9\n // x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n // x-amz-date:20130524T000000Z\n //\n // host;range;x-amz-content-sha256;x-amz-date\n // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n const canonicalRequest: string = [\n verb,\n canonicalUri,\n '', // we don't use query strings for these requests\n ...canonicalHeaders,\n '',\n signedHeaderNamesString,\n bodyHash\n ].join('\\n');\n const canonicalRequestHash: string = this._getSha256(canonicalRequest);\n\n const scope: string = `${isoDateString.date}/${this._s3Region}/s3/aws4_request`;\n // The string to sign looks like this:\n // AWS4-HMAC-SHA256\n // 20130524T423589Z\n // 20130524/us-east-1/s3/aws4_request\n // 7344ae5b7ee6c3e7e6b0fe0640412a37625d1fbfff95c48bbb2dc43964946972\n const stringToSign: string = [\n 'AWS4-HMAC-SHA256',\n isoDateString.dateTime,\n scope,\n canonicalRequestHash\n ].join('\\n');\n\n const dateKey: Buffer = this._getSha256Hmac(\n `AWS4${this._credentials.secretAccessKey}`,\n isoDateString.date\n );\n const dateRegionKey: Buffer = this._getSha256Hmac(dateKey, this._s3Region);\n const dateRegionServiceKey: Buffer = this._getSha256Hmac(dateRegionKey, 's3');\n const signingKey: Buffer = this._getSha256Hmac(dateRegionServiceKey, 'aws4_request');\n const signature: string = this._getSha256Hmac(signingKey, stringToSign, 'hex');\n\n const authorizationHeader: string = `AWS4-HMAC-SHA256 Credential=${this._credentials.accessKeyId}/${scope},SignedHeaders=${signedHeaderNamesString},Signature=${signature}`;\n\n headers.set('Authorization', authorizationHeader);\n if (this._credentials.sessionToken) {\n // Handle signing with temporary credentials (via sts:assume-role)\n headers.set('X-Amz-Security-Token', this._credentials.sessionToken);\n }\n }\n\n const webFetchOptions: IGetFetchOptions | IFetchOptionsWithBody = {\n verb,\n headers\n };\n if (verb === 'PUT') {\n (webFetchOptions as IFetchOptionsWithBody).body = body;\n }\n\n const url: string = `${this._s3Endpoint}${canonicalUri}`;\n\n this._writeDebugLine(Colorize.bold(Colorize.underline('Sending request to S3')));\n this._writeDebugLine(Colorize.bold('HOST: '), url);\n this._writeDebugLine(Colorize.bold('Headers: '));\n headers.forEach((value, name) => {\n this._writeDebugLine(Colorize.cyan(`\\t${name}: ${value}`));\n });\n\n const response: WebClientResponse = await this._webClient.fetchAsync(url, webFetchOptions);\n\n return response;\n }\n\n public _getSha256Hmac(key: string | Buffer, data: string): Buffer;\n public _getSha256Hmac(key: string | Buffer, data: string, encoding: 'hex'): string;\n public _getSha256Hmac(key: string | Buffer, data: string, encoding?: 'hex'): Buffer | string {\n const hash: crypto.Hmac = crypto.createHmac('sha256', key);\n hash.update(data);\n if (encoding) {\n return hash.digest(encoding);\n } else {\n return hash.digest();\n }\n }\n\n private _getSha256(data?: string | Buffer): string {\n if (data) {\n const hash: crypto.Hash = crypto.createHash('sha256');\n hash.update(data);\n return hash.digest('hex');\n } else {\n // This is the null SHA256 hash\n return 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';\n }\n }\n\n private _getIsoDateString(date: Date = new Date()): IIsoDateString {\n let dateString: string = date.toISOString();\n dateString = dateString.replace(/[-:]/g, ''); // Remove separator characters\n dateString = dateString.substring(0, 15); // Drop milliseconds\n\n // dateTime is an ISO8601 date. It looks like \"20130524T423589\"\n // date is an ISO date. It looks like \"20130524\"\n return {\n dateTime: `${dateString}Z`,\n date: dateString.substring(0, 8)\n };\n }\n\n private async _safeReadResponseTextAsync(response: WebClientResponse): Promise<string | undefined> {\n try {\n return await response.text();\n } catch (err) {\n // ignore the error\n }\n return undefined;\n }\n\n private async _getS3ErrorAsync(response: WebClientResponse): Promise<Error> {\n const text: string | undefined = await this._safeReadResponseTextAsync(response);\n return new Error(\n `Amazon S3 responded with status code ${response.status} (${response.statusText})${\n text ? `\\n${text}` : ''\n }`\n );\n }\n\n /**\n * Validates a S3 endpoint which is http(s):// + hostname + port. Hostname validated according to RFC 1123\n * {@link https://docs.aws.amazon.com/general/latest/gr/s3.html}\n */\n private _validateEndpoint(s3Endpoint: string): void {\n let host: string = s3Endpoint;\n\n if (!s3Endpoint) {\n throw new Error('A S3 endpoint must be provided');\n }\n\n if (!s3Endpoint.match(protocolRegex)) {\n throw new Error('The S3 endpoint must start with https:// or http://');\n }\n\n host = host.replace(protocolRegex, '');\n\n if (host.match(/\\//)) {\n throw new Error('The path should be omitted from the endpoint. Use s3Prefix to specify a path');\n }\n\n const portMatch: RegExpMatchArray | null = s3Endpoint.match(portRegex);\n if (portMatch) {\n const port: number = Number(portMatch[1]);\n if (Number.isNaN(port) || port > 65535) {\n throw new Error(`Port: ${port} is an invalid port number`);\n }\n host = host.replace(portRegex, '');\n }\n\n if (host.endsWith('.')) {\n host = host.slice(0, host.length - 1);\n }\n\n if (host.length > 253) {\n throw new Error(\n 'The S3 endpoint is too long. RFC 1123 specifies a hostname should be no longer than 253 characters.'\n );\n }\n\n const subDomains: string[] = host.split('.');\n\n const subDomainRegex: RegExp = /^[a-zA-Z0-9-]+$/;\n const isValid: boolean = subDomains.every((subDomain) => {\n return (\n subDomainRegex.test(subDomain) &&\n subDomain.length < 64 &&\n !subDomain.startsWith('-') &&\n !subDomain.endsWith('-')\n );\n });\n\n if (!isValid) {\n throw new Error(\n 'Invalid S3 endpoint. Some part of the hostname contains invalid characters or is too long'\n );\n }\n }\n\n private async _sendCacheRequestWithRetriesAsync<T>(\n sendRequest: () => Promise<RetryableRequestResponse<T>>\n ): Promise<T> {\n const response: RetryableRequestResponse<T> = await sendRequest();\n\n const log: (...messageParts: string[]) => void = this._writeDebugLine.bind(this);\n\n if (response.hasNetworkError) {\n if (storageRetryOptions && storageRetryOptions.maxTries > 1) {\n log('Network request failed. Will retry request as specified in storageRetryOptions');\n async function retry(retryAttempt: number): Promise<T> {\n const { retryDelayInMs, retryPolicyType, maxTries, maxRetryDelayInMs } = storageRetryOptions;\n let delay: number = retryDelayInMs;\n if (retryPolicyType === StorageRetryPolicyType.EXPONENTIAL) {\n delay = retryDelayInMs * Math.pow(2, retryAttempt - 1);\n }\n delay = Math.min(maxRetryDelayInMs, delay);\n\n log(`Will retry request in ${delay}s...`);\n await Async.sleepAsync(delay);\n const retryResponse: RetryableRequestResponse<T> = await sendRequest();\n\n if (retryResponse.hasNetworkError) {\n if (retryAttempt < maxTries - 1) {\n log('The retried request failed, will try again');\n return retry(retryAttempt + 1);\n } else {\n log('The retried request failed and has reached the maxTries limit');\n throw retryResponse.error;\n }\n }\n\n return retryResponse.response;\n }\n return retry(1);\n } else {\n log('Network request failed and storageRetryOptions is not specified');\n throw response.error;\n }\n }\n\n return response.response;\n }\n}\n"]} |
+0
-1
| import { RushAmazonS3BuildCachePlugin } from './RushAmazonS3BuildCachePlugin'; | ||
| export { type IAmazonS3Credentials } from './AmazonS3Credentials'; | ||
| export { AmazonS3Client } from './AmazonS3Client'; | ||
| export { WebClient, type IGetFetchOptions, type IPutFetchOptions, type WebClientResponse } from './WebClient'; | ||
| export default RushAmazonS3BuildCachePlugin; | ||
| export type { IAmazonS3BuildCacheProviderOptionsBase, IAmazonS3BuildCacheProviderOptionsAdvanced, IAmazonS3BuildCacheProviderOptionsSimple } from './AmazonS3BuildCacheProvider'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9G,eAAe,4BAA4B,CAAC;AAC5C,YAAY,EACV,sCAAsC,EACtC,0CAA0C,EAC1C,wCAAwC,EACzC,MAAM,8BAA8B,CAAC"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,eAAe,4BAA4B,CAAC;AAC5C,YAAY,EACV,sCAAsC,EACtC,0CAA0C,EAC1C,wCAAwC,EACzC,MAAM,8BAA8B,CAAC"} |
+1
-3
@@ -5,9 +5,7 @@ "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WebClient = exports.AmazonS3Client = void 0; | ||
| exports.AmazonS3Client = void 0; | ||
| const RushAmazonS3BuildCachePlugin_1 = require("./RushAmazonS3BuildCachePlugin"); | ||
| var AmazonS3Client_1 = require("./AmazonS3Client"); | ||
| Object.defineProperty(exports, "AmazonS3Client", { enumerable: true, get: function () { return AmazonS3Client_1.AmazonS3Client; } }); | ||
| var WebClient_1 = require("./WebClient"); | ||
| Object.defineProperty(exports, "WebClient", { enumerable: true, get: function () { return WebClient_1.WebClient; } }); | ||
| exports.default = RushAmazonS3BuildCachePlugin_1.RushAmazonS3BuildCachePlugin; | ||
| //# sourceMappingURL=index.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,iFAA8E;AAG9E,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,yCAA8G;AAArG,sGAAA,SAAS,OAAA;AAClB,kBAAe,2DAA4B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { RushAmazonS3BuildCachePlugin } from './RushAmazonS3BuildCachePlugin';\n\nexport { type IAmazonS3Credentials } from './AmazonS3Credentials';\nexport { AmazonS3Client } from './AmazonS3Client';\nexport { WebClient, type IGetFetchOptions, type IPutFetchOptions, type WebClientResponse } from './WebClient';\nexport default RushAmazonS3BuildCachePlugin;\nexport type {\n IAmazonS3BuildCacheProviderOptionsBase,\n IAmazonS3BuildCacheProviderOptionsAdvanced,\n IAmazonS3BuildCacheProviderOptionsSimple\n} from './AmazonS3BuildCacheProvider';\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,iFAA8E;AAG9E,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,kBAAe,2DAA4B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { RushAmazonS3BuildCachePlugin } from './RushAmazonS3BuildCachePlugin';\n\nexport { type IAmazonS3Credentials } from './AmazonS3Credentials';\nexport { AmazonS3Client } from './AmazonS3Client';\nexport default RushAmazonS3BuildCachePlugin;\nexport type {\n IAmazonS3BuildCacheProviderOptionsBase,\n IAmazonS3BuildCacheProviderOptionsAdvanced,\n IAmazonS3BuildCacheProviderOptionsSimple\n} from './AmazonS3BuildCacheProvider';\n"]} |
+6
-8
| { | ||
| "name": "@rushstack/rush-amazon-s3-build-cache-plugin", | ||
| "version": "5.143.0-pr5009.0", | ||
| "version": "5.143.0-pr5009.1", | ||
| "description": "Rush plugin for Amazon S3 cloud build cache", | ||
@@ -16,12 +16,10 @@ "repository": { | ||
| "https-proxy-agent": "~5.0.0", | ||
| "node-fetch": "2.6.7", | ||
| "@rushstack/node-core-library": "5.10.0", | ||
| "@rushstack/rush-sdk": "5.143.0-pr5009.0", | ||
| "@rushstack/terminal": "0.14.3" | ||
| "@rushstack/terminal": "0.14.3", | ||
| "@rushstack/rush-sdk": "5.143.0-pr5009.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node-fetch": "2.6.2", | ||
| "@microsoft/rush-lib": "5.143.0-pr5009.0", | ||
| "local-node-rig": "1.0.0", | ||
| "@rushstack/heft": "0.68.9" | ||
| "@microsoft/rush-lib": "5.143.0-pr5009.1", | ||
| "@rushstack/heft": "0.68.9", | ||
| "local-node-rig": "1.0.0" | ||
| }, | ||
@@ -28,0 +26,0 @@ "scripts": { |
| /// <reference types="node" /> | ||
| import * as fetch from 'node-fetch'; | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export type WebClientResponse = fetch.Response; | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export interface IWebFetchOptionsBase { | ||
| timeoutMs?: number; | ||
| verb?: 'GET' | 'PUT'; | ||
| headers?: fetch.Headers; | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export interface IGetFetchOptions extends IWebFetchOptionsBase { | ||
| verb: 'GET' | never; | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * | ||
| * @public | ||
| */ | ||
| export interface IPutFetchOptions extends IWebFetchOptionsBase { | ||
| verb: 'PUT'; | ||
| body?: Buffer; | ||
| } | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * @public | ||
| */ | ||
| export declare enum WebClientProxy { | ||
| None = 0, | ||
| Detect = 1, | ||
| Fiddler = 2 | ||
| } | ||
| /** | ||
| * A helper for issuing HTTP requests. | ||
| * | ||
| * @public | ||
| */ | ||
| export declare class WebClient { | ||
| readonly standardHeaders: fetch.Headers; | ||
| accept: string | undefined; | ||
| userAgent: string | undefined; | ||
| proxy: WebClientProxy; | ||
| constructor(); | ||
| static mergeHeaders(target: fetch.Headers, source: fetch.Headers): void; | ||
| addBasicAuthHeader(userName: string, password: string): void; | ||
| fetchAsync(url: string, options?: IGetFetchOptions | IPutFetchOptions): Promise<WebClientResponse>; | ||
| } | ||
| //# sourceMappingURL=WebClient.d.ts.map |
| {"version":3,"file":"WebClient.d.ts","sourceRoot":"","sources":["../src/WebClient.ts"],"names":[],"mappings":";AAaA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAMpC;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,QAAQ,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC5D,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC5D,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,oBAAY,cAAc;IACxB,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,OAAO,IAAA;CACR;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB,SAAgB,eAAe,EAAE,KAAK,CAAC,OAAO,CAAuB;IAE9D,MAAM,EAAE,MAAM,GAAG,SAAS,CAAS;IACnC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAgE;IAE7F,KAAK,EAAE,cAAc,CAAyB;;WAIvC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI;IAMvE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAOtD,UAAU,CACrB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,GAC5C,OAAO,CAAC,iBAAiB,CAAC;CAsD9B"} |
-119
| "use strict"; | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WebClient = exports.WebClientProxy = void 0; | ||
| // =================================================================================================================== | ||
| // AS A TEMPORARY WORKAROUND, THIS FILE WAS COPY+PASTED FROM THE "rush-lib" PROJECT. | ||
| // | ||
| // Eventually we plan to convert it into a more generic API for "node-core-library" or | ||
| // else replace it with a third party solution such as Axios. See the discussion here: | ||
| // https://github.com/microsoft/rushstack/pull/3036#discussion_r758010126 | ||
| // =================================================================================================================== | ||
| const os = __importStar(require("os")); | ||
| const process = __importStar(require("process")); | ||
| const fetch = __importStar(require("node-fetch")); | ||
| const node_core_library_1 = require("@rushstack/node-core-library"); | ||
| const createHttpsProxyAgent = node_core_library_1.Import.lazy('https-proxy-agent', require); | ||
| /** | ||
| * For use with {@link WebClient}. | ||
| * @public | ||
| */ | ||
| var WebClientProxy; | ||
| (function (WebClientProxy) { | ||
| WebClientProxy[WebClientProxy["None"] = 0] = "None"; | ||
| WebClientProxy[WebClientProxy["Detect"] = 1] = "Detect"; | ||
| WebClientProxy[WebClientProxy["Fiddler"] = 2] = "Fiddler"; | ||
| })(WebClientProxy || (exports.WebClientProxy = WebClientProxy = {})); | ||
| /** | ||
| * A helper for issuing HTTP requests. | ||
| * | ||
| * @public | ||
| */ | ||
| class WebClient { | ||
| constructor() { | ||
| this.standardHeaders = new fetch.Headers(); | ||
| this.accept = '*/*'; | ||
| this.userAgent = `rush node/${process.version} ${os.platform()} ${os.arch()}`; | ||
| this.proxy = WebClientProxy.Detect; | ||
| } | ||
| static mergeHeaders(target, source) { | ||
| source.forEach((value, name) => { | ||
| target.set(name, value); | ||
| }); | ||
| } | ||
| addBasicAuthHeader(userName, password) { | ||
| this.standardHeaders.set('Authorization', 'Basic ' + Buffer.from(userName + ':' + password).toString('base64')); | ||
| } | ||
| async fetchAsync(url, options) { | ||
| const headers = new fetch.Headers(); | ||
| WebClient.mergeHeaders(headers, this.standardHeaders); | ||
| if (options === null || options === void 0 ? void 0 : options.headers) { | ||
| WebClient.mergeHeaders(headers, options.headers); | ||
| } | ||
| if (this.userAgent) { | ||
| headers.set('user-agent', this.userAgent); | ||
| } | ||
| if (this.accept) { | ||
| headers.set('accept', this.accept); | ||
| } | ||
| let proxyUrl = ''; | ||
| switch (this.proxy) { | ||
| case WebClientProxy.Detect: | ||
| if (process.env.HTTPS_PROXY) { | ||
| proxyUrl = process.env.HTTPS_PROXY; | ||
| } | ||
| else if (process.env.HTTP_PROXY) { | ||
| proxyUrl = process.env.HTTP_PROXY; | ||
| } | ||
| break; | ||
| case WebClientProxy.Fiddler: | ||
| // For debugging, disable cert validation | ||
| // eslint-disable-next-line | ||
| process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; | ||
| proxyUrl = 'http://localhost:8888/'; | ||
| break; | ||
| } | ||
| let agent = undefined; | ||
| if (proxyUrl) { | ||
| agent = createHttpsProxyAgent(proxyUrl); | ||
| } | ||
| const timeoutMs = (options === null || options === void 0 ? void 0 : options.timeoutMs) !== undefined ? options.timeoutMs : 15 * 1000; // 15 seconds | ||
| const requestInit = { | ||
| method: options === null || options === void 0 ? void 0 : options.verb, | ||
| headers: headers, | ||
| agent: agent, | ||
| timeout: timeoutMs | ||
| }; | ||
| const putOptions = options; | ||
| if (putOptions === null || putOptions === void 0 ? void 0 : putOptions.body) { | ||
| requestInit.body = putOptions.body; | ||
| } | ||
| return await fetch.default(url, requestInit); | ||
| } | ||
| } | ||
| exports.WebClient = WebClient; | ||
| //# sourceMappingURL=WebClient.js.map |
| {"version":3,"file":"WebClient.js","sourceRoot":"","sources":["../src/WebClient.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,sHAAsH;AACtH,oFAAoF;AACpF,EAAE;AACF,sFAAsF;AACtF,uFAAuF;AACvF,yEAAyE;AACzE,sHAAsH;AAEtH,uCAAyB;AACzB,iDAAmC;AACnC,kDAAoC;AAEpC,oEAAsD;AAEtD,MAAM,qBAAqB,GAAuC,0BAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;AAuC5G;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K,EAAE,KAAK;YACZ,OAAO,EAAE,SAAS;SACnB,CAAC;QACF,MAAM,UAAU,GAAiC,OAAuC,CAAC;QACzF,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,IAAI,EAAE,CAAC;YACrB,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QACrC,CAAC;QAED,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;CACF;AAhFD,8BAgFC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n// ===================================================================================================================\n// AS A TEMPORARY WORKAROUND, THIS FILE WAS COPY+PASTED FROM THE \"rush-lib\" PROJECT.\n//\n// Eventually we plan to convert it into a more generic API for \"node-core-library\" or\n// else replace it with a third party solution such as Axios. See the discussion here:\n// https://github.com/microsoft/rushstack/pull/3036#discussion_r758010126\n// ===================================================================================================================\n\nimport * as os from 'os';\nimport * as process from 'process';\nimport * as fetch from 'node-fetch';\nimport type * as http from 'http';\nimport { Import } from '@rushstack/node-core-library';\n\nconst createHttpsProxyAgent: typeof import('https-proxy-agent') = Import.lazy('https-proxy-agent', require);\n\n/**\n * For use with {@link WebClient}.\n *\n * @public\n */\nexport type WebClientResponse = fetch.Response;\n\n/**\n * For use with {@link WebClient}.\n *\n * @public\n */\nexport interface IWebFetchOptionsBase {\n timeoutMs?: number;\n verb?: 'GET' | 'PUT';\n headers?: fetch.Headers;\n}\n\n/**\n * For use with {@link WebClient}.\n *\n * @public\n */\nexport interface IGetFetchOptions extends IWebFetchOptionsBase {\n verb: 'GET' | never;\n}\n\n/**\n * For use with {@link WebClient}.\n *\n * @public\n */\nexport interface IPutFetchOptions extends IWebFetchOptionsBase {\n verb: 'PUT';\n body?: Buffer;\n}\n\n/**\n * For use with {@link WebClient}.\n * @public\n */\nexport enum WebClientProxy {\n None,\n Detect,\n Fiddler\n}\n\n/**\n * A helper for issuing HTTP requests.\n *\n * @public\n */\nexport class WebClient {\n public readonly standardHeaders: fetch.Headers = new fetch.Headers();\n\n public accept: string | undefined = '*/*';\n public userAgent: string | undefined = `rush node/${process.version} ${os.platform()} ${os.arch()}`;\n\n public proxy: WebClientProxy = WebClientProxy.Detect;\n\n public constructor() {}\n\n public static mergeHeaders(target: fetch.Headers, source: fetch.Headers): void {\n source.forEach((value, name) => {\n target.set(name, value);\n });\n }\n\n public addBasicAuthHeader(userName: string, password: string): void {\n this.standardHeaders.set(\n 'Authorization',\n 'Basic ' + Buffer.from(userName + ':' + password).toString('base64')\n );\n }\n\n public async fetchAsync(\n url: string,\n options?: IGetFetchOptions | IPutFetchOptions\n ): Promise<WebClientResponse> {\n const headers: fetch.Headers = new fetch.Headers();\n\n WebClient.mergeHeaders(headers, this.standardHeaders);\n\n if (options?.headers) {\n WebClient.mergeHeaders(headers, options.headers);\n }\n\n if (this.userAgent) {\n headers.set('user-agent', this.userAgent);\n }\n if (this.accept) {\n headers.set('accept', this.accept);\n }\n\n let proxyUrl: string = '';\n\n switch (this.proxy) {\n case WebClientProxy.Detect:\n if (process.env.HTTPS_PROXY) {\n proxyUrl = process.env.HTTPS_PROXY;\n } else if (process.env.HTTP_PROXY) {\n proxyUrl = process.env.HTTP_PROXY;\n }\n break;\n\n case WebClientProxy.Fiddler:\n // For debugging, disable cert validation\n // eslint-disable-next-line\n process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';\n proxyUrl = 'http://localhost:8888/';\n break;\n }\n\n let agent: http.Agent | undefined = undefined;\n if (proxyUrl) {\n agent = createHttpsProxyAgent(proxyUrl);\n }\n\n const timeoutMs: number = options?.timeoutMs !== undefined ? options.timeoutMs : 15 * 1000; // 15 seconds\n const requestInit: fetch.RequestInit = {\n method: options?.verb,\n headers: headers,\n agent: agent,\n timeout: timeoutMs\n };\n const putOptions: IPutFetchOptions | undefined = options as IPutFetchOptions | undefined;\n if (putOptions?.body) {\n requestInit.body = putOptions.body;\n }\n\n return await fetch.default(url, requestInit);\n }\n}\n"]} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
4
-20%3
-25%5
-54.55%0
-100%97401
-14.26%27
-12.9%954
-19.9%+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed