use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class GetFeedExample method getFeed.
// Get a feed with full feed name
public static void getFeed(String feedName) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
Feed feed = client.getFeed(feedName);
System.out.println("Get a feed: " + feedName);
} catch (Exception e) {
System.out.println("Error during GetFeed: \n" + e.toString());
}
}
use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class ListFeedsExample method listFeeds.
// List feeds in a project.
public static void listFeeds(String projectId) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
ListFeedsResponse response = client.listFeeds(ProjectName.of(projectId).toString());
System.out.println("Listed feeds under: " + projectId);
} catch (Exception e) {
System.out.println("Error during ListFeeds: \n" + e.toString());
}
}
use of com.google.cloud.asset.v1.AssetServiceClient 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.AssetServiceClient in project java-asset by googleapis.
the class DeleteFeedExample method deleteFeed.
// Delete a feed with full feed name
public static void deleteFeed(String feedName) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
client.deleteFeed(feedName);
System.out.println("Feed deleted");
} catch (Exception e) {
System.out.println("Error during DeleteFeed: \n" + e.toString());
}
}
use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class ExportAssetsExample method exportAssets.
// Export assets for a project.
// @param exportPath where the results will be exported to.
public static void exportAssets(String exportPath, ContentType contentType) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {
try (AssetServiceClient client = AssetServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
OutputConfig outputConfig = OutputConfig.newBuilder().setGcsDestination(GcsDestination.newBuilder().setUri(exportPath).build()).build();
ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(parent.toString()).setOutputConfig(outputConfig).setContentType(contentType).build();
ExportAssetsResponse response = client.exportAssetsAsync(request).get();
System.out.println(response);
}
}
Aggregations