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;
}
}
}
}
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);
}
}
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());
}
}
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);
}
}
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()));
}
}
Aggregations