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.
Use the following require statement:
1const vault = require('vault');
The module exposes one method: get(secretKey)
. It returns a Promise.
This example retrieves an API key and uses it in an authenticated XHR request.
This is an OnRequest
Function.
1export default (request, response) => {
2 const xhr = require('xhr');
3 const vault = require('vault');
4
5 return vault.get("myApiKey").then((apiKey) => {
6 const http_options = {
7 "method": "GET",
8 "headers": {
9 "API_KEY": apiKey
10 }
11 };
12 return xhr.fetch("https://httpbin.org/get", http_options).then((resp) => {
13 console.log(resp);
14 return response.send("OK");
15 });
show all 17 linesFunctions support
Functions provides a rich set of tools. For help with cases not covered here, please contact PubNub Support.