@rushstack/rush-amazon-s3-build-cache-plugin 5.90.0 → 5.90.2-pr3954.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AmazonS3Client.js","sourceRoot":"","sources":["../src/AmazonS3Client.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAA4F;AAC5F,+CAAiC;AACjC,kDAAoC;AAKpC,MAAM,wBAAwB,GAA2B,sBAAsB,CAAC;AAChF,MAAM,gBAAgB,GAAiB,YAAY,CAAC;AACpD,MAAM,gBAAgB,GAAW,MAAM,CAAC;AACxC,MAAM,0BAA0B,GAA2B,sBAAsB,CAAC;AA4BlF,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,CAA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AE,QAAQ,EAAE,iBAAiB,EAAE,GAAG,mBAAmB,CAAC;oBAC7F,IAAI,KAAK,GAAW,cAAc,CAAC;oBACnC,IAAI,eAAe,KAAK,sBAAsB,CAAC,WAAW,EAAE;wBAC1D,KAAK,GAAG,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;qBACxD;oBACD,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;oBAE3C,GAAG,CAAC,yBAAyB,KAAK,MAAM,CAAC,CAAC;oBAC1C,MAAM,yBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACzB,MAAM,QAAQ,GAAgC,MAAM,WAAW,EAAE,CAAC;oBAElE,IAAI,QAAQ,CAAC,eAAe,EAAE;wBAC5B,IAAI,YAAY,GAAG,QAAQ,GAAG,CAAC,EAAE;4BAC/B,GAAG,CAAC,4CAA4C,CAAC,CAAC;4BAClD,OAAO,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;yBAChC;6BAAM;4BACL,GAAG,CAAC,+DAA+D,CAAC,CAAC;4BACrE,MAAM,QAAQ,CAAC,KAAK,CAAC;yBACtB;qBACF;oBAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;gBAC3B,CAAC;gBACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;aACjB;iBAAM;gBACL,GAAG,CAAC,iEAAiE,CAAC,CAAC;gBACvE,MAAM,QAAQ,CAAC,KAAK,CAAC;aACtB;SACF;QAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;CACF;AAzaD,wCAyaC","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, Colors, IColorableSequence, ITerminal } from '@rushstack/node-core-library';\nimport * as crypto from 'crypto';\nimport * as fetch from 'node-fetch';\n\nimport { IAmazonS3BuildCacheProviderOptionsAdvanced } from './AmazonS3BuildCacheProvider';\nimport { IGetFetchOptions, IPutFetchOptions, WebClient } from './WebClient';\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\n/**\n * Credentials for authorizing and signing requests to an Amazon S3 endpoint.\n *\n * @public\n */\nexport interface IAmazonS3Credentials {\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken: string | undefined;\n}\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 if (!credentialString) {\n return undefined;\n }\n\n const fields: string[] = credentialString.split(':');\n if (fields.length < 2 || fields.length > 3) {\n throw new Error('Amazon S3 credential is in an unexpected format.');\n }\n\n return {\n accessKeyId: fields[0],\n secretAccessKey: fields[1],\n sessionToken: fields[2]\n };\n }\n\n public async getObjectAsync(objectName: string): Promise<Buffer | undefined> {\n this._writeDebugLine('Reading object from S3');\n return await this._sendCacheRequestWithRetries(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._sendCacheRequestWithRetries(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 | IColorableSequence)[]): 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 | IColorableSequence)[]): 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(Colors.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(Colors.bold(Colors.underline('Sending request to S3')));\n this._writeDebugLine(Colors.bold('HOST: '), url);\n this._writeDebugLine(Colors.bold('Headers: '));\n headers.forEach((value, name) => {\n this._writeDebugLine(Colors.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.Hash = 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 _safeReadResponseText(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._safeReadResponseText(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 _sendCacheRequestWithRetries<T>(\n sendRequest: () => Promise<RetryableRequestResponse<T>>\n ): Promise<T> {\n const response: RetryableRequestResponse<T> = await sendRequest();\n\n const log: (...messageParts: (string | IColorableSequence)[]) => 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.sleep(delay);\n const response: RetryableRequestResponse<T> = await sendRequest();\n\n if (response.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 response.error;\n }\n }\n\n return response.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"]}
1
+ {"version":3,"file":"AmazonS3Client.js","sourceRoot":"","sources":["../src/AmazonS3Client.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,oEAA4F;AAC5F,+CAAiC;AACjC,kDAAoC;AAKpC,MAAM,wBAAwB,GAA2B,sBAAsB,CAAC;AAChF,MAAM,gBAAgB,GAAiB,YAAY,CAAC;AACpD,MAAM,gBAAgB,GAAW,MAAM,CAAC;AACxC,MAAM,0BAA0B,GAA2B,sBAAsB,CAAC;AA4BlF,MA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,eAAe,EAAE;wBAC5B,IAAI,YAAY,GAAG,QAAQ,GAAG,CAAC,EAAE;4BAC/B,GAAG,CAAC,4CAA4C,CAAC,CAAC;4BAClD,OAAO,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;yBAChC;6BAAM;4BACL,GAAG,CAAC,+DAA+D,CAAC,CAAC;4BACrE,MAAM,QAAQ,CAAC,KAAK,CAAC;yBACtB;qBACF;oBAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;gBAC3B,CAAC;gBACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;aACjB;iBAAM;gBACL,GAAG,CAAC,iEAAiE,CAAC,CAAC;gBACvE,MAAM,QAAQ,CAAC,KAAK,CAAC;aACtB;SACF;QAED,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;CACF;AAzaD,wCAyaC","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, Colors, IColorableSequence, ITerminal } from '@rushstack/node-core-library';\nimport * as crypto from 'crypto';\nimport * as fetch from 'node-fetch';\n\nimport { IAmazonS3BuildCacheProviderOptionsAdvanced } from './AmazonS3BuildCacheProvider';\nimport { IGetFetchOptions, IPutFetchOptions, WebClient } from './WebClient';\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\n/**\n * Credentials for authorizing and signing requests to an Amazon S3 endpoint.\n *\n * @public\n */\nexport interface IAmazonS3Credentials {\n accessKeyId: string;\n secretAccessKey: string;\n sessionToken: string | undefined;\n}\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 if (!credentialString) {\n return undefined;\n }\n\n const fields: string[] = credentialString.split(':');\n if (fields.length < 2 || fields.length > 3) {\n throw new Error('Amazon S3 credential is in an unexpected format.');\n }\n\n return {\n accessKeyId: fields[0],\n secretAccessKey: fields[1],\n sessionToken: fields[2]\n };\n }\n\n public async getObjectAsync(objectName: string): Promise<Buffer | undefined> {\n this._writeDebugLine('Reading object from S3');\n return await this._sendCacheRequestWithRetries(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._sendCacheRequestWithRetries(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 | IColorableSequence)[]): 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 | IColorableSequence)[]): 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(Colors.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(Colors.bold(Colors.underline('Sending request to S3')));\n this._writeDebugLine(Colors.bold('HOST: '), url);\n this._writeDebugLine(Colors.bold('Headers: '));\n headers.forEach((value, name) => {\n this._writeDebugLine(Colors.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 _safeReadResponseText(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._safeReadResponseText(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 _sendCacheRequestWithRetries<T>(\n sendRequest: () => Promise<RetryableRequestResponse<T>>\n ): Promise<T> {\n const response: RetryableRequestResponse<T> = await sendRequest();\n\n const log: (...messageParts: (string | IColorableSequence)[]) => 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.sleep(delay);\n const response: RetryableRequestResponse<T> = await sendRequest();\n\n if (response.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 response.error;\n }\n }\n\n return response.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"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.34.0"
8
+ "packageVersion": "7.34.4"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/rush-amazon-s3-build-cache-plugin",
3
- "version": "5.90.0",
3
+ "version": "5.90.2-pr3954.0",
4
4
  "description": "Rush plugin for Amazon S3 cloud build cache",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,17 +14,17 @@
14
14
  "dependencies": {
15
15
  "https-proxy-agent": "~5.0.0",
16
16
  "node-fetch": "2.6.7",
17
- "@rushstack/node-core-library": "3.53.3",
18
- "@rushstack/rush-sdk": "5.90.0"
17
+ "@rushstack/node-core-library": "3.55.2",
18
+ "@rushstack/rush-sdk": "5.90.2-pr3954.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/heft-jest": "1.0.1",
22
- "@types/node": "12.20.24",
23
- "@types/node-fetch": "1.6.9",
24
- "@microsoft/rush-lib": "5.90.0",
25
- "@rushstack/eslint-config": "3.1.1",
26
- "@rushstack/heft": "0.49.3",
27
- "@rushstack/heft-node-rig": "1.11.14"
22
+ "@types/node": "14.18.36",
23
+ "@types/node-fetch": "2.6.2",
24
+ "@microsoft/rush-lib": "5.90.2-pr3954.0",
25
+ "@rushstack/eslint-config": "3.2.0",
26
+ "@rushstack/heft": "0.49.7",
27
+ "@rushstack/heft-node-rig": "1.12.4"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "heft build --clean",