Exemplo n.º 1
0
Entry.prototype.toJSON = function() {
  if (is.object(this.data) && isCircular([this.data])) {
    throw new Error('The JSON data for this entry has a circular reference.');
  }

  var entry = extend(true, {}, this.metadata);

  if (is.object(this.data)) {
    entry.jsonPayload = common.GrpcService.objToStruct_(this.data, {
      stringify: true
    });
  } else if (is.string(this.data)) {
    entry.textPayload = this.data;
  }

  if (is.date(entry.timestamp)) {
    var seconds = entry.timestamp.getTime() / 1000;
    var secondsRounded = Math.floor(seconds);

    entry.timestamp = {
      seconds: secondsRounded,
      nanos: Math.floor((seconds - secondsRounded) * 1e9)
    };
  }

  return entry;
};
Exemplo n.º 2
0
/*! Developer Documentation
 *
 * @param {module:pubsub} pubsub - PubSub Object.
 * @param {object} config - Configuration object.
 * @param {string} config.baseUrl - The base URL to apply to API requests.
 * @param {string} config.id - The name of the topic or subscription.
 */
/**
 * [IAM (Identity and Access Management)](https://cloud.google.com/pubsub/access_control)
 * allows you to set permissions on invidual resources and offers a wider range
 * of roles: editor, owner, publisher, subscriber, and viewer. This gives you
 * greater flexibility and allows you to set more fine-grained access control.
 *
 * For example:
 *   * Grant access on a per-topic or per-subscription basis, rather than for
 *     the whole Cloud project.
 *   * Grant access with limited capabilities, such as to only publish messages
 *     to a topic, or to only to consume messages from a subscription, but not
 *     to delete the topic or subscription.
 *
 *
 * *The IAM access control features described in this document are Beta,
 * including the API methods to get and set IAM policies, and to test IAM
 * permissions. Google Cloud Pub/Sub's use of IAM features is not covered by any
 * SLA or deprecation policy, and may be subject to backward-incompatible
 * changes.*
 *
 * @constructor
 * @alias module:pubsub/iam
 *
 * @resource [Access Control Overview]{@link https://cloud.google.com/pubsub/access_control}
 * @resource [What is Cloud IAM?]{@link https://cloud.google.com/iam/}
 *
 * @example
 * var topic = pubsub.topic('my-topic');
 * // topic.iam
 *
 * var subscription = pubsub.subscription('my-subscription');
 * // subscription.iam
 */
function IAM(pubsub, id) {
  var config = {
    baseUrl: pubsub.defaultBaseUrl_,
    service: 'iam',
    apiVersion: 'v1',
    scopes: [
      'https://www.googleapis.com/auth/pubsub',
      'https://www.googleapis.com/auth/cloud-platform'
    ],
    packageJson: require('../package.json')
  };

  this.id = id;

  common.GrpcService.call(this, config, pubsub.options);
}
Exemplo n.º 3
0
      data.entries.forEach(function(entry) {
        // mutation was successful, no need to notify the user
        if (entry.status.code === 0) {
          return;
        }

        var status = common.GrpcService.decorateStatus_(entry.status);
        status.entry = entries[entry.index];


        if (!isCallbackMode) {
          emitter.emit('error', status);
          return;
        }

        throughStream.push(status);
      });
