Socket
Socket
Sign inDemoInstall

@sap/xsenv

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap/xsenv - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

2

package.json

@@ -1,1 +0,1 @@

{"dependencies":{"debug":"2.2.0","verror":"1.6.0"},"description":"Utility for easy setup and access of SAP HANA XS Advanced environment variables","devDependencies":{"eslint":"3.2.2","filter-node-package":"^2.0.0","istanbul":"0.4.4","lodash":"4.13.1","mocha":"3.0.2","node-style":"^2.0.0","should":"10.0.0"},"engines":{"node":"^0.12.7 || ^4.4.0 || ^6.0.0"},"main":"index.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/xsenv","optionalDependencies":{},"readme":"# @sap/xsenv\n\nUtility for easy setup and access of environment variables and services in Cloud Foundry and XSA.\n\nApplications in Cloud Foundry take various configurations from the environment.\nFor example Cloud Foundry provides properties of bound services in [VCAP_SERVICES](http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES) environment variable.\n\nTo test locally you need to provide these configurations by yourself. This package allows you to provide default configurations in a separate configuration file.\n* This reduces clutter by removing configuration data from the app code.\n* You don't have to set env vars manually each time you start your app.\n* Different developers can use their own configurations for their local tests without changing files under source control. Just add this configuration file to `.gitignore` and `.cfignore`.\n\nYou can provide default configurations on two levels:\n* For Cloud Foundry services via `getServices()` and `default-services.json`\n* For any environment variable via `loadEnv()` and `default-env.json`\n\nWhile here we often reference Cloud Foundry, it all applies also to SAP HANA XS Advanced On-premise Runtime which emulates Cloud Foundry as much as possible.\n\n## Install\n\n```sh\nnpm install --save @sap/xsenv\n```\n\n## Service Lookup\n\nNormally in Cloud Foundry you bind a service instance to your application with a command like this one:\n```sh\ncf bind-service my-app aservice\n```\n\nHere is how you can get this service configuration in your node application:\n```js\nvar xsenv = require('@sap/xsenv');\n\nvar services = xsenv.readCFServices();\nconsole.log(services.aservice.credentials); // prints { host: '...', port: '...', user: '...', passwrod: '...', ... }\n```\n\nOften the service instance name is not known in advance. Then you can pass its name as an environment variable and use it like this:\n```js\nvar services = xsenv.readCFServices();\nvar svc = services[process.env.SERVICE_NAME];\n```\n\nAnother alternative is to lookup the service based on its metadata:\n```js\nvar svc = xsenv.cfServiceCredentials({ tag: 'hdb' });\nconsole.log(svc); // prints { host: '...', port: '...', user: '...', passwrod: '...', ... }\n```\nThis example finds a service binding with `hdb` in the tags.\nSee [Service Query](#service-query) below for description of the supported query values.\n\nYou can also look up multiple services in a single call:\n```js\nvar xsenv = require('@sap/xsenv');\n\nvar services = xsenv.getServices({\n hana: { tag: 'hdb' },\n scheduler: { label: 'jobs' }\n});\n\nvar hanaCredentials = services.hana;\nvar schedulerCredentials = services.scheduler;\n```\nThis examples finds two services - one with tag `hdb` and the other with label `jobs`.\n`getServices` function provides additional convenience that default service configuration can be provided in a JSON file.\n\nTo test the above example locally, create a file called `default-services.json` in the working directory of your application.\nThis file should contain something like this:\n```json\n{\n \"hana\": {\n \"host\": \"localhost\",\n \"port\": \"30015\",\n \"user\": \"SYSTEM\",\n \"password\": \"secret\"\n },\n \"scheduler\": {\n \"host\": \"localhost\",\n \"port\": \"4242\",\n \"user\": \"my_user\",\n \"password\": \"secret\"\n }\n}\n```\nNotice that the result property names (`hana` and `scheduler`) are the same as those in the query object and also those in `default-services.json`.\n\n[Local environment setup](#local-environment-setup) describes an alternative approach to provide service configurations for local testing.\n\n### User-Provided Service Instances\n\nWhile this package can look up any kind of bound service instances, you should be aware that [User-Provided Service Instances](https://docs.cloudfoundry.org/devguide/services/user-provided.html) have less properties than managed service instances. Here is an example:\n```json\n \"VCAP_SERVICES\": {\n \"user-provided\": [\n {\n \"name\": \"pubsub\",\n \"label\": \"user-provided\",\n \"tags\": [],\n \"credentials\": {\n \"binary\": \"pubsub.rb\",\n \"host\": \"pubsub01.example.com\",\n \"password\": \"p@29w0rd\",\n \"port\": \"1234\",\n \"username\": \"pubsubuser\"\n },\n \"syslog_drain_url\": \"\"\n\t }\n ]\n }\n```\nAs you can see the only usable property is the `name`. In particular, there are no tags for user-provided services.\n\n### Service Query\n\nBoth `getServices` and `filterCFServices` use the same service query values.\n\nQuery value | Description\n------------|------------\n{string} | Matches the service with the same service instance name (`name` property). Same as `{ name: '<string>' }`.\n{object} | All properties of the given object should match corresponding service instance properties as they appear in VCAP_SERVICES. See below.\n{function} | A function that takes a service object as argument and returns `true` only if it is considered a match\n\nIf an object is given as a query value, it may have the following properties:\n\nProperty | Description\n---------|------------\n`name` | Service instance name - the name you use to bind the service\n`label` | Service name - the name shown by `cf marketplace`\n`tag` | Should match any of the service tags\n`plan` | Service instance plan - the plan you use in `cf create-service`\n\nIf multiple properties are given, _all_ of them must match.\n\n**Note:** Do not confuse the instance name (`name` property) with service name (`label` property).\nSince you can have multiple instances of the same service bound to your app,\ninstance name is unique while service name is not.\n\nHere ar some examples.\n\nFind service instance by name:\n```js\nxsenv.cfServiceCredentials('hana');\n```\n\nLook up a service by tag:\n```js\nxsenv.cfServiceCredentials({ tag: 'relational' });\n```\n\nMatch several properties:\n```js\nxsenv.cfServiceCredentials({ label: 'hana', plan: 'shared' });\n```\n\nPass a custom filter function:\n```js\nxsenv.cfServiceCredentials(function(service) {\n return /shared/.test(service.plan) && /hdi/.test(service.label);\n});\n```\nNotice that the filter function is called with the full service object as it appears in VCAP_SERVICES, but `cfServiceCredentials` returns only the `credentials` property of the matching service.\n\n### getServices(query, [servicesFile])\n\nLooks up bound service instances matching the given query.\nIf a service is not found in VCAP_SERVICES, returns default service configuration loaded from a JSON file.\n\n* `query` - An object describing requested services. Each property value is a filter as described in [Service Query](#service-query)\n* `servicesFile` - (optional) path to JSON file to load default service configuration (default is default-services.json).\nIf `null`, do not load default service configuration.\n* _returns_ - An object with the same properties as in query argument where the value of each property is the respective service credentials object\n* _throws_ - An error, if for some of the requested services no or multiple instances are found\n\n### cfServiceCredentials(filter)\n\nLooks up a bound service instance matching the given filter.\n\n**Note:** this function does not load default service configuration from default-services.json.\n\n* `filter` - Service lookup criteria as described in [Service Query](#service-query)\n* _returns_ - Credentials object of found service\n* _throws_ - An error in case no or multiple matching services are found\n\n### filterCFServices(filter)\n\nReturns all bound services that match the given criteria.\n\n* `filter` - Service lookup criteria as described in [Service Query](#service-query)\n* _returns_ - An array of credentials objects of matching services. Empty array, if no matches found.\n\n### readCFServices()\n\nTransforms VCAP_SERVICES to an object where each service instance is mapped to its name.\n\nGiven this VCAP_SERVICES example:\n```\n {\n \"hana\" : [ {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana1\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\" ]\n },\n {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana2\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\", \"SP09\" ]\n } ]\n }\n```\n`readCFServices` would return:\n```\n{\n hana1: {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana1\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\" ]\n },\n hana2: {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana2\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\", \"SP09\" ]\n }\n}\n```\n\n## Local environment setup\n\nTo test your application locally you often need to setup its environment so that resembles the environment in Cloud Foundry.\nYou can do this easily by defining the necessary environment variables in a JSON file.\n\nFor example you can create file _default-env.json_ with the following content in the working directory of the application :\n```json\n{\n \"PORT\": 3000,\n \"VCAP_SERVICES\": {\n \"hana\": [\n {\n \"credentials\": {\n \"host\": \"myhana\",\n \"port\": \"30015\",\n \"user\": \"SYSTEM\",\n \"password\": \"secret\"\n },\n \"label\": \"hana\",\n \"name\": \"hana-R90\",\n \"tags\": [\n \"hana\",\n \"database\",\n \"relational\"\n ]\n }\n ],\n \"scheduler\": [\n {\n \"credentials\": {\n \"host\": \"localhost\",\n \"port\": \"4242\",\n \"user\": \"jobuser\",\n \"password\": \"jobpassword\"\n },\n \"label\": \"scheduler\",\n \"name\": \"jobscheduler\",\n \"tags\": [\n \"scheduler\"\n ]\n }\n ]\n }\n}\n```\nThen load it in your application:\n```js\nxsenv.loadEnv();\nconsole.log(process.env.PORT); // prints 3000\nconsole.log(xsenv.cfServiceCredentials('hana-R90')); // prints { host: 'myhana, port: '30015', user: 'SYSTEM', password: 'secret' }\n```\n\nThis way you don't need in your code conditional logic if it is running in Clod Foundry or locally.\n\nYou can also use a different file name:\n```js\nxsenv.loadEnv('myenv.json');\n```\n\n### loadEnv([file])\n\nLoads the environment from a JSON file.\nThis function converts each top-level property to a string and sets it in the respective environment variable,\nunless it is already set. This function does not change existing environment variables. So the file content acts like default values for environment variables.\n\nThis function does not complain if the file does not exist.\n\n* `file` - optional name of JSON file to load, `'default-env.json'` by default. Does nothing if the file does not exist.\n\n## Loading SSL Certificates\n\nIf SSL is configured in XSA On-Premise Runtime, it will provide one or more\ntrusted CA certificates that applications can use to make SSL connections.\nIf present, the file paths of these certificates are listed in `XS_CACERT_PATH`\nenvironment variable separated by `path.delimiter` (`:` on LINUX and `;` on Windows).\n\n### loadCertificates([certPath])\n\nLoads the certificates listed in the given path.\nIf this argument is not provided, it uses `XS_CACERT_PATH` environment variable instead.\nIf that is not set either, the function returns `undefined`.\nThe function returns an array even if a single certificate is provided.\nThis function is synchronous.\n\n* `certPath` - optional string with certificate files to load. The file names are separated by `path.delimiter`. Default is `process.env.XS_CACERT_PATH`.\n* _returns_ - an array of loaded certificates or `undefined` if `certPath` argument is not provided \n* _throws_ - an error, if some of the files could not be loaded\n\nFor example this code loads the trusted CA certificates so they are used for all\nsubsequent outgoing HTTPS connections:\n```js\nvar https = require('https');\nvar xsenv = require('@sap/xsenv');\n\nhttps.globalAgent.options.ca = xsenv.loadCertificates();\n```\n\nThis function can be used also to load SSL certificates for HANA like this:\n```js\nvar hdb = require('hdb');\nvar xsenv = require('@sap/xsenv');\n\nvar client = hdb.createClient({\n host : 'hostname',\n port : 30015,\n ca : xsenv.loadCertificates(),\n ...\n});\n```\n\n### loadCaCert()\n\n**Deprecated.** Use `loadCertificates` instead.\n\nThis function loads the certificates listed in `XS_CACERT_PATH` environment variable\ninto [https.globalAgent](https://nodejs.org/api/https.html#https_https_globalagent) of Node.js.\nAll subsequent outgoing HTTPS connections will use these certificates to verify the certificate\nof the remote host. The verification should be successful if the certificate of the\nremote host is signed (directly or via some intermediary) by some of these trusted\ncertificates.\n\nIt is suggested to call this function once during the application startup.\n\n```js\nxsenv.loadCaCert();\n```\n\nIf `XS_CACERT_PATH` variable is not set, the function does nothing.\nThis function is synchronous.\nIt will throw an error if it cannot load some of the certificates.\n\n## Debugging\n\nSet `DEBUG=xsenv` in the environment to enable debug traces. See [debug](https://www.npmjs.com/package/debug) package for details.\n","readmeFilename":"README.md","repository":{},"scripts":{"lint":"eslint -c node_modules/node-style/.eslintrc -f stylish lib/","prepareRelease":"clean-packages && npm prune --production","test":"make test"},"version":"1.2.6","license":"SEE LICENSE IN developer-license-3.1.txt"}
{"dependencies":{"debug":"2.6.7","verror":"1.10.0"},"description":"Utility for easy setup and access of SAP HANA XS Advanced environment variables","devDependencies":{"eslint":"3.2.2","filter-node-package":"^2.0.0","istanbul":"0.4.4","lodash":"4.17.4","mocha":"3.0.2","node-style":"^2.0.0","should":"10.0.0"},"engines":{"node":"^0.12.7 || ^4.4.0 || ^6.0.0"},"main":"index.js","maintainers":[{"name":"https-support.sap.com","email":"do-not-reply@sap.com"}],"name":"@sap/xsenv","optionalDependencies":{},"readme":"# @sap/xsenv\n\nUtility for easy setup and access of environment variables and services in Cloud Foundry and XSA.\n\nApplications in Cloud Foundry take various configurations from the environment.\nFor example Cloud Foundry provides properties of bound services in [VCAP_SERVICES](http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES) environment variable.\n\nTo test locally you need to provide these configurations by yourself. This package allows you to provide default configurations in a separate configuration file.\n* This reduces clutter by removing configuration data from the app code.\n* You don't have to set env vars manually each time you start your app.\n* Different developers can use their own configurations for their local tests without changing files under source control. Just add this configuration file to `.gitignore` and `.cfignore`.\n\nYou can provide default configurations on two levels:\n* For Cloud Foundry services via `getServices()` and `default-services.json`\n* For any environment variable via `loadEnv()` and `default-env.json`\n\nWhile here we often reference Cloud Foundry, it all applies also to SAP HANA XS Advanced On-premise Runtime which emulates Cloud Foundry as much as possible.\n\n## Install\n\n```sh\nnpm install --save @sap/xsenv\n```\n\n## Service Lookup\n\nNormally in Cloud Foundry you bind a service instance to your application with a command like this one:\n```sh\ncf bind-service my-app aservice\n```\n\nHere is how you can get this service configuration in your node application:\n```js\nvar xsenv = require('@sap/xsenv');\n\nvar services = xsenv.readCFServices();\nconsole.log(services.aservice.credentials); // prints { host: '...', port: '...', user: '...', passwrod: '...', ... }\n```\n\nOften the service instance name is not known in advance. Then you can pass its name as an environment variable and use it like this:\n```js\nvar services = xsenv.readCFServices();\nvar svc = services[process.env.SERVICE_NAME];\n```\n\nAnother alternative is to lookup the service based on its metadata:\n```js\nvar svc = xsenv.cfServiceCredentials({ tag: 'hdb' });\nconsole.log(svc); // prints { host: '...', port: '...', user: '...', passwrod: '...', ... }\n```\nThis example finds a service binding with `hdb` in the tags.\nSee [Service Query](#service-query) below for description of the supported query values.\n\nYou can also look up multiple services in a single call:\n```js\nvar xsenv = require('@sap/xsenv');\n\nvar services = xsenv.getServices({\n hana: { tag: 'hdb' },\n scheduler: { label: 'jobs' }\n});\n\nvar hanaCredentials = services.hana;\nvar schedulerCredentials = services.scheduler;\n```\nThis examples finds two services - one with tag `hdb` and the other with label `jobs`.\n`getServices` function provides additional convenience that default service configuration can be provided in a JSON file.\n\nTo test the above example locally, create a file called `default-services.json` in the working directory of your application.\nThis file should contain something like this:\n```json\n{\n \"hana\": {\n \"host\": \"localhost\",\n \"port\": \"30015\",\n \"user\": \"SYSTEM\",\n \"password\": \"secret\"\n },\n \"scheduler\": {\n \"host\": \"localhost\",\n \"port\": \"4242\",\n \"user\": \"my_user\",\n \"password\": \"secret\"\n }\n}\n```\nNotice that the result property names (`hana` and `scheduler`) are the same as those in the query object and also those in `default-services.json`.\n\n[Local environment setup](#local-environment-setup) describes an alternative approach to provide service configurations for local testing.\n\n### User-Provided Service Instances\n\nWhile this package can look up any kind of bound service instances, you should be aware that [User-Provided Service Instances](https://docs.cloudfoundry.org/devguide/services/user-provided.html) have less properties than managed service instances. Here is an example:\n```json\n \"VCAP_SERVICES\": {\n \"user-provided\": [\n {\n \"name\": \"pubsub\",\n \"label\": \"user-provided\",\n \"tags\": [],\n \"credentials\": {\n \"binary\": \"pubsub.rb\",\n \"host\": \"pubsub01.example.com\",\n \"password\": \"p@29w0rd\",\n \"port\": \"1234\",\n \"username\": \"pubsubuser\"\n },\n \"syslog_drain_url\": \"\"\n\t }\n ]\n }\n```\nAs you can see the only usable property is the `name`. In particular, there are no tags for user-provided services.\n\n### Service Query\n\nBoth `getServices` and `filterCFServices` use the same service query values.\n\nQuery value | Description\n------------|------------\n{string} | Matches the service with the same service instance name (`name` property). Same as `{ name: '<string>' }`.\n{object} | All properties of the given object should match corresponding service instance properties as they appear in VCAP_SERVICES. See below.\n{function} | A function that takes a service object as argument and returns `true` only if it is considered a match\n\nIf an object is given as a query value, it may have the following properties:\n\nProperty | Description\n---------|------------\n`name` | Service instance name - the name you use to bind the service\n`label` | Service name - the name shown by `cf marketplace`\n`tag` | Should match any of the service tags\n`plan` | Service instance plan - the plan you use in `cf create-service`\n\nIf multiple properties are given, _all_ of them must match.\n\n**Note:** Do not confuse the instance name (`name` property) with service name (`label` property).\nSince you can have multiple instances of the same service bound to your app,\ninstance name is unique while service name is not.\n\nHere ar some examples.\n\nFind service instance by name:\n```js\nxsenv.cfServiceCredentials('hana');\n```\n\nLook up a service by tag:\n```js\nxsenv.cfServiceCredentials({ tag: 'relational' });\n```\n\nMatch several properties:\n```js\nxsenv.cfServiceCredentials({ label: 'hana', plan: 'shared' });\n```\n\nPass a custom filter function:\n```js\nxsenv.cfServiceCredentials(function(service) {\n return /shared/.test(service.plan) && /hdi/.test(service.label);\n});\n```\nNotice that the filter function is called with the full service object as it appears in VCAP_SERVICES, but `cfServiceCredentials` returns only the `credentials` property of the matching service.\n\n### getServices(query, [servicesFile])\n\nLooks up bound service instances matching the given query.\nIf a service is not found in VCAP_SERVICES, returns default service configuration loaded from a JSON file.\n\n* `query` - An object describing requested services. Each property value is a filter as described in [Service Query](#service-query)\n* `servicesFile` - (optional) path to JSON file to load default service configuration (default is default-services.json).\nIf `null`, do not load default service configuration.\n* _returns_ - An object with the same properties as in query argument where the value of each property is the respective service credentials object\n* _throws_ - An error, if for some of the requested services no or multiple instances are found\n\n### cfServiceCredentials(filter)\n\nLooks up a bound service instance matching the given filter.\n\n**Note:** this function does not load default service configuration from default-services.json.\n\n* `filter` - Service lookup criteria as described in [Service Query](#service-query)\n* _returns_ - Credentials object of found service\n* _throws_ - An error in case no or multiple matching services are found\n\n### filterCFServices(filter)\n\nReturns all bound services that match the given criteria.\n\n* `filter` - Service lookup criteria as described in [Service Query](#service-query)\n* _returns_ - An array of credentials objects of matching services. Empty array, if no matches found.\n\n### readCFServices()\n\nTransforms VCAP_SERVICES to an object where each service instance is mapped to its name.\n\nGiven this VCAP_SERVICES example:\n```\n {\n \"hana\" : [ {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana1\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\" ]\n },\n {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana2\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\", \"SP09\" ]\n } ]\n }\n```\n`readCFServices` would return:\n```\n{\n hana1: {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana1\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\" ]\n },\n hana2: {\n \"credentials\" : {\n ...\n },\n \"label\" : \"hana\",\n \"name\" : \"hana2\",\n \"plan\" : \"shared\",\n \"tags\" : [ \"hana\", \"relational\", \"SP09\" ]\n }\n}\n```\n\n## Local environment setup\n\nTo test your application locally you often need to setup its environment so that resembles the environment in Cloud Foundry.\nYou can do this easily by defining the necessary environment variables in a JSON file.\n\nFor example you can create file _default-env.json_ with the following content in the working directory of the application :\n```json\n{\n \"PORT\": 3000,\n \"VCAP_SERVICES\": {\n \"hana\": [\n {\n \"credentials\": {\n \"host\": \"myhana\",\n \"port\": \"30015\",\n \"user\": \"SYSTEM\",\n \"password\": \"secret\"\n },\n \"label\": \"hana\",\n \"name\": \"hana-R90\",\n \"tags\": [\n \"hana\",\n \"database\",\n \"relational\"\n ]\n }\n ],\n \"scheduler\": [\n {\n \"credentials\": {\n \"host\": \"localhost\",\n \"port\": \"4242\",\n \"user\": \"jobuser\",\n \"password\": \"jobpassword\"\n },\n \"label\": \"scheduler\",\n \"name\": \"jobscheduler\",\n \"tags\": [\n \"scheduler\"\n ]\n }\n ]\n }\n}\n```\nThen load it in your application:\n```js\nxsenv.loadEnv();\nconsole.log(process.env.PORT); // prints 3000\nconsole.log(xsenv.cfServiceCredentials('hana-R90')); // prints { host: 'myhana, port: '30015', user: 'SYSTEM', password: 'secret' }\n```\n\nThis way you don't need in your code conditional logic if it is running in Clod Foundry or locally.\n\nYou can also use a different file name:\n```js\nxsenv.loadEnv('myenv.json');\n```\n\n### loadEnv([file])\n\nLoads the environment from a JSON file.\nThis function converts each top-level property to a string and sets it in the respective environment variable,\nunless it is already set. This function does not change existing environment variables. So the file content acts like default values for environment variables.\n\nThis function does not complain if the file does not exist.\n\n* `file` - optional name of JSON file to load, `'default-env.json'` by default. Does nothing if the file does not exist.\n\n## Loading SSL Certificates\n\nIf SSL is configured in XSA On-Premise Runtime, it will provide one or more\ntrusted CA certificates that applications can use to make SSL connections.\nIf present, the file paths of these certificates are listed in `XS_CACERT_PATH`\nenvironment variable separated by `path.delimiter` (`:` on LINUX and `;` on Windows).\n\n### loadCertificates([certPath])\n\nLoads the certificates listed in the given path.\nIf this argument is not provided, it uses `XS_CACERT_PATH` environment variable instead.\nIf that is not set either, the function returns `undefined`.\nThe function returns an array even if a single certificate is provided.\nThis function is synchronous.\n\n* `certPath` - optional string with certificate files to load. The file names are separated by `path.delimiter`. Default is `process.env.XS_CACERT_PATH`.\n* _returns_ - an array of loaded certificates or `undefined` if `certPath` argument is not provided \n* _throws_ - an error, if some of the files could not be loaded\n\nFor example this code loads the trusted CA certificates so they are used for all\nsubsequent outgoing HTTPS connections:\n```js\nvar https = require('https');\nvar xsenv = require('@sap/xsenv');\n\nhttps.globalAgent.options.ca = xsenv.loadCertificates();\n```\n\nThis function can be used also to load SSL certificates for HANA like this:\n```js\nvar hdb = require('hdb');\nvar xsenv = require('@sap/xsenv');\n\nvar client = hdb.createClient({\n host : 'hostname',\n port : 30015,\n ca : xsenv.loadCertificates(),\n ...\n});\n```\n\n### loadCaCert()\n\n**Deprecated.** Use `loadCertificates` instead.\n\nThis function loads the certificates listed in `XS_CACERT_PATH` environment variable\ninto [https.globalAgent](https://nodejs.org/api/https.html#https_https_globalagent) of Node.js.\nAll subsequent outgoing HTTPS connections will use these certificates to verify the certificate\nof the remote host. The verification should be successful if the certificate of the\nremote host is signed (directly or via some intermediary) by some of these trusted\ncertificates.\n\nIt is suggested to call this function once during the application startup.\n\n```js\nxsenv.loadCaCert();\n```\n\nIf `XS_CACERT_PATH` variable is not set, the function does nothing.\nThis function is synchronous.\nIt will throw an error if it cannot load some of the certificates.\n\n## Debugging\n\nSet `DEBUG=xsenv` in the environment to enable debug traces. See [debug](https://www.npmjs.com/package/debug) package for details.\n","readmeFilename":"README.md","repository":{},"scripts":{"lint":"eslint -c node_modules/node-style/.eslintrc -f stylish lib/","prepareRelease":"clean-packages && npm prune --production","test":"make test"},"version":"1.2.7","license":"SEE LICENSE IN developer-license-3.1.txt"}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc