|
| 1 | +/* |
| 2 | + * Copyright 2018 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.asset; |
| 18 | + |
| 19 | +// [START asset_quickstart_batch_get_assets_history] |
| 20 | +// Imports the Google Cloud client library |
| 21 | + |
| 22 | +import com.google.cloud.ServiceOptions; |
| 23 | +import com.google.cloud.asset.v1beta1.AssetServiceClient; |
| 24 | +import com.google.cloud.asset.v1beta1.BatchGetAssetsHistoryRequest; |
| 25 | +import com.google.cloud.asset.v1beta1.BatchGetAssetsHistoryResponse; |
| 26 | +import com.google.cloud.asset.v1beta1.ContentType; |
| 27 | +import com.google.cloud.asset.v1beta1.ProjectName; |
| 28 | +import com.google.cloud.asset.v1beta1.TimeWindow; |
| 29 | +import java.util.Arrays; |
| 30 | + |
| 31 | +public class BatchGetAssetsHistoryExample { |
| 32 | + |
| 33 | + // Use the default project Id. |
| 34 | + private static final String projectId = ServiceOptions.getDefaultProjectId(); |
| 35 | + |
| 36 | + // Export assets for a project. |
| 37 | + // @param args path where the results will be exported to. |
| 38 | + public static void main(String... args) throws Exception { |
| 39 | + // Asset names, e.g.: "//storage.googleapis.com/[BUCKET_NAME]" |
| 40 | + String[] assetNames = args[0].split(","); |
| 41 | + try (AssetServiceClient client = AssetServiceClient.create()) { |
| 42 | + ProjectName parent = ProjectName.of(projectId); |
| 43 | + ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED; |
| 44 | + TimeWindow readTimeWindow = TimeWindow.newBuilder().build(); |
| 45 | + BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() |
| 46 | + .setParent(parent.toString()) |
| 47 | + .addAllAssetNames(Arrays.asList(assetNames)) |
| 48 | + .setContentType(contentType) |
| 49 | + .setReadTimeWindow(readTimeWindow) |
| 50 | + .build(); |
| 51 | + BatchGetAssetsHistoryResponse response = client.batchGetAssetsHistory(request); |
| 52 | + System.out.println(response); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | +// [END asset_quickstart_batch_get_assets_history] |
0 commit comments