PubNub FunctionsVault Module

Vault module provides access to the secrets stored in your secret store. Vault only allows retrieval of the unencrypted value of your secrets. It does not allow storing new secrets in the secret store or modifying the value of existing secrets. In order to store new secrets please go to the Functions editor page and look for MY SECRETS.

The Vault module is made available with the following require statement:

const vault = require('vault');

Vault module provides a single method: get(<secretKey>). Consistent with the other Functions modules, this method returns a Promise.

The following example shows how to retrieve a securely stored API key from the secret store in order to make an authenticated XHR request to another service with it.

Note that the following Function is of OnRequest type.

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");
        });
    });
};