use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class ListAssetsExample method listAssets.
public static void listAssets(String projectId, String[] assetTypes, ContentType contentType) throws IOException, IllegalArgumentException {
try (AssetServiceClient client = AssetServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
// Build initial ListAssetsRequest without setting page token.
ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent.toString()).addAllAssetTypes(Arrays.asList(assetTypes)).setContentType(contentType).build();
// Repeatedly call ListAssets until page token is empty.
ListAssetsPagedResponse response = client.listAssets(request);
System.out.println(response);
while (!response.getNextPageToken().isEmpty()) {
request = request.toBuilder().setPageToken(response.getNextPageToken()).build();
response = client.listAssets(request);
System.out.println(response);
}
}
}
use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class SearchAllIamPoliciesExample method searchAllIamPolicies.
// Searches for all the iam policies within the given scope.
public static void searchAllIamPolicies(String scope, String query) {
// TODO(developer): Replace these variables before running the sample.
int pageSize = 0;
String pageToken = "";
SearchAllIamPoliciesRequest request = SearchAllIamPoliciesRequest.newBuilder().setScope(scope).setQuery(query).setPageSize(pageSize).setPageToken(pageToken).build();
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
SearchAllIamPoliciesPagedResponse response = client.searchAllIamPolicies(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 SearchAllIamPolicies:%n%s", e.toString()));
}
}
use of com.google.cloud.asset.v1.AssetServiceClient 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();
}
}
use of com.google.cloud.asset.v1.AssetServiceClient in project gapic-generator-java by googleapis.
the class AsyncAnalyzeIamPolicyLongrunning method asyncAnalyzeIamPolicyLongrunning.
public static void asyncAnalyzeIamPolicyLongrunning() throws Exception {
// It may require modifications to work in your environment.
try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
AnalyzeIamPolicyLongrunningRequest request = AnalyzeIamPolicyLongrunningRequest.newBuilder().setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()).setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()).build();
ApiFuture<Operation> future = assetServiceClient.analyzeIamPolicyLongrunningCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
}
use of com.google.cloud.asset.v1.AssetServiceClient in project gapic-generator-java by googleapis.
the class AsyncAnalyzeIamPolicyLongrunningLRO method asyncAnalyzeIamPolicyLongrunningLRO.
public static void asyncAnalyzeIamPolicyLongrunningLRO() throws Exception {
// It may require modifications to work in your environment.
try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
AnalyzeIamPolicyLongrunningRequest request = AnalyzeIamPolicyLongrunningRequest.newBuilder().setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()).setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()).build();
OperationFuture<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningMetadata> future = assetServiceClient.analyzeIamPolicyLongrunningOperationCallable().futureCall(request);
// Do something.
AnalyzeIamPolicyLongrunningResponse response = future.get();
}
}
Aggregations