Search in sources :

Example 1 with AnalyzeIamPolicyResponse

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

the class SyncAnalyzeIamPolicy method syncAnalyzeIamPolicy.

public static void syncAnalyzeIamPolicy() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        AnalyzeIamPolicyRequest request = AnalyzeIamPolicyRequest.newBuilder().setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()).setExecutionTimeout(Duration.newBuilder().build()).build();
        AnalyzeIamPolicyResponse response = assetServiceClient.analyzeIamPolicy(request);
    }
}
Also used : AnalyzeIamPolicyRequest(com.google.cloud.asset.v1.AnalyzeIamPolicyRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) AnalyzeIamPolicyResponse(com.google.cloud.asset.v1.AnalyzeIamPolicyResponse)

Example 2 with AnalyzeIamPolicyResponse

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

the class AnalyzeIamPolicyExample method analyzeIamPolicy.

// Analyzes accessible IAM policies that match a request.
public static void analyzeIamPolicy(String scope, String fullResourceName) {
    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();
    AnalyzeIamPolicyRequest request = AnalyzeIamPolicyRequest.newBuilder().setAnalysisQuery(query).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        AnalyzeIamPolicyResponse response = client.analyzeIamPolicy(request);
        System.out.println("Analyze completed successfully:\n" + response);
    } catch (IOException e) {
        System.out.println("Failed to create client:\n" + e.toString());
    } catch (ApiException e) {
        System.out.println("Error during AnalyzeIamPolicy:\n" + e.toString());
    }
}
Also used : Options(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options) AnalyzeIamPolicyRequest(com.google.cloud.asset.v1.AnalyzeIamPolicyRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ResourceSelector(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector) IamPolicyAnalysisQuery(com.google.cloud.asset.v1.IamPolicyAnalysisQuery) AnalyzeIamPolicyResponse(com.google.cloud.asset.v1.AnalyzeIamPolicyResponse) IOException(java.io.IOException) ApiException(com.google.api.gax.rpc.ApiException)

Example 3 with AnalyzeIamPolicyResponse

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

the class AsyncAnalyzeIamPolicy method asyncAnalyzeIamPolicy.

public static void asyncAnalyzeIamPolicy() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        AnalyzeIamPolicyRequest request = AnalyzeIamPolicyRequest.newBuilder().setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()).setExecutionTimeout(Duration.newBuilder().build()).build();
        ApiFuture<AnalyzeIamPolicyResponse> future = assetServiceClient.analyzeIamPolicyCallable().futureCall(request);
        // Do something.
        AnalyzeIamPolicyResponse response = future.get();
    }
}
Also used : AnalyzeIamPolicyRequest(com.google.cloud.asset.v1.AnalyzeIamPolicyRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) AnalyzeIamPolicyResponse(com.google.cloud.asset.v1.AnalyzeIamPolicyResponse)

Aggregations

AnalyzeIamPolicyRequest (com.google.cloud.asset.v1.AnalyzeIamPolicyRequest)3 AnalyzeIamPolicyResponse (com.google.cloud.asset.v1.AnalyzeIamPolicyResponse)3 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)3 ApiException (com.google.api.gax.rpc.ApiException)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