Exemplo n.º 4
0
Entry.fromApiResponse_ = function(entry) {
  var data = entry[entry.payload];

  if (entry.payload === 'jsonPayload') {
    data = common.GrpcService.structToObj_(data);
  }

  var serializedEntry = new Entry(entry, data);

  if (serializedEntry.metadata.timestamp) {
    var ms = serializedEntry.metadata.timestamp.seconds * 1000;
    ms += serializedEntry.metadata.timestamp.nanos / 1e6;
    serializedEntry.metadata.timestamp = new Date(ms);
  }

  return serializedEntry;
};
Exemplo n.º 5
0
Entry.prototype.toJSON = function() {
  var entry = extend(true, {}, this);

  var whitelist = [
    'logName',
    'resource',
    'timestamp',
    'severity',
    'insertId',
    'httpRequest',
    'labels',
    'operation'
  ];

  for (var prop in entry) {
    if (whitelist.indexOf(prop) === -1) {
      delete entry[prop];
    }
  }

  if (is.string(this.resource)) {
    entry.resource = {
      type: this.resource
    };
  }

  if (is.object(this.data)) {
    entry.jsonPayload = common.GrpcService.objToStruct_(this.data, {
      stringify: true
    });
  } else if (is.string(this.data)) {
    entry.textPayload = this.data;
  }

  if (is.date(entry.timestamp)) {
    var seconds = entry.timestamp.getTime() / 1000;
    var secondsRounded = Math.floor(seconds);

    entry.timestamp = {
      seconds: secondsRounded,
      nanos: Math.floor((seconds - secondsRounded) * 1e9)
    };
  }

  return entry;
};
Exemplo n.º 6
0
/**
 * [Google Cloud Logging](https://cloud.google.com/logging/docs) collects and
 * stores logs from applications and services on the Google Cloud Platform:
 *
 *   - Export your logs to Google Cloud Storage, Google BigQuery, or Google
 *     Cloud Pub/Sub.
 *   - Integrate third-party logs from your virtual machine instances by
 *     installing the logging agent, `google-fluentd`.
 *
 * @alias module:logging
 * @constructor
 *
 * @classdesc
 * <p class="notice">
 *   **This is a Beta release of Google Cloud Logging.** This API is not covered
 *   by any SLA or deprecation policy and may be subject to
 *   backward-incompatible changes.
 * </p>
 *
 * The `gcloud.logging` method will return a `logging` object, allowing you to
 * create sinks, write log entries, and more.
 *
 * To learn more about Logging, see the
 * [What is Google Cloud Logging?](https://cloud.google.com/logging/docs)
 *
 * @resource [What is Google Cloud Logging?]{@link https://cloud.google.com/logging/docs}
 * @resource [Introduction to the Cloud Logging API]{@link https://cloud.google.com/logging/docs/api}
 *
 * @param {object} options - [Configuration object](#/docs).
 *
 * @example
 * var gcloud = require('google-cloud')({
 *   keyFilename: '/path/to/keyfile.json',
 *   projectId: 'grape-spaceship-123'
 * });
 *
 * var logging = gcloud.logging();
 */
function Logging(options) {
  if (!(this instanceof Logging)) {
    options = common.util.normalizeArguments(this, options);
    return new Logging(options);
  }

  var config = {
    baseUrl: 'logging.googleapis.com',
    service: 'logging',
    apiVersion: 'v2',
    protoServices: {
      ConfigServiceV2:
        googleProtoFiles('logging', 'v2', 'logging_config.proto'),
      LoggingServiceV2: googleProtoFiles.logging.v2
    },
    scopes: [
      'https://www.googleapis.com/auth/cloud-platform'
    ],
    userAgent: PKG.name + '/' + PKG.version
  };

  common.GrpcService.call(this, config, options);
}
Exemplo n.º 7
0
/**
 * <p class="notice">
 *   **This is a Beta release of Google Cloud Natural Language.** This API is
 *   not covered by any SLA or deprecation policy and may be subject to
 *   backward-incompatible changes.
 * </p>
 *
 * The [Google Cloud Natural Language](https://cloud.google.com/natural-language/docs)
 * API provides natural language understanding technologies to developers,
 * including sentiment analysis, entity recognition, and syntax analysis. This
 * API is part of the larger Cloud Machine Learning API.
 *
 * The Cloud Natural Language API currently supports English for
 * [sentiment analysis](https://cloud.google.com/natural-language/docs/reference/rest/v1beta1/documents/analyzeSentiment)
 * and English, Spanish, and Japanese for
 * [entity analysis](https://cloud.google.com/natural-language/docs/reference/rest/v1beta1/documents/analyzeEntities)
 * and
 * [syntax analysis](https://cloud.google.com/natural-language/docs/reference/rest/v1beta1/documents/annotateText).
 *
 * @constructor
 * @alias module:language
 *
 * @resource [Google Cloud Natural Language API Documentation]{@link https://cloud.google.com/natural-language/docs}
 *
 * @param {object} options - [Configuration object](#/docs).
 */
function Language(options) {
  if (!(this instanceof Language)) {
    options = common.util.normalizeArguments(this, options);
    return new Language(options);
  }

  var config = {
    baseUrl: 'language.googleapis.com',
    service: 'language',
    apiVersion: 'v1beta1',
    protoServices: {
      LanguageService: {
        path: googleProtoFiles.language.v1beta1,
        service: 'cloud.language'
      }
    },
    scopes: [
      'https://www.googleapis.com/auth/cloud-platform'
    ],
    userAgent: PKG.name + '/' + PKG.version
  };

  common.GrpcService.call(this, config, options);
}
Exemplo n.º 8
0
function FakeGrpcService() {
  this.calledWith_ = arguments;
  GrpcService.apply(this, arguments);
}