Search in sources :

Example 16 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project gapic-generator-java by googleapis.

the class SyncSearchAllResourcesStringStringListstring method syncSearchAllResourcesStringStringListstring.

public static void syncSearchAllResourcesStringStringListstring() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        String scope = "scope109264468";
        String query = "query107944136";
        List<String> assetTypes = new ArrayList<>();
        for (ResourceSearchResult element : assetServiceClient.searchAllResources(scope, query, assetTypes).iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ResourceSearchResult(com.google.cloud.asset.v1.ResourceSearchResult) ArrayList(java.util.ArrayList)

Example 17 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project gapic-generator-java by googleapis.

the class AsyncUpdateFeed method asyncUpdateFeed.

public static void asyncUpdateFeed() 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();
        ApiFuture<Feed> future = assetServiceClient.updateFeedCallable().futureCall(request);
        // Do something.
        Feed response = future.get();
    }
}
Also used : UpdateFeedRequest(com.google.cloud.asset.v1.UpdateFeedRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Example 18 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project gapic-generator-java by googleapis.

the class SyncUpdateFeedFeed method syncUpdateFeedFeed.

public static void syncUpdateFeedFeed() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        Feed feed = Feed.newBuilder().build();
        Feed response = assetServiceClient.updateFeed(feed);
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Example 19 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.

the class AnalyzeIamPolicyExample method analyzeIamPolicy.

// Analyzes accessible IAM policies that match a request.
public static void analyzeIamPolicy(String scope, String fullResourceName) {
    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();
    AnalyzeIamPolicyRequest request = AnalyzeIamPolicyRequest.newBuilder().setAnalysisQuery(query).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        AnalyzeIamPolicyResponse response = client.analyzeIamPolicy(request);
        System.out.println("Analyze completed successfully:\n" + response);
    } catch (IOException e) {
        System.out.println("Failed to create client:\n" + e.toString());
    } catch (ApiException e) {
        System.out.println("Error during AnalyzeIamPolicy:\n" + e.toString());
    }
}
Also used : Options(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.Options) AnalyzeIamPolicyRequest(com.google.cloud.asset.v1.AnalyzeIamPolicyRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ResourceSelector(com.google.cloud.asset.v1.IamPolicyAnalysisQuery.ResourceSelector) IamPolicyAnalysisQuery(com.google.cloud.asset.v1.IamPolicyAnalysisQuery) AnalyzeIamPolicyResponse(com.google.cloud.asset.v1.AnalyzeIamPolicyResponse) IOException(java.io.IOException) ApiException(com.google.api.gax.rpc.ApiException)

Example 20 with AssetServiceClient

use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.

the class CreateFeedExample method createFeed.

// Create a feed
public static void createFeed(String[] assetNames, String feedId, String topic, String projectId, ContentType contentType) throws IOException, IllegalArgumentException {
    // String[] assetNames = {"MY_ASSET_NAME"}
    // ContentType contentType = contentType
    // String FeedId = "MY_FEED_ID"
    // String topic = "projects/[PROJECT_ID]/topics/[TOPIC_NAME]"
    // String projectID = "MY_PROJECT_ID"
    Feed feed = Feed.newBuilder().addAllAssetNames(Arrays.asList(assetNames)).setContentType(contentType).setFeedOutputConfig(FeedOutputConfig.newBuilder().setPubsubDestination(PubsubDestination.newBuilder().setTopic(topic).build()).build()).build();
    CreateFeedRequest request = CreateFeedRequest.newBuilder().setParent(String.format(ProjectName.of(projectId).toString())).setFeedId(feedId).setFeed(feed).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AssetServiceClient client = AssetServiceClient.create()) {
        Feed response = client.createFeed(request);
        System.out.println("Feed created successfully: " + response.getName());
    } catch (IOException | IllegalArgumentException e) {
        System.out.println("Error during CreateFeed: \n" + e.toString());
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) IOException(java.io.IOException) CreateFeedRequest(com.google.cloud.asset.v1.CreateFeedRequest) Feed(com.google.cloud.asset.v1.Feed)

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