How to use the google-auth-library.GCPEnv.CLOUD_FUNCTIONS function in google-auth-library

To help you get started, we’ve selected a few google-auth-library examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-logging-bunyan / test / middleware / test-express.ts View on Github external
assert.strictEqual(passedOptions.length, 2);
    assert.ok(
      passedOptions.some(
        option => option!.logName === `${LOGNAME}_${APP_LOG_SUFFIX}`
      )
    );
    assert.ok(passedOptions.some(option => option!.logName === LOGNAME));
    assert.ok(passedOptions.every(option => option!.level === LEVEL));
  });

  it('should acquire the projectId and pass to makeMiddleware', async () => {
    await middleware();
    assert.strictEqual(passedProjectId, FAKE_PROJECT_ID);
  });

  [GCPEnv.APP_ENGINE, GCPEnv.CLOUD_FUNCTIONS].forEach(env => {
    it(`should not generate the request logger on ${env}`, async () => {
      authEnvironment = env;
      await middleware();
      assert.ok(passedOptions);
      assert.strictEqual(passedOptions.length, 1);
      // emitRequestLog parameter to makeChildLogger should be undefined.
      assert.strictEqual(passedEmitRequestLog, undefined);
    });
  });
});
github googleapis / nodejs-logging-bunyan / src / middleware / express.ts View on Github external
name: `${options.logName}_${APP_LOG_SUFFIX}`,
    streams: [loggingBunyanApp.stream(options.level as types.LogLevel)],
  });

  const auth = loggingBunyanApp.stackdriverLog.logging.auth;
  const [env, projectId] = await Promise.all([
    auth.getEnv(),
    auth.getProjectId(),
  ]);

  // Unless we are running on Google App Engine or Cloud Functions, generate a
  // parent request log entry that all the request-specific logs ("app logs")
  // will nest under. GAE and GCF generate the parent request logs
  // automatically.
  let emitRequestLog;
  if (env !== GCPEnv.APP_ENGINE && env !== GCPEnv.CLOUD_FUNCTIONS) {
    const loggingBunyanReq = new LoggingBunyan(options);
    const requestLogger = bunyan.createLogger({
      name: options.logName!,
      streams: [loggingBunyanReq.stream(options.level as types.LogLevel)],
    });
    emitRequestLog = (httpRequest: HttpRequest, trace: string) => {
      requestLogger.info({[LOGGING_TRACE_KEY]: trace, httpRequest});
    };
  }

  return {
    logger,
    mw: commonMiddleware.express.makeMiddleware(
      projectId,
      makeChildLogger,
      emitRequestLog
github googleapis / nodejs-logging / src / metadata.ts View on Github external
export async function detectServiceContext(
  auth: GoogleAuth
): Promise {
  const env = await auth.getEnv();
  switch (env) {
    case GCPEnv.APP_ENGINE:
      return {
        service: process.env.GAE_SERVICE || process.env.GAE_MODULE_NAME,
        version: process.env.GAE_VERSION || process.env.GAE_MODULE_VERSION,
      };
    case GCPEnv.CLOUD_FUNCTIONS:
      return {
        service: process.env.FUNCTION_NAME,
      };
    // One Kubernetes we probably need to use the pod-name to describe the
    // service. Currently there isn't a universal way to acquire the pod
    // name from within the pod.
    case GCPEnv.KUBERNETES_ENGINE:
    case GCPEnv.COMPUTE_ENGINE:
    default:
      return null;
  }
}
github googleapis / nodejs-logging / test / metadata.ts View on Github external
async getEnv() {
              return GCPEnv.CLOUD_FUNCTIONS;
            },
          };