Socket
Socket
Sign inDemoInstall

@sap/xsenv

Package Overview
Dependencies
3
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 3.2.1

6

CHANGELOG.md

@@ -8,2 +8,8 @@ # Change Log

## 3.2.1 - 2022-02-28
### Added
- Reading K8s services now caches the results to decrease file system calls.
- Documentation on how to disable caching for K8s Services if needed.
## 3.2.0 - 2022-01-24

@@ -10,0 +16,0 @@

21

lib/k8sservice.js

@@ -9,2 +9,4 @@ 'use strict';

const DEFAULT_SECRETS_PATH = '/etc/secrets/sapcp/';
const NodeCache = require('node-cache');
const k8sSecretsCache = new NodeCache({ stdTTL: 9 * 60 });

@@ -81,7 +83,22 @@ exports.readK8SServices = readK8SServices;

function readK8SServices(secretsPath) {
function readK8SServices(secretsPath, disableCache) {
secretsPath = secretsPath || DEFAULT_SECRETS_PATH;
assert(typeof secretsPath === 'string', 'secrets directory path must be string');
let result = undefined;
return fs.existsSync(secretsPath) ? readSecrets(secretsPath) : undefined;
let cachedSecrets = k8sSecretsCache.get(`${secretsPath}-services`);
if (cachedSecrets && !disableCache) {
debug(`Cached Secrets found: ${secretsPath}-services`);
debug(cachedSecrets);
return cachedSecrets;
}
if (fs.existsSync(secretsPath)) {
result = readSecrets(secretsPath);
debug(`Caching Secret: ${secretsPath}-services`);
debug(result);
k8sSecretsCache.set(`${secretsPath}-services`, result);
}
return result;
}

9

lib/xsservices.js

@@ -81,3 +81,3 @@ 'use strict';

* @param filter Filter used to find a bound service, see filterCFServices
* @return credentials property of found service
* @return Array of objects representing all found service instances (credentials and its meta data)
* @throws Error in case no or multiple matching services are found

@@ -127,6 +127,7 @@ */

* @param path {string} A string containing the mount path where the secrets are mounted in K8S environment.
* @param options {object} An object with options to customize behavior. Currently allows only to disable K8s secrets caching.
* @return Object with appropriate services or empty object if no CF or K8S services found.
* @throws Error in case bad CF json or bad path.
*/
function readServices(path) {
function readServices(path, options) {
let cfServices = readCFServices();

@@ -137,5 +138,5 @@ if (cfServices && Object.keys(cfServices).length > 0) {

}
let k8sServices = readK8SServices(path);
debug('Empty VCAP_SERVICES, returning K8s services: %s.', k8sServices);
let k8sServices = readK8SServices(path, options && options.disableCache);
debug('Empty VCAP_SERVICES, returning K8s services: %s.', JSON.stringify(k8sServices));
return k8sServices || {};
}
{
"name": "@sap/xsenv",
"version": "3.2.0",
"version": "3.2.1",
"lockfileVersion": 1,

@@ -10,2 +10,5 @@ "requires": true,

},
"clone": {
"version": "2.1.2"
},
"core-util-is": {

@@ -26,2 +29,8 @@ "version": "1.0.2"

},
"node-cache": {
"version": "5.1.2",
"requires": {
"clone": "2.x"
}
},
"verror": {

@@ -28,0 +37,0 @@ "version": "1.10.0",

{
"name": "@sap/xsenv",
"version": "3.2.0",
"version": "3.2.1",
"description": "Utility for easy setup and access of SAP HANA XS Advanced environment variables",

@@ -34,2 +34,3 @@ "repository": {},

"node-style": "^2.0.0",
"proxyquire": "^2.1.3",
"should": "10.0.0"

@@ -39,4 +40,5 @@ },

"debug": "4.3.3",
"node-cache": "^5.1.0",
"verror": "1.10.0"
}
}

@@ -350,5 +350,6 @@ # @sap/xsenv

### readServices([path])
### readServices([path], [options])
* `path` - (optional) A string containing the mount path where the secrets are located in Kubernetes. By default is "/etc/secrets/sapcp".
* `options` - (optional) An object with options to customize behavior. Only supports field `disableCache` to disable K8s secrets caching.
* _returns_ Returns an object where each service instance is mapped to its name. Works in Kubernetes and Cloud Foundry.

@@ -355,0 +356,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc