gcp-metadata
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -41,4 +41,21 @@ /** | ||
/** | ||
* A cache for the detected GCP Residency. | ||
*/ | ||
export declare let gcpResidencyCache: boolean | null; | ||
/** | ||
* Sets the detected GCP Residency. | ||
* Useful for forcing metadata server detection behavior. | ||
* | ||
* Set `null` to autodetect the environment (default behavior). | ||
*/ | ||
export declare function setGCPResidency(value?: boolean | null): void; | ||
/** | ||
* Obtain the timeout for requests to the metadata server. | ||
* | ||
* In certain environments and conditions requests can take longer than | ||
* the default timeout to complete. This function will determine the | ||
* appropriate timeout based on the environment. | ||
* | ||
* @returns {number} a request timeout duration in milliseconds. | ||
*/ | ||
export declare function requestTimeout(): number; |
@@ -9,5 +9,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.requestTimeout = exports.resetIsAvailableCache = exports.isAvailable = exports.project = exports.instance = exports.HEADERS = exports.HEADER_VALUE = exports.HEADER_NAME = exports.SECONDARY_HOST_ADDRESS = exports.HOST_ADDRESS = exports.BASE_PATH = void 0; | ||
exports.requestTimeout = exports.setGCPResidency = exports.gcpResidencyCache = exports.resetIsAvailableCache = exports.isAvailable = exports.project = exports.instance = exports.HEADERS = exports.HEADER_VALUE = exports.HEADER_NAME = exports.SECONDARY_HOST_ADDRESS = exports.HOST_ADDRESS = exports.BASE_PATH = void 0; | ||
const gaxios_1 = require("gaxios"); | ||
const jsonBigint = require("json-bigint"); | ||
const gcp_residency_1 = require("./gcp-residency"); | ||
exports.BASE_PATH = '/computeMetadata/v1'; | ||
@@ -242,18 +243,32 @@ exports.HOST_ADDRESS = 'http://169.254.169.254'; | ||
/** | ||
* A cache for the detected GCP Residency. | ||
*/ | ||
exports.gcpResidencyCache = null; | ||
/** | ||
* Sets the detected GCP Residency. | ||
* Useful for forcing metadata server detection behavior. | ||
* | ||
* Set `null` to autodetect the environment (default behavior). | ||
*/ | ||
function setGCPResidency(value = null) { | ||
exports.gcpResidencyCache = value !== null ? value : (0, gcp_residency_1.detectGCPResidency)(); | ||
} | ||
exports.setGCPResidency = setGCPResidency; | ||
/** | ||
* Obtain the timeout for requests to the metadata server. | ||
* | ||
* In certain environments and conditions requests can take longer than | ||
* the default timeout to complete. This function will determine the | ||
* appropriate timeout based on the environment. | ||
* | ||
* @returns {number} a request timeout duration in milliseconds. | ||
*/ | ||
function requestTimeout() { | ||
// In testing, we were able to reproduce behavior similar to | ||
// https://github.com/googleapis/google-auth-library-nodejs/issues/798 | ||
// by making many concurrent network requests. Requests do not actually fail, | ||
// rather they take significantly longer to complete (and we hit our | ||
// default 3000ms timeout). | ||
// | ||
// This logic detects a GCF environment, using the documented environment | ||
// variables K_SERVICE and FUNCTION_NAME: | ||
// https://cloud.google.com/functions/docs/env-var and, in a GCF environment | ||
// eliminates timeouts (by setting the value to 0 to disable). | ||
return process.env.K_SERVICE || process.env.FUNCTION_NAME ? 0 : 3000; | ||
// Detecting the residency can be resource-intensive. Let's cache the result. | ||
if (exports.gcpResidencyCache === null) { | ||
exports.gcpResidencyCache = (0, gcp_residency_1.detectGCPResidency)(); | ||
} | ||
return exports.gcpResidencyCache ? 0 : 3000; | ||
} | ||
exports.requestTimeout = requestTimeout; | ||
//# sourceMappingURL=index.js.map |
@@ -7,2 +7,9 @@ # Changelog | ||
## [5.1.0](https://github.com/googleapis/gcp-metadata/compare/v5.0.1...v5.1.0) (2022-12-07) | ||
### Features | ||
* Extend GCP Residency Detection Support ([#528](https://github.com/googleapis/gcp-metadata/issues/528)) ([2b35bb0](https://github.com/googleapis/gcp-metadata/commit/2b35bb0e6fb1a18294aeeebba91a6bf7b400385a)) | ||
## [5.0.1](https://github.com/googleapis/gcp-metadata/compare/v5.0.0...v5.0.1) (2022-09-09) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "gcp-metadata", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Get the metadata from a Google Cloud Platform environment", | ||
@@ -49,5 +49,6 @@ "repository": "googleapis/gcp-metadata", | ||
"@types/ncp": "^2.0.1", | ||
"@types/node": "^17.0.25", | ||
"@types/node": "^18.0.0", | ||
"@types/sinon": "^10.0.13", | ||
"@types/tmp": "0.2.3", | ||
"@types/uuid": "^8.0.0", | ||
"@types/uuid": "^9.0.0", | ||
"c8": "^7.0.0", | ||
@@ -62,2 +63,3 @@ "cross-env": "^7.0.3", | ||
"nock": "^13.0.0", | ||
"sinon": "^14.0.0", | ||
"tmp": "^0.2.0", | ||
@@ -64,0 +66,0 @@ "typescript": "^4.6.3", |
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
70359
10
502
22
11