stephenplusplus / google-auto-auth

Making it as easy as possible to authenticate a Google API request
MIT License
34 stars 9 forks source link

add environment detection helpers #8

Closed stephenplusplus closed 7 years ago

stephenplusplus commented 7 years ago

Inspired by https://github.com/GoogleCloudPlatform/google-cloud-node/pull/1808

This adds new helper methods to detect the environment an app is running in. Ideally, this will live in google-auth-library someday. At that time, these new methods can still exist, and will simply swap out where the legwork is taking place.

var auth = require('google-auto-auth')()

auth.getEnvironment(function(err, env) {
  env = {
    IS_APP_ENGINE: Boolean,
    IS_CLOUD_FUNCTION: Boolean,
    IS_COMPUTE_ENGINE: Boolean
  }
})

auth.isAppEngine(function(err, isAppEngine) {
  isAppEngine = Boolean
})

auth.isCloudFunction(function(err, isCloudFunction) {
  isCloudFunction = Boolean
})

auth.isComputeEngine(function(err, isComputeEngine) {
  isComputeEngine = Boolean
})
stephenplusplus commented 7 years ago

@jmdobry PTAL