Search in sources :

Example 51 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.

the class UpdateFeedExample method updateFeed.

// Update a feed
public static void updateFeed(String feedName, String topic) throws Exception {
    // String feedName = "MY_FEED_NAME"
    // String topic = "projects/[PROJECT_ID]/topics/[TOPIC_NAME]"
    Feed feed = Feed.newBuilder().setName(feedName).setFeedOutputConfig(FeedOutputConfig.newBuilder().setPubsubDestination(PubsubDestination.newBuilder().setTopic(topic).build()).build()).build();
    UpdateFeedRequest request = UpdateFeedRequest.newBuilder().setFeed(feed).setUpdateMask(FieldMask.newBuilder().addPaths("feed_output_config.pubsub_destination.topic").build()).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        Feed response = client.updateFeed(request);
        System.out.println("Feed updated successfully: " + response.getName());
    } catch (Exception e) {
        System.out.println("Error during UpdateFeed: \n" + e.toString());
    }
}
Also used : UpdateFeedRequest(com.google.cloud.asset.v1.UpdateFeedRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Example 52 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.

the class BatchGetAssetsHistoryExample method main.

// Export assets for a project.
// @param args path where the results will be exported to.
public static void main(String... args) throws Exception {
    // Asset names, e.g.: "//storage.googleapis.com/[BUCKET_NAME]"
    String[] assetNames = args[0].split(",");
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED;
        TimeWindow readTimeWindow = TimeWindow.newBuilder().build();
        BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder().setParent(parent.toString()).addAllAssetNames(Arrays.asList(assetNames)).setContentType(contentType).setReadTimeWindow(readTimeWindow).build();
        BatchGetAssetsHistoryResponse response = client.batchGetAssetsHistory(request);
        System.out.println(response);
    }
}
Also used : ContentType(com.google.cloud.asset.v1.ContentType) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) BatchGetAssetsHistoryRequest(com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest) BatchGetAssetsHistoryResponse(com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse) TimeWindow(com.google.cloud.asset.v1.TimeWindow)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)52 Feed (com.google.cloud.asset.v1.Feed)13 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 ApiException (com.google.api.gax.rpc.ApiException)5 AnalyzeIamPolicyLongrunningRequest (com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest)5 ExportAssetsRequest (com.google.cloud.asset.v1.ExportAssetsRequest)5 ExportAssetsResponse (com.google.cloud.asset.v1.ExportAssetsResponse)4 ListFeedsResponse (com.google.cloud.asset.v1.ListFeedsResponse)4 ProjectName (com.google.cloud.asset.v1.ProjectName)4 AnalyzeIamPolicyRequest (com.google.cloud.asset.v1.AnalyzeIamPolicyRequest)3 AnalyzeIamPolicyResponse (com.google.cloud.asset.v1.AnalyzeIamPolicyResponse)3 CreateFeedRequest (com.google.cloud.asset.v1.CreateFeedRequest)3 IamPolicyAnalysisQuery (com.google.cloud.asset.v1.IamPolicyAnalysisQuery)3 Options (com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options)3 ResourceSelector (com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector)3 IamPolicySearchResult (com.google.cloud.asset.v1.IamPolicySearchResult)3 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)3 ResourceSearchResult (com.google.cloud.asset.v1.ResourceSearchResult)3 SearchAllIamPoliciesRequest (com.google.cloud.asset.v1.SearchAllIamPoliciesRequest)3