Constructor

AssetServiceClient

new AssetServiceClient(options)

Construct an instance of AssetServiceClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Values in options have the following properties:

Parameter

credentials

Optional

object

Credentials object.

credentials.client_email

Optional

string

credentials.private_key

Optional

string

email

Optional

string

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename

Optional

string

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port

Optional

number

The port on which to connect to the remote host.

projectId

Optional

string

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise

Optional

function()

Custom promise module to use instead of native Promises.

servicePath

Optional

string

The domain name of the API remote host.

Properties

port

static

The port for this API service.

scopes

static

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static

The DNS address for this API service.

Methods

batchGetAssetsHistory

batchGetAssetsHistory(request, options, callback) returns Promise

Batch gets the update history of assets that overlap a time window. For RESOURCE content, this API outputs history with asset in both non-delete or deleted status. For IAM_POLICY content, this API outputs history when the asset and its attached IAM POLICY both exist. This can create gaps in the output history.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

Required. The relative name of the root asset. It can only be an organization number (such as "organizations/123"), a project ID (such as "projects/my-project-id")", or a project number (such as "projects/12345").

contentType

number

Required. The content type.

The number should be among the values of ContentType

readTimeWindow

Object

Optional. The time window for the asset history. Both start_time and end_time are optional and if set, it must be after 2018-10-02 UTC. If end_time is not set, it is default to current timestamp. If start_time is not set, the snapshot of the assets at end_time will be returned. The returned results contain all temporal assets whose time window overlap with read_time_window.

This object should have the same structure as TimeWindow

assetNames

Optional

Array of string

A list of the full names of the assets. For example: //compute.googleapis.com/projects/my_project_123/zones/zone1/instances/instance1. See Resource Names for more info.

The request becomes a no-op if the asset name list is empty, and the max size of the asset name list is 100 in one request.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing BatchGetAssetsHistoryResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing BatchGetAssetsHistoryResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const asset = require('asset.v1beta1');

const client = new asset.v1beta1.AssetServiceClient({
  // optional auth parameters.
});

const formattedParent = client.projectPath('[PROJECT]');
const contentType = 'CONTENT_TYPE_UNSPECIFIED';
const readTimeWindow = {};
const request = {
  parent: formattedParent,
  contentType: contentType,
  readTimeWindow: readTimeWindow,
};
client.batchGetAssetsHistory(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

exportAssets

exportAssets(request, options, callback) returns Promise

Exports assets with time and resource types to a given Cloud Storage location. The output format is newline-delimited JSON. This API implements the google.longrunning.Operation API allowing you to keep track of the export.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

Required. The relative name of the root asset. This can only be an organization number (such as "organizations/123"), a project ID (such as "projects/my-project-id"), a project number (such as "projects/12345"), or a folder number (such as "folders/123").

outputConfig

Object

Required. Output configuration indicating where the results will be output to. All results will be in newline delimited JSON format.

This object should have the same structure as OutputConfig

readTime

Optional

Object

Timestamp to take an asset snapshot. This can only be set to a timestamp between 2018-10-02 UTC (inclusive) and the current time. If not specified, the current time will be used. Due to delays in resource data collection and indexing, there is a volatile window during which running the same query may get different results.

This object should have the same structure as Timestamp

assetTypes

Optional

Array of string

A list of asset types of which to take a snapshot for. For example: "google.compute.Disk". If specified, only matching assets will be returned. See Introduction to Cloud Asset Inventory for all supported asset types.

contentType

Optional

number

Asset content type. If not specified, no content but the asset name will be returned.

The number should be among the values of ContentType

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is a gax.Operation object.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is a gax.Operation object. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const asset = require('asset.v1beta1');

const client = new asset.v1beta1.AssetServiceClient({
  // optional auth parameters.
});

const formattedParent = client.projectPath('[PROJECT]');
const outputConfig = {};
const request = {
  parent: formattedParent,
  outputConfig: outputConfig,
};

// Handle the operation using the promise pattern.
client.exportAssets(request)
  .then(responses => {
    const [operation, initialApiResponse] = responses;

    // Operation#promise starts polling for the completion of the LRO.
    return operation.promise();
  })
  .then(responses => {
    const result = responses[0];
    const metadata = responses[1];
    const finalApiResponse = responses[2];
  })
  .catch(err => {
    console.error(err);
  });

const formattedParent = client.projectPath('[PROJECT]');
const outputConfig = {};
const request = {
  parent: formattedParent,
  outputConfig: outputConfig,
};

// Handle the operation using the event emitter pattern.
client.exportAssets(request)
  .then(responses => {
    const [operation, initialApiResponse] = responses;

    // Adding a listener for the "complete" event starts polling for the
    // completion of the operation.
    operation.on('complete', (result, metadata, finalApiResponse) => {
      // doSomethingWith(result);
    });

    // Adding a listener for the "progress" event causes the callback to be
    // called on any change in metadata when the operation is polled.
    operation.on('progress', (metadata, apiResponse) => {
      // doSomethingWith(metadata)
    });

    // Adding a listener for the "error" event handles any errors found during polling.
    operation.on('error', err => {
      // throw(err);
    });
  })
  .catch(err => {
    console.error(err);
  });

const formattedParent = client.projectPath('[PROJECT]');
const outputConfig = {};
const request = {
  parent: formattedParent,
  outputConfig: outputConfig,
};

// Handle the operation using the await pattern.
const [operation] = await client.exportAssets(request);

const [response] = await operation.promise();

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.

matchProjectFromProjectName

matchProjectFromProjectName(projectName) returns String

Parse the projectName from a project resource.

Parameter

projectName

String

A fully-qualified path representing a project resources.

Returns

String 

  • A string representing the project.

projectPath

projectPath(project) returns String

Return a fully-qualified project resource name string.

Parameter

project

String

Returns

String