Search in sources :

Example 26 with AssetServiceClient

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

Example 27 with AssetServiceClient

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()));
    }
}
Also used : SearchAllIamPoliciesPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) SearchAllIamPoliciesRequest(com.google.cloud.asset.v1.SearchAllIamPoliciesRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) IOException(java.io.IOException) ApiException(com.google.api.gax.rpc.ApiException)

Example 28 with AssetServiceClient

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

Example 29 with AssetServiceClient

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

Example 30 with AssetServiceClient

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

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