Search in sources :

Example 21 with AssetServiceClient

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());
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Example 22 with AssetServiceClient

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());
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ListFeedsResponse(com.google.cloud.asset.v1.ListFeedsResponse)

Example 23 with AssetServiceClient

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());
    }
}
Also used : Options(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options) AnalyzeIamPolicyLongrunningRequest(com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest) IamPolicyAnalysisOutputConfig(com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ResourceSelector(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector) IamPolicyAnalysisQuery(com.google.cloud.asset.v1.IamPolicyAnalysisQuery) IOException(java.io.IOException) BigQueryDestination(com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.BigQueryDestination) ExecutionException(java.util.concurrent.ExecutionException) ApiException(com.google.api.gax.rpc.ApiException)

Example 24 with AssetServiceClient

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());
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient)

Example 25 with AssetServiceClient

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);
    }
}
Also used : OutputConfig(com.google.cloud.asset.v1.OutputConfig) ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ExportAssetsResponse(com.google.cloud.asset.v1.ExportAssetsResponse)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)52 Feed (com.google.cloud.asset.v1.Feed)13 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)6 ApiException (com.google.api.gax.rpc.ApiException)5 AnalyzeIamPolicyLongrunningRequest (com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest)5 ExportAssetsRequest (com.google.cloud.asset.v1.ExportAssetsRequest)5 ExportAssetsResponse (com.google.cloud.asset.v1.ExportAssetsResponse)4 ListFeedsResponse (com.google.cloud.asset.v1.ListFeedsResponse)4 ProjectName (com.google.cloud.asset.v1.ProjectName)4 AnalyzeIamPolicyRequest (com.google.cloud.asset.v1.AnalyzeIamPolicyRequest)3 AnalyzeIamPolicyResponse (com.google.cloud.asset.v1.AnalyzeIamPolicyResponse)3 CreateFeedRequest (com.google.cloud.asset.v1.CreateFeedRequest)3 IamPolicyAnalysisQuery (com.google.cloud.asset.v1.IamPolicyAnalysisQuery)3 Options (com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options)3 ResourceSelector (com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector)3 IamPolicySearchResult (com.google.cloud.asset.v1.IamPolicySearchResult)3 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)3 ResourceSearchResult (com.google.cloud.asset.v1.ResourceSearchResult)3 SearchAllIamPoliciesRequest (com.google.cloud.asset.v1.SearchAllIamPoliciesRequest)3