Search in sources :

Example 46 with AssetServiceClient

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

the class AsyncSearchAllResourcesPaged method asyncSearchAllResourcesPaged.

public static void asyncSearchAllResourcesPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        SearchAllResourcesRequest request = SearchAllResourcesRequest.newBuilder().setScope("scope109264468").setQuery("query107944136").addAllAssetTypes(new ArrayList<String>()).setPageSize(883849137).setPageToken("pageToken873572522").setOrderBy("orderBy-1207110587").setReadMask(FieldMask.newBuilder().build()).build();
        while (true) {
            SearchAllResourcesResponse response = assetServiceClient.searchAllResourcesCallable().call(request);
            for (ResourceSearchResult element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : SearchAllResourcesResponse(com.google.cloud.asset.v1.SearchAllResourcesResponse) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) SearchAllResourcesRequest(com.google.cloud.asset.v1.SearchAllResourcesRequest) ResourceSearchResult(com.google.cloud.asset.v1.ResourceSearchResult) ArrayList(java.util.ArrayList)

Example 47 with AssetServiceClient

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

the class SyncUpdateFeed method syncUpdateFeed.

public static void syncUpdateFeed() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        UpdateFeedRequest request = UpdateFeedRequest.newBuilder().setFeed(Feed.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        Feed response = assetServiceClient.updateFeed(request);
    }
}
Also used : UpdateFeedRequest(com.google.cloud.asset.v1.UpdateFeedRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Example 48 with AssetServiceClient

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

the class AnalyzeIamPolicyLongrunningGcsExample method analyzeIamPolicyLongrunning.

// Analyzes accessible IAM policies that match a request.
public static void analyzeIamPolicyLongrunning(String scope, String fullResourceName, String uri) {
    ResourceSelector resourceSelector = ResourceSelector.newBuilder().setFullResourceName(fullResourceName).build();
    Options options = Options.newBuilder().setExpandGroups(true).setOutputGroupEdges(true).build();
    IamPolicyAnalysisQuery query = IamPolicyAnalysisQuery.newBuilder().setScope(scope).setResourceSelector(resourceSelector).setOptions(options).build();
    GcsDestination gcsDestination = GcsDestination.newBuilder().setUri(uri).build();
    IamPolicyAnalysisOutputConfig outputConfig = IamPolicyAnalysisOutputConfig.newBuilder().setGcsDestination(GcsDestination.newBuilder().setUri(uri).build()).build();
    AnalyzeIamPolicyLongrunningRequest request = AnalyzeIamPolicyLongrunningRequest.newBuilder().setAnalysisQuery(query).setOutputConfig(outputConfig).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        System.out.println("Analyze completed successfully:\n" + client.analyzeIamPolicyLongrunningAsync(request).getMetadata().get());
    } catch (IOException e) {
        System.out.println("Failed to create client:\n" + e.toString());
    } catch (InterruptedException e) {
        System.out.println("Operation was interrupted:\n" + e.toString());
    } catch (ExecutionException e) {
        System.out.println("Operation was aborted:\n" + e.toString());
    } catch (ApiException e) {
        System.out.println("Error during AnalyzeIamPolicyLongrunning:\n" + e.toString());
    }
}
Also used : Options(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options) AnalyzeIamPolicyLongrunningRequest(com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest) IamPolicyAnalysisOutputConfig(com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ResourceSelector(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector) IamPolicyAnalysisQuery(com.google.cloud.asset.v1.IamPolicyAnalysisQuery) IOException(java.io.IOException) GcsDestination(com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.GcsDestination) ExecutionException(java.util.concurrent.ExecutionException) ApiException(com.google.api.gax.rpc.ApiException)

Example 49 with AssetServiceClient

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

the class ExportAssetsBigqueryExample method exportBigQuery.

// Export assets to BigQuery for a project.
public static void exportBigQuery(String bigqueryDataset, String bigqueryTable, ContentType contentType, boolean isPerType) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        OutputConfig outputConfig;
        // Outputs to per-type BigQuery table.
        if (isPerType) {
            outputConfig = OutputConfig.newBuilder().setBigqueryDestination(BigQueryDestination.newBuilder().setDataset(bigqueryDataset).setTable(bigqueryTable).setForce(true).setSeparateTablesPerAssetType(true).setPartitionSpec(PartitionSpec.newBuilder().setPartitionKey(PartitionSpec.PartitionKey.READ_TIME).build()).build()).build();
        } else {
            outputConfig = OutputConfig.newBuilder().setBigqueryDestination(BigQueryDestination.newBuilder().setDataset(bigqueryDataset).setTable(bigqueryTable).setForce(true).build()).build();
        }
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(parent.toString()).setContentType(contentType).setOutputConfig(outputConfig).build();
        ExportAssetsResponse response = client.exportAssetsAsync(request).get();
        System.out.println(response);
    }
}
Also used : OutputConfig(com.google.cloud.asset.v1.OutputConfig) ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ExportAssetsResponse(com.google.cloud.asset.v1.ExportAssetsResponse)

Example 50 with AssetServiceClient

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

the class SearchAllResourcesExample method searchAllResources.

// Searches for all the resources within the given scope.
public static void searchAllResources(String scope, String query) {
    // TODO(developer): Replace these variables before running the sample.
    String[] assetTypes = {};
    int pageSize = 0;
    String pageToken = "";
    String orderBy = "";
    SearchAllResourcesRequest request = SearchAllResourcesRequest.newBuilder().setScope(scope).setQuery(query).addAllAssetTypes(Arrays.asList(assetTypes)).setPageSize(pageSize).setPageToken(pageToken).setOrderBy(orderBy).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        SearchAllResourcesPagedResponse response = client.searchAllResources(request);
        System.out.println("Search completed successfully:\n" + response.getPage().getValues());
    } catch (IOException e) {
        System.out.println(String.format("Failed to create client:%n%s", e.toString()));
    } catch (InvalidArgumentException e) {
        System.out.println(String.format("Invalid request:%n%s", e.toString()));
    } catch (ApiException e) {
        System.out.println(String.format("Error during SearchAllResources:%n%s", e.toString()));
    }
}
Also used : SearchAllResourcesPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) SearchAllResourcesRequest(com.google.cloud.asset.v1.SearchAllResourcesRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) IOException(java.io.IOException) ApiException(com.google.api.gax.rpc.ApiException)

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