Vault Module
The vault
module gives you secure access to secrets. It returns the decrypted value during Function execution. Secrets are encrypted at rest and decrypted only during execution.
Add or manage secrets in the Functions UI:
- Functions v1: Open the Functions editor and select My secrets.
- Functions v2: Open the Package Revision that contains your Function and select Assign secrets.
Manage secrets in Admin Portal
You can also manage secrets on the Keyset page of the Admin Portal.
Use the following require()
statement:
const vault = require('vault');
The module exposes one method: get(secretKey)
. It returns a Promise. If the secret is missing, the Promise rejects.
This example retrieves an API key and uses it in an authenticated XHR request.
This is an On Request
Function.
export default (request, response) => {
const xhr = require('xhr');
const vault = require('vault');
return vault.get("myApiKey").then((apiKey) => {
const http_options = {
"method": "GET",
"headers": {
"API_KEY": apiKey
}
};
return xhr.fetch("https://httpbin.org/get", http_options).then((resp) => {
console.log(resp);
return response.send("OK");
});
show all 17 linesFunctions support
Functions provides a rich set of tools. For help with cases not covered here, please contact PubNub Support.