use of com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options 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());
}
}
use of com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options 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());
}
}
use of com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options 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());
}
}
Aggregations