Search in sources :

Example 1 with BigQueryDestination

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

the class AnalyzeIamPolicyLongrunningBigqueryExample method analyzeIamPolicyLongrunning.

// Analyzes accessible IAM policies that match a request.
public static void analyzeIamPolicyLongrunning(String scope, String fullResourceName, String dataset, String tablePrefix) {
    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();
    BigQueryDestination bigQueryDestination = BigQueryDestination.newBuilder().setDataset(dataset).setTablePrefix(tablePrefix).build();
    IamPolicyAnalysisOutputConfig outputConfig = IamPolicyAnalysisOutputConfig.newBuilder().setBigqueryDestination(bigQueryDestination).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) BigQueryDestination(com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.BigQueryDestination) ExecutionException(java.util.concurrent.ExecutionException) ApiException(com.google.api.gax.rpc.ApiException)

Aggregations

ApiException (com.google.api.gax.rpc.ApiException)1 AnalyzeIamPolicyLongrunningRequest (com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest)1 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)1 IamPolicyAnalysisOutputConfig (com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig)1 BigQueryDestination (com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.BigQueryDestination)1 IamPolicyAnalysisQuery (com.google.cloud.asset.v1.IamPolicyAnalysisQuery)1 Options (com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options)1 ResourceSelector (com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1