Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cloud-functions-runtime-config

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloud-functions-runtime-config

This is a wrapper around Google API Client to read Runtime Config variables in Cloud Functions.

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Cloud Functions Runtime Config

This is a wrapper around Google API Client to read Runtime Config variables in Cloud Functions.

Note: Runtime Config is currently in beta so things might break!

Installation

npm install --save cloud-functions-runtime-config

Usage

const runtimeConfig = require('cloud-functions-runtime-config');
const lunchPlans = runtimeConfig.getVariable('dev-config', 'lunch-plans');

exports.lunchPlanner = (req, res) => {
    return lunchPlans
        .then((val) => {
            console.log(val);
            res.status(200).send(val);
        })
        .catch((err) => {
            console.error(err);
            res.status(500).send(err);
        });
};

Basic example

Enable the RuntimeConfig API

Either using the API Manager in Cloud Console or using gcloud:

gcloud service-management enable runtimeconfig.googleapis.com
Config setup

Create a config resource and store a variable in it.

gcloud beta runtime-config configs create dev-config
gcloud beta runtime-config configs variables \
    set lunch-plans "lets go for a hamburger!" \
    --config-name dev-config
Cloud Function

A basic HTTP Function that returns the variable value.

const runtimeConfig = require('cloud-functions-runtime-config');
const lunchPlans = runtimeConfig.getVariable('dev-config', 'lunch-plans');

exports.lunchPlanner = (req, res) => {
    return lunchPlans
        .then((val) => res.status(200).send(val))
        .catch((err) => res.status(500).send(err));
};

Deploying the Function with an HTTP trigger:

gcloud beta functions deploy lunchPlanner \
    --trigger-http \
    --stage-bucket=<YOUR-BUCKET>

Test the Function:

curl https://us-central1-$(gcloud config get-value core/project).cloudfunctions.net/lunchPlanner
Cleanup
gcloud beta runtime-config configs delete dev-config
gcloud beta functions delete lunchPlanner

API

runtimeConfig.getVariable(config, variable)

Returns a Promise that is either resolved to the value read from Runtime Config or rejected if the variable could not be read.

config

Type: string

variable

Type: string

runtimeConfig.getVariables(config, variables)

Returns a Promise that is either resolved to an Array of values or rejected if any of the variables could not be read. The values are returned in the same order as the variableNames.

config

Type: string

variables

Type: Array<string>

License

The MIT License (MIT)

Keywords

FAQs

Package last updated on 16 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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