From 1c8f18cbfeae5983d9b8171c682eeb8595ce93c5 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 24 Jun 2022 15:02:29 +0000 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#1242) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 --- google-cloud-asset/pom.xml | 16 + .../cloud/asset/v1/AssetServiceClient.java | 37 +- .../cloud/asset/v1/AssetServiceSettings.java | 23 +- .../cloud/asset/v1/stub/AssetServiceStub.java | 6 +- .../v1/stub/AssetServiceStubSettings.java | 53 +- .../HttpJsonAssetServiceCallableFactory.java | 105 + .../v1/stub/HttpJsonAssetServiceStub.java | 1303 +++++++++++++ .../asset/v1p1beta1/AssetServiceClient.java | 14 + .../asset/v1p1beta1/AssetServiceSettings.java | 23 +- .../stub/AssetServiceStubSettings.java | 53 +- .../HttpJsonAssetServiceCallableFactory.java | 105 + .../stub/HttpJsonAssetServiceStub.java | 292 +++ .../asset/v1p2beta1/AssetServiceClient.java | 14 + .../asset/v1p2beta1/AssetServiceSettings.java | 23 +- .../stub/AssetServiceStubSettings.java | 53 +- .../HttpJsonAssetServiceCallableFactory.java | 105 + .../stub/HttpJsonAssetServiceStub.java | 390 ++++ .../asset/v1p4beta1/AssetServiceClient.java | 37 +- .../asset/v1p4beta1/AssetServiceSettings.java | 23 +- .../v1p4beta1/stub/AssetServiceStub.java | 6 +- .../stub/AssetServiceStubSettings.java | 53 +- .../HttpJsonAssetServiceCallableFactory.java | 105 + .../stub/HttpJsonAssetServiceStub.java | 299 +++ .../asset/v1p5beta1/AssetServiceClient.java | 14 + .../asset/v1p5beta1/AssetServiceSettings.java | 23 +- .../stub/AssetServiceStubSettings.java | 53 +- .../HttpJsonAssetServiceCallableFactory.java | 105 + .../stub/HttpJsonAssetServiceStub.java | 209 ++ .../v1/AssetServiceClientHttpJsonTest.java | 1710 +++++++++++++++++ .../AssetServiceClientHttpJsonTest.java | 186 ++ .../AssetServiceClientHttpJsonTest.java | 403 ++++ .../AssetServiceClientHttpJsonTest.java | 225 +++ .../AssetServiceClientHttpJsonTest.java | 145 ++ .../AsyncAnalyzeIamPolicy.java | 50 + .../SyncAnalyzeIamPolicy.java | 46 + .../AsyncAnalyzeIamPolicyLongrunning.java | 50 + .../AsyncAnalyzeIamPolicyLongrunningLRO.java | 52 + .../SyncAnalyzeIamPolicyLongrunning.java | 47 + .../analyzemove/AsyncAnalyzeMove.java | 47 + .../analyzemove/SyncAnalyzeMove.java | 43 + .../AsyncBatchGetAssetsHistory.java | 54 + .../SyncBatchGetAssetsHistory.java | 50 + .../AsyncBatchGetEffectiveIamPolicies.java | 49 + .../SyncBatchGetEffectiveIamPolicies.java | 46 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../createfeed/AsyncCreateFeed.java | 47 + .../createfeed/SyncCreateFeed.java | 44 + .../createfeed/SyncCreateFeedString.java | 38 + .../AsyncCreateSavedQuery.java | 49 + .../SyncCreateSavedQuery.java | 45 + ...eSavedQueryFoldernameSavedqueryString.java | 41 + ...QueryOrganizationnameSavedqueryString.java | 43 + ...SavedQueryProjectnameSavedqueryString.java | 41 + ...reateSavedQueryStringSavedqueryString.java | 41 + .../deletefeed/AsyncDeleteFeed.java | 46 + .../deletefeed/SyncDeleteFeed.java | 42 + .../deletefeed/SyncDeleteFeedFeedname.java | 38 + .../deletefeed/SyncDeleteFeedString.java | 38 + .../AsyncDeleteSavedQuery.java | 47 + .../SyncDeleteSavedQuery.java | 43 + .../SyncDeleteSavedQuerySavedqueryname.java | 38 + .../SyncDeleteSavedQueryString.java | 38 + .../exportassets/AsyncExportAssets.java | 55 + .../exportassets/AsyncExportAssetsLRO.java | 56 + .../exportassets/SyncExportAssets.java | 52 + .../getfeed/AsyncGetFeed.java | 46 + .../getfeed/SyncGetFeed.java | 43 + .../getfeed/SyncGetFeedFeedname.java | 39 + .../getfeed/SyncGetFeedString.java | 39 + .../getsavedquery/AsyncGetSavedQuery.java | 47 + .../getsavedquery/SyncGetSavedQuery.java | 44 + .../SyncGetSavedQuerySavedqueryname.java | 39 + .../SyncGetSavedQueryString.java | 39 + .../listassets/AsyncListAssets.java | 57 + .../listassets/AsyncListAssetsPaged.java | 65 + .../listassets/SyncListAssets.java | 54 + .../SyncListAssetsResourcename.java | 42 + .../listassets/SyncListAssetsString.java | 41 + .../listfeeds/AsyncListFeeds.java | 44 + .../listfeeds/SyncListFeeds.java | 40 + .../listfeeds/SyncListFeedsString.java | 38 + .../AsyncListSavedQueries.java | 52 + .../AsyncListSavedQueriesPaged.java | 60 + .../SyncListSavedQueries.java | 48 + .../SyncListSavedQueriesFoldername.java | 41 + .../SyncListSavedQueriesOrganizationname.java | 41 + .../SyncListSavedQueriesProjectname.java | 41 + .../SyncListSavedQueriesString.java | 41 + .../AsyncSearchAllIamPolicies.java | 54 + .../AsyncSearchAllIamPoliciesPaged.java | 62 + .../SyncSearchAllIamPolicies.java | 51 + .../SyncSearchAllIamPoliciesStringString.java | 42 + .../AsyncSearchAllResources.java | 56 + .../AsyncSearchAllResourcesPaged.java | 64 + .../SyncSearchAllResources.java | 53 + ...rchAllResourcesStringStringListstring.java | 45 + .../updatefeed/AsyncUpdateFeed.java | 47 + .../updatefeed/SyncUpdateFeed.java | 44 + .../updatefeed/SyncUpdateFeedFeed.java | 38 + .../AsyncUpdateSavedQuery.java | 48 + .../SyncUpdateSavedQuery.java | 44 + ...ncUpdateSavedQuerySavedqueryFieldmask.java | 40 + .../SyncBatchGetAssetsHistory.java | 45 + .../SyncBatchGetAssetsHistory.java | 46 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../AsyncSearchAllIamPolicies.java | 51 + .../AsyncSearchAllIamPoliciesPaged.java | 59 + .../SyncSearchAllIamPolicies.java | 48 + .../SyncSearchAllIamPoliciesStringString.java | 42 + .../AsyncSearchAllResources.java | 54 + .../AsyncSearchAllResourcesPaged.java | 62 + .../SyncSearchAllResources.java | 51 + ...rchAllResourcesStringStringListstring.java | 46 + .../SyncSearchAllResources.java | 45 + .../SyncSearchAllResources.java | 46 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../createfeed/AsyncCreateFeed.java | 47 + .../createfeed/SyncCreateFeed.java | 44 + .../createfeed/SyncCreateFeedString.java | 38 + .../deletefeed/AsyncDeleteFeed.java | 46 + .../deletefeed/SyncDeleteFeed.java | 42 + .../deletefeed/SyncDeleteFeedFeedname.java | 38 + .../deletefeed/SyncDeleteFeedString.java | 38 + .../getfeed/AsyncGetFeed.java | 46 + .../getfeed/SyncGetFeed.java | 43 + .../getfeed/SyncGetFeedFeedname.java | 39 + .../getfeed/SyncGetFeedString.java | 39 + .../listfeeds/AsyncListFeeds.java | 44 + .../listfeeds/SyncListFeeds.java | 40 + .../listfeeds/SyncListFeedsString.java | 38 + .../updatefeed/AsyncUpdateFeed.java | 47 + .../updatefeed/SyncUpdateFeed.java | 44 + .../updatefeed/SyncUpdateFeedFeed.java | 38 + .../createfeed/SyncCreateFeed.java | 45 + .../createfeed/SyncCreateFeed.java | 46 + .../AsyncAnalyzeIamPolicy.java | 48 + .../SyncAnalyzeIamPolicy.java | 44 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../AsyncExportIamPolicyAnalysis.java | 50 + .../AsyncExportIamPolicyAnalysisLRO.java | 50 + .../SyncExportIamPolicyAnalysis.java | 47 + .../SyncAnalyzeIamPolicy.java | 45 + .../SyncAnalyzeIamPolicy.java | 46 + .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../listassets/AsyncListAssets.java | 55 + .../listassets/AsyncListAssetsPaged.java | 63 + .../listassets/SyncListAssets.java | 52 + .../listassets/SyncListAssets.java | 45 + .../listassets/SyncListAssets.java | 46 + 159 files changed, 11902 insertions(+), 37 deletions(-) create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceCallableFactory.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceCallableFactory.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceStub.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceCallableFactory.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceStub.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceCallableFactory.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceStub.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceCallableFactory.java create mode 100644 google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceStub.java create mode 100644 google-cloud-asset/src/test/java/com/google/cloud/asset/v1/AssetServiceClientHttpJsonTest.java create mode 100644 google-cloud-asset/src/test/java/com/google/cloud/asset/v1p1beta1/AssetServiceClientHttpJsonTest.java create mode 100644 google-cloud-asset/src/test/java/com/google/cloud/asset/v1p2beta1/AssetServiceClientHttpJsonTest.java create mode 100644 google-cloud-asset/src/test/java/com/google/cloud/asset/v1p4beta1/AssetServiceClientHttpJsonTest.java create mode 100644 google-cloud-asset/src/test/java/com/google/cloud/asset/v1p5beta1/AssetServiceClientHttpJsonTest.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunning.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunningLRO.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/SyncAnalyzeIamPolicyLongrunning.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/AsyncAnalyzeMove.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/SyncAnalyzeMove.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/AsyncBatchGetAssetsHistory.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/SyncBatchGetAssetsHistory.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/AsyncBatchGetEffectiveIamPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/SyncBatchGetEffectiveIamPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/AsyncCreateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeedString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/AsyncCreateSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryFoldernameSavedqueryString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryOrganizationnameSavedqueryString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryProjectnameSavedqueryString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryStringSavedqueryString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/AsyncDeleteFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/AsyncDeleteSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuerySavedqueryname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQueryString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssetsLRO.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/SyncExportAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/AsyncGetFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedFeedname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/AsyncGetSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuerySavedqueryname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQueryString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssetsPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsResourcename.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/AsyncListFeeds.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeeds.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeedsString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueries.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueriesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueries.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesFoldername.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesOrganizationname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesProjectname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResources.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResources.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/AsyncUpdateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/AsyncUpdateSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuery.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuerySavedqueryFieldmask.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/assetservicesettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1/stub/assetservicestubsettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResources.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResources.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetservicesettings/searchallresources/SyncSearchAllResources.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p1beta1/stub/assetservicestubsettings/searchallresources/SyncSearchAllResources.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/AsyncCreateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeedString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/AsyncDeleteFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/AsyncGetFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedFeedname.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/AsyncListFeeds.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeeds.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeedsString.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/AsyncUpdateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetservicesettings/createfeed/SyncCreateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p2beta1/stub/assetservicestubsettings/createfeed/SyncCreateFeed.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysis.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysisLRO.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/SyncExportIamPolicyAnalysis.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetservicesettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p4beta1/stub/assetservicestubsettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssetsPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/SyncListAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetservicesettings/listassets/SyncListAssets.java create mode 100644 samples/snippets/generated/com/google/cloud/asset/v1p5beta1/stub/assetservicestubsettings/listassets/SyncListAssets.java diff --git a/google-cloud-asset/pom.xml b/google-cloud-asset/pom.xml index ff96571e6..0011ac1dd 100644 --- a/google-cloud-asset/pom.xml +++ b/google-cloud-asset/pom.xml @@ -77,6 +77,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -139,12 +143,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceClient.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceClient.java index fc8484e62..b885e4813 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceClient.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceClient.java @@ -19,6 +19,7 @@ import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutures; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.paging.AbstractFixedSizeCollection; import com.google.api.gax.paging.AbstractPage; @@ -31,7 +32,6 @@ import com.google.cloud.asset.v1.stub.AssetServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -110,13 +110,28 @@ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * AssetServiceSettings assetServiceSettings =
+ *     AssetServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class AssetServiceClient implements BackgroundResource { private final AssetServiceSettings settings; private final AssetServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of AssetServiceClient with default settings. */ public static final AssetServiceClient create() throws IOException { @@ -147,13 +162,17 @@ public static final AssetServiceClient create(AssetServiceStub stub) { protected AssetServiceClient(AssetServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((AssetServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected AssetServiceClient(AssetServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final AssetServiceSettings getSettings() { @@ -168,10 +187,18 @@ public AssetServiceStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Exports assets with time and resource types to a given Cloud Storage location/BigQuery table. diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceSettings.java index 7e1e9518e..9ed0dabea 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/AssetServiceSettings.java @@ -26,6 +26,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -226,11 +227,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssetServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return AssetServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssetServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssetServiceStubSettings.defaultTransportChannelProvider(); } @@ -240,11 +248,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssetServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -282,6 +296,11 @@ private static Builder createDefault() { return new Builder(AssetServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssetServiceStubSettings.newHttpJsonBuilder()); + } + public AssetServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssetServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStub.java index 4e17bcbc3..8be0b9772 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStub.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStub.java @@ -72,7 +72,11 @@ public abstract class AssetServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public OperationCallable diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java index 905ae39ac..8cc8a48a3 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java @@ -31,6 +31,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -547,6 +550,11 @@ public AssetServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssetServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssetServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -579,18 +587,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) @@ -598,11 +613,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssetServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -884,6 +918,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .exportAssetsSettings() diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceCallableFactory.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceCallableFactory.java new file mode 100644 index 000000000..08af9f934 --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the AssetService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonAssetServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java new file mode 100644 index 000000000..b2b344b6a --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1/stub/HttpJsonAssetServiceStub.java @@ -0,0 +1,1303 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.stub; + +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.ListSavedQueriesPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningMetadata; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; +import com.google.cloud.asset.v1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyResponse; +import com.google.cloud.asset.v1.AnalyzeMoveRequest; +import com.google.cloud.asset.v1.AnalyzeMoveResponse; +import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; +import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesRequest; +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesResponse; +import com.google.cloud.asset.v1.CreateFeedRequest; +import com.google.cloud.asset.v1.CreateSavedQueryRequest; +import com.google.cloud.asset.v1.DeleteFeedRequest; +import com.google.cloud.asset.v1.DeleteSavedQueryRequest; +import com.google.cloud.asset.v1.ExportAssetsRequest; +import com.google.cloud.asset.v1.ExportAssetsResponse; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.GetFeedRequest; +import com.google.cloud.asset.v1.GetSavedQueryRequest; +import com.google.cloud.asset.v1.ListAssetsRequest; +import com.google.cloud.asset.v1.ListAssetsResponse; +import com.google.cloud.asset.v1.ListFeedsRequest; +import com.google.cloud.asset.v1.ListFeedsResponse; +import com.google.cloud.asset.v1.ListSavedQueriesRequest; +import com.google.cloud.asset.v1.ListSavedQueriesResponse; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.SearchAllIamPoliciesRequest; +import com.google.cloud.asset.v1.SearchAllIamPoliciesResponse; +import com.google.cloud.asset.v1.SearchAllResourcesRequest; +import com.google.cloud.asset.v1.SearchAllResourcesResponse; +import com.google.cloud.asset.v1.UpdateFeedRequest; +import com.google.cloud.asset.v1.UpdateSavedQueryRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the AssetService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonAssetServiceStub extends AssetServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(AnalyzeIamPolicyLongrunningMetadata.getDescriptor()) + .add(ExportAssetsResponse.getDescriptor()) + .add(AnalyzeIamPolicyLongrunningResponse.getDescriptor()) + .add(ExportAssetsRequest.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + exportAssetsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/ExportAssets") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}:exportAssets", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ExportAssetsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listAssetsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/ListAssets") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/assets", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "assetTypes", request.getAssetTypesList()); + serializer.putQueryParam( + fields, "contentType", request.getContentType()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "readTime", request.getReadTime()); + serializer.putQueryParam( + fields, "relationshipTypes", request.getRelationshipTypesList()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListAssetsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + BatchGetAssetsHistoryRequest, BatchGetAssetsHistoryResponse> + batchGetAssetsHistoryMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/BatchGetAssetsHistory") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}:batchGetAssetsHistory", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "assetNames", request.getAssetNamesList()); + serializer.putQueryParam( + fields, "contentType", request.getContentType()); + serializer.putQueryParam( + fields, "readTimeWindow", request.getReadTimeWindow()); + serializer.putQueryParam( + fields, "relationshipTypes", request.getRelationshipTypesList()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BatchGetAssetsHistoryResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor createFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/CreateFeed") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/feeds", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Feed.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/GetFeed") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/feeds/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Feed.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listFeedsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/ListFeeds") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/feeds", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListFeedsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/UpdateFeed") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{feed.name=*/*/feeds/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "feed.name", request.getFeed().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("*", request.toBuilder().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Feed.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/DeleteFeed") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/feeds/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + searchAllResourcesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/SearchAllResources") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{scope=*/*}:searchAllResources", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "scope", request.getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "assetTypes", request.getAssetTypesList()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + serializer.putQueryParam(fields, "readMask", request.getReadMask()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchAllResourcesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse> + searchAllIamPoliciesMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/SearchAllIamPolicies") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{scope=*/*}:searchAllIamPolicies", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "scope", request.getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "assetTypes", request.getAssetTypesList()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchAllIamPoliciesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + analyzeIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/AnalyzeIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{analysisQuery.scope=*/*}:analyzeIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "analysisQuery.scope", + request.getAnalysisQuery().getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "analysisQuery", request.getAnalysisQuery()); + serializer.putQueryParam( + fields, "executionTimeout", request.getExecutionTimeout()); + serializer.putQueryParam( + fields, "savedAnalysisQuery", request.getSavedAnalysisQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AnalyzeIamPolicyResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + analyzeIamPolicyLongrunningMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/AnalyzeIamPolicyLongrunning") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{analysisQuery.scope=*/*}:analyzeIamPolicyLongrunning", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "analysisQuery.scope", + request.getAnalysisQuery().getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("*", request.toBuilder().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (AnalyzeIamPolicyLongrunningRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + analyzeMoveMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/AnalyzeMove") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{resource=*/*}:analyzeMove", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "resource", request.getResource()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "destinationParent", request.getDestinationParent()); + serializer.putQueryParam(fields, "view", request.getView()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AnalyzeMoveResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createSavedQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/CreateSavedQuery") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/savedQueries", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "savedQueryId", request.getSavedQueryId()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("savedQuery", request.getSavedQuery())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SavedQuery.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getSavedQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/GetSavedQuery") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/savedQueries/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SavedQuery.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listSavedQueriesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/ListSavedQueries") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{parent=*/*}/savedQueries", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "filter", request.getFilter()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListSavedQueriesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateSavedQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/UpdateSavedQuery") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{savedQuery.name=*/*/savedQueries/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "savedQuery.name", request.getSavedQuery().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("savedQuery", request.getSavedQuery())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SavedQuery.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteSavedQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/DeleteSavedQuery") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{name=*/*/savedQueries/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + BatchGetEffectiveIamPoliciesRequest, BatchGetEffectiveIamPoliciesResponse> + batchGetEffectiveIamPoliciesMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName("google.cloud.asset.v1.AssetService/BatchGetEffectiveIamPolicies") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/{scope=*/*}/effectiveIamPolicies:batchGet", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "scope", request.getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "names", request.getNamesList()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BatchGetEffectiveIamPoliciesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable exportAssetsCallable; + private final OperationCallable + exportAssetsOperationCallable; + private final UnaryCallable listAssetsCallable; + private final UnaryCallable listAssetsPagedCallable; + private final UnaryCallable + batchGetAssetsHistoryCallable; + private final UnaryCallable createFeedCallable; + private final UnaryCallable getFeedCallable; + private final UnaryCallable listFeedsCallable; + private final UnaryCallable updateFeedCallable; + private final UnaryCallable deleteFeedCallable; + private final UnaryCallable + searchAllResourcesCallable; + private final UnaryCallable + searchAllResourcesPagedCallable; + private final UnaryCallable + searchAllIamPoliciesCallable; + private final UnaryCallable + searchAllIamPoliciesPagedCallable; + private final UnaryCallable + analyzeIamPolicyCallable; + private final UnaryCallable + analyzeIamPolicyLongrunningCallable; + private final OperationCallable< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningMetadata> + analyzeIamPolicyLongrunningOperationCallable; + private final UnaryCallable analyzeMoveCallable; + private final UnaryCallable createSavedQueryCallable; + private final UnaryCallable getSavedQueryCallable; + private final UnaryCallable + listSavedQueriesCallable; + private final UnaryCallable + listSavedQueriesPagedCallable; + private final UnaryCallable updateSavedQueryCallable; + private final UnaryCallable deleteSavedQueryCallable; + private final UnaryCallable< + BatchGetEffectiveIamPoliciesRequest, BatchGetEffectiveIamPoliciesResponse> + batchGetEffectiveIamPoliciesCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssetServiceStub create(AssetServiceStubSettings settings) + throws IOException { + return new HttpJsonAssetServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssetServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssetServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssetServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub( + AssetServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings exportAssetsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(exportAssetsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listAssetsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listAssetsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchGetAssetsHistoryTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(batchGetAssetsHistoryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listFeedsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listFeedsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + searchAllResourcesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(searchAllResourcesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + searchAllIamPoliciesTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + analyzeIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(analyzeIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + analyzeIamPolicyLongrunningTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(analyzeIamPolicyLongrunningMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings analyzeMoveTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(analyzeMoveMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createSavedQueryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createSavedQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getSavedQueryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getSavedQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listSavedQueriesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listSavedQueriesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateSavedQueryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateSavedQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteSavedQueryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteSavedQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchGetEffectiveIamPoliciesTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(batchGetEffectiveIamPoliciesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.exportAssetsCallable = + callableFactory.createUnaryCallable( + exportAssetsTransportSettings, settings.exportAssetsSettings(), clientContext); + this.exportAssetsOperationCallable = + callableFactory.createOperationCallable( + exportAssetsTransportSettings, + settings.exportAssetsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listAssetsCallable = + callableFactory.createUnaryCallable( + listAssetsTransportSettings, settings.listAssetsSettings(), clientContext); + this.listAssetsPagedCallable = + callableFactory.createPagedCallable( + listAssetsTransportSettings, settings.listAssetsSettings(), clientContext); + this.batchGetAssetsHistoryCallable = + callableFactory.createUnaryCallable( + batchGetAssetsHistoryTransportSettings, + settings.batchGetAssetsHistorySettings(), + clientContext); + this.createFeedCallable = + callableFactory.createUnaryCallable( + createFeedTransportSettings, settings.createFeedSettings(), clientContext); + this.getFeedCallable = + callableFactory.createUnaryCallable( + getFeedTransportSettings, settings.getFeedSettings(), clientContext); + this.listFeedsCallable = + callableFactory.createUnaryCallable( + listFeedsTransportSettings, settings.listFeedsSettings(), clientContext); + this.updateFeedCallable = + callableFactory.createUnaryCallable( + updateFeedTransportSettings, settings.updateFeedSettings(), clientContext); + this.deleteFeedCallable = + callableFactory.createUnaryCallable( + deleteFeedTransportSettings, settings.deleteFeedSettings(), clientContext); + this.searchAllResourcesCallable = + callableFactory.createUnaryCallable( + searchAllResourcesTransportSettings, + settings.searchAllResourcesSettings(), + clientContext); + this.searchAllResourcesPagedCallable = + callableFactory.createPagedCallable( + searchAllResourcesTransportSettings, + settings.searchAllResourcesSettings(), + clientContext); + this.searchAllIamPoliciesCallable = + callableFactory.createUnaryCallable( + searchAllIamPoliciesTransportSettings, + settings.searchAllIamPoliciesSettings(), + clientContext); + this.searchAllIamPoliciesPagedCallable = + callableFactory.createPagedCallable( + searchAllIamPoliciesTransportSettings, + settings.searchAllIamPoliciesSettings(), + clientContext); + this.analyzeIamPolicyCallable = + callableFactory.createUnaryCallable( + analyzeIamPolicyTransportSettings, settings.analyzeIamPolicySettings(), clientContext); + this.analyzeIamPolicyLongrunningCallable = + callableFactory.createUnaryCallable( + analyzeIamPolicyLongrunningTransportSettings, + settings.analyzeIamPolicyLongrunningSettings(), + clientContext); + this.analyzeIamPolicyLongrunningOperationCallable = + callableFactory.createOperationCallable( + analyzeIamPolicyLongrunningTransportSettings, + settings.analyzeIamPolicyLongrunningOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.analyzeMoveCallable = + callableFactory.createUnaryCallable( + analyzeMoveTransportSettings, settings.analyzeMoveSettings(), clientContext); + this.createSavedQueryCallable = + callableFactory.createUnaryCallable( + createSavedQueryTransportSettings, settings.createSavedQuerySettings(), clientContext); + this.getSavedQueryCallable = + callableFactory.createUnaryCallable( + getSavedQueryTransportSettings, settings.getSavedQuerySettings(), clientContext); + this.listSavedQueriesCallable = + callableFactory.createUnaryCallable( + listSavedQueriesTransportSettings, settings.listSavedQueriesSettings(), clientContext); + this.listSavedQueriesPagedCallable = + callableFactory.createPagedCallable( + listSavedQueriesTransportSettings, settings.listSavedQueriesSettings(), clientContext); + this.updateSavedQueryCallable = + callableFactory.createUnaryCallable( + updateSavedQueryTransportSettings, settings.updateSavedQuerySettings(), clientContext); + this.deleteSavedQueryCallable = + callableFactory.createUnaryCallable( + deleteSavedQueryTransportSettings, settings.deleteSavedQuerySettings(), clientContext); + this.batchGetEffectiveIamPoliciesCallable = + callableFactory.createUnaryCallable( + batchGetEffectiveIamPoliciesTransportSettings, + settings.batchGetEffectiveIamPoliciesSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(exportAssetsMethodDescriptor); + methodDescriptors.add(listAssetsMethodDescriptor); + methodDescriptors.add(batchGetAssetsHistoryMethodDescriptor); + methodDescriptors.add(createFeedMethodDescriptor); + methodDescriptors.add(getFeedMethodDescriptor); + methodDescriptors.add(listFeedsMethodDescriptor); + methodDescriptors.add(updateFeedMethodDescriptor); + methodDescriptors.add(deleteFeedMethodDescriptor); + methodDescriptors.add(searchAllResourcesMethodDescriptor); + methodDescriptors.add(searchAllIamPoliciesMethodDescriptor); + methodDescriptors.add(analyzeIamPolicyMethodDescriptor); + methodDescriptors.add(analyzeIamPolicyLongrunningMethodDescriptor); + methodDescriptors.add(analyzeMoveMethodDescriptor); + methodDescriptors.add(createSavedQueryMethodDescriptor); + methodDescriptors.add(getSavedQueryMethodDescriptor); + methodDescriptors.add(listSavedQueriesMethodDescriptor); + methodDescriptors.add(updateSavedQueryMethodDescriptor); + methodDescriptors.add(deleteSavedQueryMethodDescriptor); + methodDescriptors.add(batchGetEffectiveIamPoliciesMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable exportAssetsCallable() { + return exportAssetsCallable; + } + + @Override + public OperationCallable + exportAssetsOperationCallable() { + return exportAssetsOperationCallable; + } + + @Override + public UnaryCallable listAssetsCallable() { + return listAssetsCallable; + } + + @Override + public UnaryCallable listAssetsPagedCallable() { + return listAssetsPagedCallable; + } + + @Override + public UnaryCallable + batchGetAssetsHistoryCallable() { + return batchGetAssetsHistoryCallable; + } + + @Override + public UnaryCallable createFeedCallable() { + return createFeedCallable; + } + + @Override + public UnaryCallable getFeedCallable() { + return getFeedCallable; + } + + @Override + public UnaryCallable listFeedsCallable() { + return listFeedsCallable; + } + + @Override + public UnaryCallable updateFeedCallable() { + return updateFeedCallable; + } + + @Override + public UnaryCallable deleteFeedCallable() { + return deleteFeedCallable; + } + + @Override + public UnaryCallable + searchAllResourcesCallable() { + return searchAllResourcesCallable; + } + + @Override + public UnaryCallable + searchAllResourcesPagedCallable() { + return searchAllResourcesPagedCallable; + } + + @Override + public UnaryCallable + searchAllIamPoliciesCallable() { + return searchAllIamPoliciesCallable; + } + + @Override + public UnaryCallable + searchAllIamPoliciesPagedCallable() { + return searchAllIamPoliciesPagedCallable; + } + + @Override + public UnaryCallable + analyzeIamPolicyCallable() { + return analyzeIamPolicyCallable; + } + + @Override + public UnaryCallable + analyzeIamPolicyLongrunningCallable() { + return analyzeIamPolicyLongrunningCallable; + } + + @Override + public OperationCallable< + AnalyzeIamPolicyLongrunningRequest, + AnalyzeIamPolicyLongrunningResponse, + AnalyzeIamPolicyLongrunningMetadata> + analyzeIamPolicyLongrunningOperationCallable() { + return analyzeIamPolicyLongrunningOperationCallable; + } + + @Override + public UnaryCallable analyzeMoveCallable() { + return analyzeMoveCallable; + } + + @Override + public UnaryCallable createSavedQueryCallable() { + return createSavedQueryCallable; + } + + @Override + public UnaryCallable getSavedQueryCallable() { + return getSavedQueryCallable; + } + + @Override + public UnaryCallable + listSavedQueriesCallable() { + return listSavedQueriesCallable; + } + + @Override + public UnaryCallable + listSavedQueriesPagedCallable() { + return listSavedQueriesPagedCallable; + } + + @Override + public UnaryCallable updateSavedQueryCallable() { + return updateSavedQueryCallable; + } + + @Override + public UnaryCallable deleteSavedQueryCallable() { + return deleteSavedQueryCallable; + } + + @Override + public UnaryCallable + batchGetEffectiveIamPoliciesCallable() { + return batchGetEffectiveIamPoliciesCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceClient.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceClient.java index 8745c46ab..4610f6c88 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceClient.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceClient.java @@ -102,6 +102,20 @@ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * AssetServiceSettings assetServiceSettings =
+ *     AssetServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceSettings.java index 9b9c95e86..c6b476cdd 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/AssetServiceSettings.java @@ -24,6 +24,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -113,11 +114,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssetServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return AssetServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssetServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssetServiceStubSettings.defaultTransportChannelProvider(); } @@ -127,11 +135,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssetServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -169,6 +183,11 @@ private static Builder createDefault() { return new Builder(AssetServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssetServiceStubSettings.newHttpJsonBuilder()); + } + public AssetServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssetServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/AssetServiceStubSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/AssetServiceStubSettings.java index 401920107..808ed4c8f 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/AssetServiceStubSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/AssetServiceStubSettings.java @@ -28,6 +28,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -260,6 +263,11 @@ public AssetServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssetServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssetServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -292,18 +300,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) @@ -311,11 +326,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssetServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -418,6 +452,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .searchAllResourcesSettings() diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceCallableFactory.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceCallableFactory.java new file mode 100644 index 000000000..fc1a62cf8 --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the AssetService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceStub.java new file mode 100644 index 000000000..403f13d0c --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p1beta1/stub/HttpJsonAssetServiceStub.java @@ -0,0 +1,292 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.stub; + +import static com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; +import static com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllResourcesPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesRequest; +import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse; +import com.google.cloud.asset.v1p1beta1.SearchAllResourcesRequest; +import com.google.cloud.asset.v1p1beta1.SearchAllResourcesResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the AssetService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceStub extends AssetServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + searchAllResourcesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p1beta1.AssetService/SearchAllResources") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p1beta1/{scope=*/*}/resources:searchAll", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "scope", request.getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "assetTypes", request.getAssetTypesList()); + serializer.putQueryParam(fields, "orderBy", request.getOrderBy()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchAllResourcesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + SearchAllIamPoliciesRequest, SearchAllIamPoliciesResponse> + searchAllIamPoliciesMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName("google.cloud.asset.v1p1beta1.AssetService/SearchAllIamPolicies") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p1beta1/{scope=*/*}/iamPolicies:searchAll", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "scope", request.getScope()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "query", request.getQuery()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SearchAllIamPoliciesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable + searchAllResourcesCallable; + private final UnaryCallable + searchAllResourcesPagedCallable; + private final UnaryCallable + searchAllIamPoliciesCallable; + private final UnaryCallable + searchAllIamPoliciesPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssetServiceStub create(AssetServiceStubSettings settings) + throws IOException { + return new HttpJsonAssetServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssetServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssetServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssetServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub( + AssetServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + searchAllResourcesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(searchAllResourcesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + searchAllIamPoliciesTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(searchAllIamPoliciesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.searchAllResourcesCallable = + callableFactory.createUnaryCallable( + searchAllResourcesTransportSettings, + settings.searchAllResourcesSettings(), + clientContext); + this.searchAllResourcesPagedCallable = + callableFactory.createPagedCallable( + searchAllResourcesTransportSettings, + settings.searchAllResourcesSettings(), + clientContext); + this.searchAllIamPoliciesCallable = + callableFactory.createUnaryCallable( + searchAllIamPoliciesTransportSettings, + settings.searchAllIamPoliciesSettings(), + clientContext); + this.searchAllIamPoliciesPagedCallable = + callableFactory.createPagedCallable( + searchAllIamPoliciesTransportSettings, + settings.searchAllIamPoliciesSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(searchAllResourcesMethodDescriptor); + methodDescriptors.add(searchAllIamPoliciesMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + searchAllResourcesCallable() { + return searchAllResourcesCallable; + } + + @Override + public UnaryCallable + searchAllResourcesPagedCallable() { + return searchAllResourcesPagedCallable; + } + + @Override + public UnaryCallable + searchAllIamPoliciesCallable() { + return searchAllIamPoliciesCallable; + } + + @Override + public UnaryCallable + searchAllIamPoliciesPagedCallable() { + return searchAllIamPoliciesPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceClient.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceClient.java index 5916e52c1..99203e50e 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceClient.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceClient.java @@ -90,6 +90,20 @@ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * AssetServiceSettings assetServiceSettings =
+ *     AssetServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceSettings.java index 77fd9226e..557fdc0d9 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/AssetServiceSettings.java @@ -21,6 +21,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -119,11 +120,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssetServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return AssetServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssetServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssetServiceStubSettings.defaultTransportChannelProvider(); } @@ -133,11 +141,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssetServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -175,6 +189,11 @@ private static Builder createDefault() { return new Builder(AssetServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssetServiceStubSettings.newHttpJsonBuilder()); + } + public AssetServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssetServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/AssetServiceStubSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/AssetServiceStubSettings.java index e3de865da..daf1b5fbe 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/AssetServiceStubSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/AssetServiceStubSettings.java @@ -24,6 +24,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; @@ -126,6 +129,11 @@ public AssetServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssetServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssetServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -158,18 +166,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) @@ -177,11 +192,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssetServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -307,6 +341,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .createFeedSettings() diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceCallableFactory.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceCallableFactory.java new file mode 100644 index 000000000..a21066222 --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the AssetService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceStub.java new file mode 100644 index 000000000..9fe724efd --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p2beta1/stub/HttpJsonAssetServiceStub.java @@ -0,0 +1,390 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1p2beta1.CreateFeedRequest; +import com.google.cloud.asset.v1p2beta1.DeleteFeedRequest; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.GetFeedRequest; +import com.google.cloud.asset.v1p2beta1.ListFeedsRequest; +import com.google.cloud.asset.v1p2beta1.ListFeedsResponse; +import com.google.cloud.asset.v1p2beta1.UpdateFeedRequest; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the AssetService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceStub extends AssetServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor createFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/CreateFeed") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p2beta1/{parent=*/*}/feeds", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Feed.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/GetFeed") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p2beta1/{name=*/*/feeds/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Feed.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listFeedsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/ListFeeds") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p2beta1/{parent=*/*}/feeds", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListFeedsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor updateFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/UpdateFeed") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p2beta1/{feed.name=*/*/feeds/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "feed.name", request.getFeed().getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("*", request.toBuilder().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Feed.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor deleteFeedMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p2beta1.AssetService/DeleteFeed") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p2beta1/{name=*/*/feeds/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable createFeedCallable; + private final UnaryCallable getFeedCallable; + private final UnaryCallable listFeedsCallable; + private final UnaryCallable updateFeedCallable; + private final UnaryCallable deleteFeedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssetServiceStub create(AssetServiceStubSettings settings) + throws IOException { + return new HttpJsonAssetServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssetServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssetServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssetServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub( + AssetServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings createFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listFeedsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listFeedsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteFeedTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteFeedMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createFeedCallable = + callableFactory.createUnaryCallable( + createFeedTransportSettings, settings.createFeedSettings(), clientContext); + this.getFeedCallable = + callableFactory.createUnaryCallable( + getFeedTransportSettings, settings.getFeedSettings(), clientContext); + this.listFeedsCallable = + callableFactory.createUnaryCallable( + listFeedsTransportSettings, settings.listFeedsSettings(), clientContext); + this.updateFeedCallable = + callableFactory.createUnaryCallable( + updateFeedTransportSettings, settings.updateFeedSettings(), clientContext); + this.deleteFeedCallable = + callableFactory.createUnaryCallable( + deleteFeedTransportSettings, settings.deleteFeedSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createFeedMethodDescriptor); + methodDescriptors.add(getFeedMethodDescriptor); + methodDescriptors.add(listFeedsMethodDescriptor); + methodDescriptors.add(updateFeedMethodDescriptor); + methodDescriptors.add(deleteFeedMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable createFeedCallable() { + return createFeedCallable; + } + + @Override + public UnaryCallable getFeedCallable() { + return getFeedCallable; + } + + @Override + public UnaryCallable listFeedsCallable() { + return listFeedsCallable; + } + + @Override + public UnaryCallable updateFeedCallable() { + return updateFeedCallable; + } + + @Override + public UnaryCallable deleteFeedCallable() { + return deleteFeedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceClient.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceClient.java index afe04e032..4a78f7783 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceClient.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceClient.java @@ -18,13 +18,13 @@ import com.google.api.core.BetaApi; import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.httpjson.longrunning.OperationsClient; import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.asset.v1p4beta1.stub.AssetServiceStub; import com.google.cloud.asset.v1p4beta1.stub.AssetServiceStubSettings; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -97,6 +97,20 @@ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * AssetServiceSettings assetServiceSettings =
+ *     AssetServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -104,7 +118,8 @@ public class AssetServiceClient implements BackgroundResource { private final AssetServiceSettings settings; private final AssetServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of AssetServiceClient with default settings. */ public static final AssetServiceClient create() throws IOException { @@ -135,13 +150,17 @@ public static final AssetServiceClient create(AssetServiceStub stub) { protected AssetServiceClient(AssetServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((AssetServiceStubSettings) settings.getStubSettings()).createStub(); - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } protected AssetServiceClient(AssetServiceStub stub) { this.settings = null; this.stub = stub; - this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + this.operationsClient = + com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub()); + this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub()); } public final AssetServiceSettings getSettings() { @@ -156,10 +175,18 @@ public AssetServiceStub getStub() { * Returns the OperationsClient that can be used to query the status of a long-running operation * returned by another API method call. */ - public final OperationsClient getOperationsClient() { + public final com.google.longrunning.OperationsClient getOperationsClient() { return operationsClient; } + /** + * Returns the OperationsClient that can be used to query the status of a long-running operation + * returned by another API method call. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Analyzes IAM policies based on the specified request. Returns a list of diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceSettings.java index dc4d4e3ef..5311b8619 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/AssetServiceSettings.java @@ -21,6 +21,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -117,11 +118,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssetServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return AssetServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssetServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssetServiceStubSettings.defaultTransportChannelProvider(); } @@ -131,11 +139,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssetServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -173,6 +187,11 @@ private static Builder createDefault() { return new Builder(AssetServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssetServiceStubSettings.newHttpJsonBuilder()); + } + public AssetServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssetServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStub.java index bae7a3139..25e175a79 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStub.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStub.java @@ -39,7 +39,11 @@ public abstract class AssetServiceStub implements BackgroundResource { public OperationsStub getOperationsStub() { - throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + return null; + } + + public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() { + return null; } public UnaryCallable diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStubSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStubSettings.java index 4e9f45949..d61b88111 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStubSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/AssetServiceStubSettings.java @@ -25,6 +25,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -127,6 +130,11 @@ public AssetServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssetServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssetServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -159,18 +167,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) @@ -178,11 +193,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssetServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -298,6 +332,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .analyzeIamPolicySettings() diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceCallableFactory.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceCallableFactory.java new file mode 100644 index 000000000..9bdf29e21 --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the AssetService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceStub.java new file mode 100644 index 000000000..df17ff20d --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p4beta1/stub/HttpJsonAssetServiceStub.java @@ -0,0 +1,299 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshot; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1p4beta1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1p4beta1.AnalyzeIamPolicyResponse; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisRequest; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisResponse; +import com.google.longrunning.Operation; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the AssetService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceStub extends AssetServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(ExportIamPolicyAnalysisResponse.getDescriptor()) + .add(ExportIamPolicyAnalysisRequest.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + analyzeIamPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p4beta1.AssetService/AnalyzeIamPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p4beta1/{analysisQuery.parent=*/*}:analyzeIamPolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "analysisQuery.parent", + request.getAnalysisQuery().getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "analysisQuery", request.getAnalysisQuery()); + serializer.putQueryParam(fields, "options", request.getOptions()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AnalyzeIamPolicyResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + exportIamPolicyAnalysisMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.asset.v1p4beta1.AssetService/ExportIamPolicyAnalysis") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p4beta1/{analysisQuery.parent=*/*}:exportIamPolicyAnalysis", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, + "analysisQuery.parent", + request.getAnalysisQuery().getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("*", request.toBuilder().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (ExportIamPolicyAnalysisRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable + analyzeIamPolicyCallable; + private final UnaryCallable + exportIamPolicyAnalysisCallable; + private final OperationCallable< + ExportIamPolicyAnalysisRequest, + ExportIamPolicyAnalysisResponse, + ExportIamPolicyAnalysisRequest> + exportIamPolicyAnalysisOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssetServiceStub create(AssetServiceStubSettings settings) + throws IOException { + return new HttpJsonAssetServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssetServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssetServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssetServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub( + AssetServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + analyzeIamPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(analyzeIamPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + exportIamPolicyAnalysisTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(exportIamPolicyAnalysisMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.analyzeIamPolicyCallable = + callableFactory.createUnaryCallable( + analyzeIamPolicyTransportSettings, settings.analyzeIamPolicySettings(), clientContext); + this.exportIamPolicyAnalysisCallable = + callableFactory.createUnaryCallable( + exportIamPolicyAnalysisTransportSettings, + settings.exportIamPolicyAnalysisSettings(), + clientContext); + this.exportIamPolicyAnalysisOperationCallable = + callableFactory.createOperationCallable( + exportIamPolicyAnalysisTransportSettings, + settings.exportIamPolicyAnalysisOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(analyzeIamPolicyMethodDescriptor); + methodDescriptors.add(exportIamPolicyAnalysisMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable + analyzeIamPolicyCallable() { + return analyzeIamPolicyCallable; + } + + @Override + public UnaryCallable + exportIamPolicyAnalysisCallable() { + return exportIamPolicyAnalysisCallable; + } + + @Override + public OperationCallable< + ExportIamPolicyAnalysisRequest, + ExportIamPolicyAnalysisResponse, + ExportIamPolicyAnalysisRequest> + exportIamPolicyAnalysisOperationCallable() { + return exportIamPolicyAnalysisOperationCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceClient.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceClient.java index 7ca3cb104..32d438775 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceClient.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceClient.java @@ -107,6 +107,20 @@ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * AssetServiceSettings assetServiceSettings =
+ *     AssetServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceSettings.java index c29b30874..e3c529721 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/AssetServiceSettings.java @@ -23,6 +23,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -102,11 +103,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return AssetServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return AssetServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return AssetServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return AssetServiceStubSettings.defaultTransportChannelProvider(); } @@ -116,11 +124,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return AssetServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -158,6 +172,11 @@ private static Builder createDefault() { return new Builder(AssetServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(AssetServiceStubSettings.newHttpJsonBuilder()); + } + public AssetServiceStubSettings.Builder getStubSettingsBuilder() { return ((AssetServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/AssetServiceStubSettings.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/AssetServiceStubSettings.java index e724f9ba1..bc768614f 100644 --- a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/AssetServiceStubSettings.java +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/AssetServiceStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -161,6 +164,11 @@ public AssetServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcAssetServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonAssetServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -193,18 +201,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) @@ -212,11 +227,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(AssetServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return AssetServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -308,6 +342,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { builder .listAssetsSettings() diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceCallableFactory.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceCallableFactory.java new file mode 100644 index 000000000..cec881476 --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the AssetService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceStub.java b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceStub.java new file mode 100644 index 000000000..ef08931ef --- /dev/null +++ b/google-cloud-asset/src/main/java/com/google/cloud/asset/v1p5beta1/stub/HttpJsonAssetServiceStub.java @@ -0,0 +1,209 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.stub; + +import static com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.asset.v1p5beta1.ListAssetsRequest; +import com.google.cloud.asset.v1p5beta1.ListAssetsResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the AssetService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonAssetServiceStub extends AssetServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listAssetsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.asset.v1p5beta1.AssetService/ListAssets") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1p5beta1/{parent=*/*}/assets", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "assetTypes", request.getAssetTypesList()); + serializer.putQueryParam( + fields, "contentType", request.getContentType()); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + serializer.putQueryParam(fields, "readTime", request.getReadTime()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListAssetsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable listAssetsCallable; + private final UnaryCallable listAssetsPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonAssetServiceStub create(AssetServiceStubSettings settings) + throws IOException { + return new HttpJsonAssetServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonAssetServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonAssetServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonAssetServiceStub( + AssetServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub(AssetServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonAssetServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonAssetServiceStub, using the given settings. This is protected + * so that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected HttpJsonAssetServiceStub( + AssetServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings listAssetsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listAssetsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listAssetsCallable = + callableFactory.createUnaryCallable( + listAssetsTransportSettings, settings.listAssetsSettings(), clientContext); + this.listAssetsPagedCallable = + callableFactory.createPagedCallable( + listAssetsTransportSettings, settings.listAssetsSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listAssetsMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listAssetsCallable() { + return listAssetsCallable; + } + + @Override + public UnaryCallable listAssetsPagedCallable() { + return listAssetsPagedCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-asset/src/test/java/com/google/cloud/asset/v1/AssetServiceClientHttpJsonTest.java b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1/AssetServiceClientHttpJsonTest.java new file mode 100644 index 000000000..24723ab81 --- /dev/null +++ b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1/AssetServiceClientHttpJsonTest.java @@ -0,0 +1,1710 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1; + +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.ListSavedQueriesPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; +import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.asset.v1.stub.HttpJsonAssetServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Duration; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.protobuf.Timestamp; +import com.google.type.Expr; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class AssetServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssetServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssetServiceStub.getMethodDescriptors(), + AssetServiceSettings.getDefaultEndpoint()); + AssetServiceSettings settings = + AssetServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssetServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void exportAssetsTest() throws Exception { + ExportAssetsResponse expectedResponse = + ExportAssetsResponse.newBuilder() + .setReadTime(Timestamp.newBuilder().build()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .setOutputResult(OutputResult.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("exportAssetsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ExportAssetsRequest request = + ExportAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setOutputConfig(OutputConfig.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + + ExportAssetsResponse actualResponse = client.exportAssetsAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void exportAssetsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ExportAssetsRequest request = + ExportAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setOutputConfig(OutputConfig.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + client.exportAssetsAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listAssetsTest() throws Exception { + Asset responsesElement = Asset.newBuilder().build(); + ListAssetsResponse expectedResponse = + ListAssetsResponse.newBuilder() + .setNextPageToken("") + .addAllAssets(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ResourceName parent = FolderName.of("[FOLDER]"); + + ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listAssetsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ResourceName parent = FolderName.of("[FOLDER]"); + client.listAssets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listAssetsTest2() throws Exception { + Asset responsesElement = Asset.newBuilder().build(); + ListAssetsResponse expectedResponse = + ListAssetsResponse.newBuilder() + .setNextPageToken("") + .addAllAssets(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + + ListAssetsPagedResponse pagedListResponse = client.listAssets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listAssetsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + client.listAssets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchGetAssetsHistoryTest() throws Exception { + BatchGetAssetsHistoryResponse expectedResponse = + BatchGetAssetsHistoryResponse.newBuilder() + .addAllAssets(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + BatchGetAssetsHistoryRequest request = + BatchGetAssetsHistoryRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .addAllAssetNames(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setReadTimeWindow(TimeWindow.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + + BatchGetAssetsHistoryResponse actualResponse = client.batchGetAssetsHistory(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void batchGetAssetsHistoryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchGetAssetsHistoryRequest request = + BatchGetAssetsHistoryRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .addAllAssetNames(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setReadTimeWindow(TimeWindow.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + client.batchGetAssetsHistory(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createFeedTest() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .setCondition(Expr.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + + Feed actualResponse = client.createFeed(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + client.createFeed(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getFeedTest() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .setCondition(Expr.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + + Feed actualResponse = client.getFeed(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + client.getFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getFeedTest2() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .setCondition(Expr.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "name-2459/name-2459/feeds/feed-2459"; + + Feed actualResponse = client.getFeed(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getFeedExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "name-2459/name-2459/feeds/feed-2459"; + client.getFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listFeedsTest() throws Exception { + ListFeedsResponse expectedResponse = + ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + + ListFeedsResponse actualResponse = client.listFeeds(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listFeedsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + client.listFeeds(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateFeedTest() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .setCondition(Expr.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + Feed feed = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .setCondition(Expr.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + + Feed actualResponse = client.updateFeed(feed); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Feed feed = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .setCondition(Expr.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + client.updateFeed(feed); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteFeedTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + + client.deleteFeed(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + client.deleteFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteFeedTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "name-2459/name-2459/feeds/feed-2459"; + + client.deleteFeed(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteFeedExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "name-2459/name-2459/feeds/feed-2459"; + client.deleteFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchAllResourcesTest() throws Exception { + ResourceSearchResult responsesElement = ResourceSearchResult.newBuilder().build(); + SearchAllResourcesResponse expectedResponse = + SearchAllResourcesResponse.newBuilder() + .setNextPageToken("") + .addAllResults(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + List assetTypes = new ArrayList<>(); + + SearchAllResourcesPagedResponse pagedListResponse = + client.searchAllResources(scope, query, assetTypes); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchAllResourcesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + List assetTypes = new ArrayList<>(); + client.searchAllResources(scope, query, assetTypes); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchAllIamPoliciesTest() throws Exception { + IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build(); + SearchAllIamPoliciesResponse expectedResponse = + SearchAllIamPoliciesResponse.newBuilder() + .setNextPageToken("") + .addAllResults(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + + SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchAllIamPoliciesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + client.searchAllIamPolicies(scope, query); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void analyzeIamPolicyTest() throws Exception { + AnalyzeIamPolicyResponse expectedResponse = + AnalyzeIamPolicyResponse.newBuilder() + .setMainAnalysis(AnalyzeIamPolicyResponse.IamPolicyAnalysis.newBuilder().build()) + .addAllServiceAccountImpersonationAnalysis( + new ArrayList()) + .setFullyExplored(true) + .build(); + mockService.addResponse(expectedResponse); + + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setScope("scope-2319/scope-2319") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .setOptions(IamPolicyAnalysisQuery.Options.newBuilder().build()) + .setConditionContext( + IamPolicyAnalysisQuery.ConditionContext.newBuilder().build()) + .build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setExecutionTimeout(Duration.newBuilder().build()) + .build(); + + AnalyzeIamPolicyResponse actualResponse = client.analyzeIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void analyzeIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setScope("scope-2319/scope-2319") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .setOptions(IamPolicyAnalysisQuery.Options.newBuilder().build()) + .setConditionContext( + IamPolicyAnalysisQuery.ConditionContext.newBuilder().build()) + .build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setExecutionTimeout(Duration.newBuilder().build()) + .build(); + client.analyzeIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void analyzeIamPolicyLongrunningTest() throws Exception { + AnalyzeIamPolicyLongrunningResponse expectedResponse = + AnalyzeIamPolicyLongrunningResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("analyzeIamPolicyLongrunningTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setScope("scope-2319/scope-2319") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .setOptions(IamPolicyAnalysisQuery.Options.newBuilder().build()) + .setConditionContext( + IamPolicyAnalysisQuery.ConditionContext.newBuilder().build()) + .build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + + AnalyzeIamPolicyLongrunningResponse actualResponse = + client.analyzeIamPolicyLongrunningAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void analyzeIamPolicyLongrunningExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setScope("scope-2319/scope-2319") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .setOptions(IamPolicyAnalysisQuery.Options.newBuilder().build()) + .setConditionContext( + IamPolicyAnalysisQuery.ConditionContext.newBuilder().build()) + .build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + client.analyzeIamPolicyLongrunningAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void analyzeMoveTest() throws Exception { + AnalyzeMoveResponse expectedResponse = + AnalyzeMoveResponse.newBuilder().addAllMoveAnalysis(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + AnalyzeMoveRequest request = + AnalyzeMoveRequest.newBuilder() + .setResource("resource-4407/resource-4407") + .setDestinationParent("destinationParent-1733659048") + .build(); + + AnalyzeMoveResponse actualResponse = client.analyzeMove(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void analyzeMoveExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AnalyzeMoveRequest request = + AnalyzeMoveRequest.newBuilder() + .setResource("resource-4407/resource-4407") + .setDestinationParent("destinationParent-1733659048") + .build(); + client.analyzeMove(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSavedQueryTest() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + + SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createSavedQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSavedQueryTest2() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + + SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createSavedQueryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSavedQueryTest3() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + + SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createSavedQueryExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSavedQueryTest4() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + + SavedQuery actualResponse = client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createSavedQueryExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + client.createSavedQuery(parent, savedQuery, savedQueryId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSavedQueryTest() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); + + SavedQuery actualResponse = client.getSavedQuery(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getSavedQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); + client.getSavedQuery(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSavedQueryTest2() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "name-3263/name-3263/savedQueries/savedQuerie-3263"; + + SavedQuery actualResponse = client.getSavedQuery(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getSavedQueryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "name-3263/name-3263/savedQueries/savedQuerie-3263"; + client.getSavedQuery(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSavedQueriesTest() throws Exception { + SavedQuery responsesElement = SavedQuery.newBuilder().build(); + ListSavedQueriesResponse expectedResponse = + ListSavedQueriesResponse.newBuilder() + .setNextPageToken("") + .addAllSavedQueries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSavedQueriesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + client.listSavedQueries(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSavedQueriesTest2() throws Exception { + SavedQuery responsesElement = SavedQuery.newBuilder().build(); + ListSavedQueriesResponse expectedResponse = + ListSavedQueriesResponse.newBuilder() + .setNextPageToken("") + .addAllSavedQueries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSavedQueriesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + client.listSavedQueries(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSavedQueriesTest3() throws Exception { + SavedQuery responsesElement = SavedQuery.newBuilder().build(); + ListSavedQueriesResponse expectedResponse = + ListSavedQueriesResponse.newBuilder() + .setNextPageToken("") + .addAllSavedQueries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSavedQueriesExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listSavedQueries(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSavedQueriesTest4() throws Exception { + SavedQuery responsesElement = SavedQuery.newBuilder().build(); + ListSavedQueriesResponse expectedResponse = + ListSavedQueriesResponse.newBuilder() + .setNextPageToken("") + .addAllSavedQueries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + + ListSavedQueriesPagedResponse pagedListResponse = client.listSavedQueries(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSavedQueriesList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listSavedQueriesExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + client.listSavedQueries(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateSavedQueryTest() throws Exception { + SavedQuery expectedResponse = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + SavedQuery savedQuery = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + SavedQuery actualResponse = client.updateSavedQuery(savedQuery, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateSavedQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SavedQuery savedQuery = + SavedQuery.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .setDescription("description-1724546052") + .setCreateTime(Timestamp.newBuilder().build()) + .setCreator("creator1028554796") + .setLastUpdateTime(Timestamp.newBuilder().build()) + .setLastUpdater("lastUpdater1649733971") + .putAllLabels(new HashMap()) + .setContent(SavedQuery.QueryContent.newBuilder().build()) + .build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateSavedQuery(savedQuery, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteSavedQueryTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); + + client.deleteSavedQuery(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteSavedQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); + client.deleteSavedQuery(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteSavedQueryTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "name-3263/name-3263/savedQueries/savedQuerie-3263"; + + client.deleteSavedQuery(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteSavedQueryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "name-3263/name-3263/savedQueries/savedQuerie-3263"; + client.deleteSavedQuery(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchGetEffectiveIamPoliciesTest() throws Exception { + BatchGetEffectiveIamPoliciesResponse expectedResponse = + BatchGetEffectiveIamPoliciesResponse.newBuilder() + .addAllPolicyResults( + new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + BatchGetEffectiveIamPoliciesRequest request = + BatchGetEffectiveIamPoliciesRequest.newBuilder() + .setScope(FolderName.of("[FOLDER]").toString()) + .addAllNames(new ArrayList()) + .build(); + + BatchGetEffectiveIamPoliciesResponse actualResponse = + client.batchGetEffectiveIamPolicies(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void batchGetEffectiveIamPoliciesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchGetEffectiveIamPoliciesRequest request = + BatchGetEffectiveIamPoliciesRequest.newBuilder() + .setScope(FolderName.of("[FOLDER]").toString()) + .addAllNames(new ArrayList()) + .build(); + client.batchGetEffectiveIamPolicies(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p1beta1/AssetServiceClientHttpJsonTest.java b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p1beta1/AssetServiceClientHttpJsonTest.java new file mode 100644 index 000000000..1a4adb9a8 --- /dev/null +++ b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p1beta1/AssetServiceClientHttpJsonTest.java @@ -0,0 +1,186 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1; + +import static com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; +import static com.google.cloud.asset.v1p1beta1.AssetServiceClient.SearchAllResourcesPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.asset.v1p1beta1.stub.HttpJsonAssetServiceStub; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class AssetServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssetServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssetServiceStub.getMethodDescriptors(), + AssetServiceSettings.getDefaultEndpoint()); + AssetServiceSettings settings = + AssetServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssetServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void searchAllResourcesTest() throws Exception { + StandardResourceMetadata responsesElement = StandardResourceMetadata.newBuilder().build(); + SearchAllResourcesResponse expectedResponse = + SearchAllResourcesResponse.newBuilder() + .setNextPageToken("") + .addAllResults(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + List assetTypes = new ArrayList<>(); + + SearchAllResourcesPagedResponse pagedListResponse = + client.searchAllResources(scope, query, assetTypes); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchAllResourcesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + List assetTypes = new ArrayList<>(); + client.searchAllResources(scope, query, assetTypes); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void searchAllIamPoliciesTest() throws Exception { + IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build(); + SearchAllIamPoliciesResponse expectedResponse = + SearchAllIamPoliciesResponse.newBuilder() + .setNextPageToken("") + .addAllResults(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + + SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void searchAllIamPoliciesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String scope = "scope-2319/scope-2319"; + String query = "query107944136"; + client.searchAllIamPolicies(scope, query); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p2beta1/AssetServiceClientHttpJsonTest.java b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p2beta1/AssetServiceClientHttpJsonTest.java new file mode 100644 index 000000000..272ec68dc --- /dev/null +++ b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p2beta1/AssetServiceClientHttpJsonTest.java @@ -0,0 +1,403 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.asset.v1p2beta1.stub.HttpJsonAssetServiceStub; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class AssetServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssetServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssetServiceStub.getMethodDescriptors(), + AssetServiceSettings.getDefaultEndpoint()); + AssetServiceSettings settings = + AssetServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssetServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createFeedTest() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + + Feed actualResponse = client.createFeed(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void createFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + client.createFeed(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getFeedTest() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + + Feed actualResponse = client.getFeed(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + client.getFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getFeedTest2() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "name-2459/name-2459/feeds/feed-2459"; + + Feed actualResponse = client.getFeed(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void getFeedExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "name-2459/name-2459/feeds/feed-2459"; + client.getFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listFeedsTest() throws Exception { + ListFeedsResponse expectedResponse = + ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String parent = "parent-4715/parent-4715"; + + ListFeedsResponse actualResponse = client.listFeeds(parent); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listFeedsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "parent-4715/parent-4715"; + client.listFeeds(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateFeedTest() throws Exception { + Feed expectedResponse = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Feed feed = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .build(); + + Feed actualResponse = client.updateFeed(feed); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void updateFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Feed feed = + Feed.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) + .build(); + client.updateFeed(feed); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteFeedTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + + client.deleteFeed(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteFeedExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + client.deleteFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteFeedTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "name-2459/name-2459/feeds/feed-2459"; + + client.deleteFeed(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteFeedExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "name-2459/name-2459/feeds/feed-2459"; + client.deleteFeed(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p4beta1/AssetServiceClientHttpJsonTest.java b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p4beta1/AssetServiceClientHttpJsonTest.java new file mode 100644 index 000000000..ba3c44d89 --- /dev/null +++ b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p4beta1/AssetServiceClientHttpJsonTest.java @@ -0,0 +1,225 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.asset.v1p4beta1.stub.HttpJsonAssetServiceStub; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class AssetServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssetServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssetServiceStub.getMethodDescriptors(), + AssetServiceSettings.getDefaultEndpoint()); + AssetServiceSettings settings = + AssetServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssetServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void analyzeIamPolicyTest() throws Exception { + AnalyzeIamPolicyResponse expectedResponse = + AnalyzeIamPolicyResponse.newBuilder() + .setMainAnalysis(AnalyzeIamPolicyResponse.IamPolicyAnalysis.newBuilder().build()) + .addAllServiceAccountImpersonationAnalysis( + new ArrayList()) + .setFullyExplored(true) + .addAllNonCriticalErrors(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setParent("parent-4715/parent-4715") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .build()) + .setOptions(AnalyzeIamPolicyRequest.Options.newBuilder().build()) + .build(); + + AnalyzeIamPolicyResponse actualResponse = client.analyzeIamPolicy(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void analyzeIamPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setParent("parent-4715/parent-4715") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .build()) + .setOptions(AnalyzeIamPolicyRequest.Options.newBuilder().build()) + .build(); + client.analyzeIamPolicy(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void exportIamPolicyAnalysisTest() throws Exception { + ExportIamPolicyAnalysisResponse expectedResponse = + ExportIamPolicyAnalysisResponse.newBuilder() + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("exportIamPolicyAnalysisTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + ExportIamPolicyAnalysisRequest request = + ExportIamPolicyAnalysisRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setParent("parent-4715/parent-4715") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .build()) + .setOptions(ExportIamPolicyAnalysisRequest.Options.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + + ExportIamPolicyAnalysisResponse actualResponse = + client.exportIamPolicyAnalysisAsync(request).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void exportIamPolicyAnalysisExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ExportIamPolicyAnalysisRequest request = + ExportIamPolicyAnalysisRequest.newBuilder() + .setAnalysisQuery( + IamPolicyAnalysisQuery.newBuilder() + .setParent("parent-4715/parent-4715") + .setResourceSelector( + IamPolicyAnalysisQuery.ResourceSelector.newBuilder().build()) + .setIdentitySelector( + IamPolicyAnalysisQuery.IdentitySelector.newBuilder().build()) + .setAccessSelector(IamPolicyAnalysisQuery.AccessSelector.newBuilder().build()) + .build()) + .setOptions(ExportIamPolicyAnalysisRequest.Options.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + client.exportIamPolicyAnalysisAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p5beta1/AssetServiceClientHttpJsonTest.java b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p5beta1/AssetServiceClientHttpJsonTest.java new file mode 100644 index 000000000..1514c3cb5 --- /dev/null +++ b/google-cloud-asset/src/test/java/com/google/cloud/asset/v1p5beta1/AssetServiceClientHttpJsonTest.java @@ -0,0 +1,145 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1; + +import static com.google.cloud.asset.v1p5beta1.AssetServiceClient.ListAssetsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.asset.v1p5beta1.stub.HttpJsonAssetServiceStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class AssetServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static AssetServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonAssetServiceStub.getMethodDescriptors(), + AssetServiceSettings.getDefaultEndpoint()); + AssetServiceSettings settings = + AssetServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = AssetServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listAssetsTest() throws Exception { + Asset responsesElement = Asset.newBuilder().build(); + ListAssetsResponse expectedResponse = + ListAssetsResponse.newBuilder() + .setNextPageToken("") + .addAllAssets(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + + ListAssetsPagedResponse pagedListResponse = client.listAssets(request); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0)); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void listAssetsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent("parent-4715/parent-4715") + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + client.listAssets(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java new file mode 100644 index 000000000..2963ffcc7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzeiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyResponse; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicyAnalysisQuery; +import com.google.protobuf.Duration; + +public class AsyncAnalyzeIamPolicy { + + public static void main(String[] args) throws Exception { + asyncAnalyzeIamPolicy(); + } + + public static void asyncAnalyzeIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setExecutionTimeout(Duration.newBuilder().build()) + .build(); + ApiFuture future = + assetServiceClient.analyzeIamPolicyCallable().futureCall(request); + // Do something. + AnalyzeIamPolicyResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzeiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java new file mode 100644 index 000000000..b509227ba --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzeiampolicy_sync] +import com.google.cloud.asset.v1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyResponse; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicyAnalysisQuery; +import com.google.protobuf.Duration; + +public class SyncAnalyzeIamPolicy { + + public static void main(String[] args) throws Exception { + syncAnalyzeIamPolicy(); + } + + public static void syncAnalyzeIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setExecutionTimeout(Duration.newBuilder().build()) + .build(); + AnalyzeIamPolicyResponse response = assetServiceClient.analyzeIamPolicy(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzeiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunning.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunning.java new file mode 100644 index 000000000..81c6d01a4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunning.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzeiampolicylongrunning_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig; +import com.google.cloud.asset.v1.IamPolicyAnalysisQuery; +import com.google.longrunning.Operation; + +public class AsyncAnalyzeIamPolicyLongrunning { + + public static void main(String[] args) throws Exception { + asyncAnalyzeIamPolicyLongrunning(); + } + + public static void asyncAnalyzeIamPolicyLongrunning() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + ApiFuture future = + assetServiceClient.analyzeIamPolicyLongrunningCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzeiampolicylongrunning_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunningLRO.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunningLRO.java new file mode 100644 index 000000000..6f5f57a33 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/AsyncAnalyzeIamPolicyLongrunningLRO.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzeiampolicylongrunning_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningMetadata; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig; +import com.google.cloud.asset.v1.IamPolicyAnalysisQuery; + +public class AsyncAnalyzeIamPolicyLongrunningLRO { + + public static void main(String[] args) throws Exception { + asyncAnalyzeIamPolicyLongrunningLRO(); + } + + public static void asyncAnalyzeIamPolicyLongrunningLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + OperationFuture + future = + assetServiceClient.analyzeIamPolicyLongrunningOperationCallable().futureCall(request); + // Do something. + AnalyzeIamPolicyLongrunningResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzeiampolicylongrunning_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/SyncAnalyzeIamPolicyLongrunning.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/SyncAnalyzeIamPolicyLongrunning.java new file mode 100644 index 000000000..03dabc154 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzeiampolicylongrunning/SyncAnalyzeIamPolicyLongrunning.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzeiampolicylongrunning_sync] +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; +import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig; +import com.google.cloud.asset.v1.IamPolicyAnalysisQuery; + +public class SyncAnalyzeIamPolicyLongrunning { + + public static void main(String[] args) throws Exception { + syncAnalyzeIamPolicyLongrunning(); + } + + public static void syncAnalyzeIamPolicyLongrunning() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyLongrunningRequest request = + AnalyzeIamPolicyLongrunningRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setSavedAnalysisQuery("savedAnalysisQuery376058885") + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + AnalyzeIamPolicyLongrunningResponse response = + assetServiceClient.analyzeIamPolicyLongrunningAsync(request).get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzeiampolicylongrunning_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/AsyncAnalyzeMove.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/AsyncAnalyzeMove.java new file mode 100644 index 000000000..5ff6e4af4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/AsyncAnalyzeMove.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzemove_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AnalyzeMoveRequest; +import com.google.cloud.asset.v1.AnalyzeMoveResponse; +import com.google.cloud.asset.v1.AssetServiceClient; + +public class AsyncAnalyzeMove { + + public static void main(String[] args) throws Exception { + asyncAnalyzeMove(); + } + + public static void asyncAnalyzeMove() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeMoveRequest request = + AnalyzeMoveRequest.newBuilder() + .setResource("resource-341064690") + .setDestinationParent("destinationParent-1733659048") + .build(); + ApiFuture future = + assetServiceClient.analyzeMoveCallable().futureCall(request); + // Do something. + AnalyzeMoveResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzemove_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/SyncAnalyzeMove.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/SyncAnalyzeMove.java new file mode 100644 index 000000000..ee4c6de6a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/analyzemove/SyncAnalyzeMove.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_analyzemove_sync] +import com.google.cloud.asset.v1.AnalyzeMoveRequest; +import com.google.cloud.asset.v1.AnalyzeMoveResponse; +import com.google.cloud.asset.v1.AssetServiceClient; + +public class SyncAnalyzeMove { + + public static void main(String[] args) throws Exception { + syncAnalyzeMove(); + } + + public static void syncAnalyzeMove() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeMoveRequest request = + AnalyzeMoveRequest.newBuilder() + .setResource("resource-341064690") + .setDestinationParent("destinationParent-1733659048") + .build(); + AnalyzeMoveResponse response = assetServiceClient.analyzeMove(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_analyzemove_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/AsyncBatchGetAssetsHistory.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/AsyncBatchGetAssetsHistory.java new file mode 100644 index 000000000..acede2761 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/AsyncBatchGetAssetsHistory.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_batchgetassetshistory_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; +import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.TimeWindow; +import java.util.ArrayList; + +public class AsyncBatchGetAssetsHistory { + + public static void main(String[] args) throws Exception { + asyncBatchGetAssetsHistory(); + } + + public static void asyncBatchGetAssetsHistory() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + BatchGetAssetsHistoryRequest request = + BatchGetAssetsHistoryRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .addAllAssetNames(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setReadTimeWindow(TimeWindow.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + ApiFuture future = + assetServiceClient.batchGetAssetsHistoryCallable().futureCall(request); + // Do something. + BatchGetAssetsHistoryResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_batchgetassetshistory_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/SyncBatchGetAssetsHistory.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/SyncBatchGetAssetsHistory.java new file mode 100644 index 000000000..1b7b0550d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgetassetshistory/SyncBatchGetAssetsHistory.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_batchgetassetshistory_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; +import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.TimeWindow; +import java.util.ArrayList; + +public class SyncBatchGetAssetsHistory { + + public static void main(String[] args) throws Exception { + syncBatchGetAssetsHistory(); + } + + public static void syncBatchGetAssetsHistory() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + BatchGetAssetsHistoryRequest request = + BatchGetAssetsHistoryRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .addAllAssetNames(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setReadTimeWindow(TimeWindow.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + BatchGetAssetsHistoryResponse response = assetServiceClient.batchGetAssetsHistory(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_batchgetassetshistory_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/AsyncBatchGetEffectiveIamPolicies.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/AsyncBatchGetEffectiveIamPolicies.java new file mode 100644 index 000000000..81d53596f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/AsyncBatchGetEffectiveIamPolicies.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_batchgeteffectiveiampolicies_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesRequest; +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesResponse; +import com.google.cloud.asset.v1.FolderName; +import java.util.ArrayList; + +public class AsyncBatchGetEffectiveIamPolicies { + + public static void main(String[] args) throws Exception { + asyncBatchGetEffectiveIamPolicies(); + } + + public static void asyncBatchGetEffectiveIamPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + BatchGetEffectiveIamPoliciesRequest request = + BatchGetEffectiveIamPoliciesRequest.newBuilder() + .setScope(FolderName.of("[FOLDER]").toString()) + .addAllNames(new ArrayList()) + .build(); + ApiFuture future = + assetServiceClient.batchGetEffectiveIamPoliciesCallable().futureCall(request); + // Do something. + BatchGetEffectiveIamPoliciesResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_batchgeteffectiveiampolicies_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/SyncBatchGetEffectiveIamPolicies.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/SyncBatchGetEffectiveIamPolicies.java new file mode 100644 index 000000000..34c35ce24 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/batchgeteffectiveiampolicies/SyncBatchGetEffectiveIamPolicies.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_batchgeteffectiveiampolicies_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesRequest; +import com.google.cloud.asset.v1.BatchGetEffectiveIamPoliciesResponse; +import com.google.cloud.asset.v1.FolderName; +import java.util.ArrayList; + +public class SyncBatchGetEffectiveIamPolicies { + + public static void main(String[] args) throws Exception { + syncBatchGetEffectiveIamPolicies(); + } + + public static void syncBatchGetEffectiveIamPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + BatchGetEffectiveIamPoliciesRequest request = + BatchGetEffectiveIamPoliciesRequest.newBuilder() + .setScope(FolderName.of("[FOLDER]").toString()) + .addAllNames(new ArrayList()) + .build(); + BatchGetEffectiveIamPoliciesResponse response = + assetServiceClient.batchGetEffectiveIamPolicies(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_batchgeteffectiveiampolicies_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000..70b2503fb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.AssetServiceSettings; +import com.google.cloud.asset.v1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1_generated_assetserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000..4f134b7dc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.AssetServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1_generated_assetserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000..73e93fda0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_create_setendpoint_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.AssetServiceSettings; +import com.google.cloud.asset.v1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1_generated_assetserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/AsyncCreateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/AsyncCreateFeed.java new file mode 100644 index 000000000..d9c447036 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/AsyncCreateFeed.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createfeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.CreateFeedRequest; +import com.google.cloud.asset.v1.Feed; + +public class AsyncCreateFeed { + + public static void main(String[] args) throws Exception { + asyncCreateFeed(); + } + + public static void asyncCreateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + CreateFeedRequest request = + CreateFeedRequest.newBuilder() + .setParent("parent-995424086") + .setFeedId("feedId-1278410919") + .setFeed(Feed.newBuilder().build()) + .build(); + ApiFuture future = assetServiceClient.createFeedCallable().futureCall(request); + // Do something. + Feed response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_createfeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeed.java new file mode 100644 index 000000000..1325bacda --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeed.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createfeed_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.CreateFeedRequest; +import com.google.cloud.asset.v1.Feed; + +public class SyncCreateFeed { + + public static void main(String[] args) throws Exception { + syncCreateFeed(); + } + + public static void syncCreateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + CreateFeedRequest request = + CreateFeedRequest.newBuilder() + .setParent("parent-995424086") + .setFeedId("feedId-1278410919") + .setFeed(Feed.newBuilder().build()) + .build(); + Feed response = assetServiceClient.createFeed(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_createfeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeedString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeedString.java new file mode 100644 index 000000000..e02c8fa45 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createfeed/SyncCreateFeedString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createfeed_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; + +public class SyncCreateFeedString { + + public static void main(String[] args) throws Exception { + syncCreateFeedString(); + } + + public static void syncCreateFeedString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = "parent-995424086"; + Feed response = assetServiceClient.createFeed(parent); + } + } +} +// [END asset_v1_generated_assetserviceclient_createfeed_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/AsyncCreateSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/AsyncCreateSavedQuery.java new file mode 100644 index 000000000..9d226baf9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/AsyncCreateSavedQuery.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createsavedquery_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.CreateSavedQueryRequest; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class AsyncCreateSavedQuery { + + public static void main(String[] args) throws Exception { + asyncCreateSavedQuery(); + } + + public static void asyncCreateSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + CreateSavedQueryRequest request = + CreateSavedQueryRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setSavedQuery(SavedQuery.newBuilder().build()) + .setSavedQueryId("savedQueryId378086268") + .build(); + ApiFuture future = + assetServiceClient.createSavedQueryCallable().futureCall(request); + // Do something. + SavedQuery response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_createsavedquery_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQuery.java new file mode 100644 index 000000000..fbbb37bc6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQuery.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createsavedquery_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.CreateSavedQueryRequest; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncCreateSavedQuery { + + public static void main(String[] args) throws Exception { + syncCreateSavedQuery(); + } + + public static void syncCreateSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + CreateSavedQueryRequest request = + CreateSavedQueryRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setSavedQuery(SavedQuery.newBuilder().build()) + .setSavedQueryId("savedQueryId378086268") + .build(); + SavedQuery response = assetServiceClient.createSavedQuery(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_createsavedquery_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryFoldernameSavedqueryString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryFoldernameSavedqueryString.java new file mode 100644 index 000000000..65f971548 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryFoldernameSavedqueryString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createsavedquery_foldernamesavedquerystring_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncCreateSavedQueryFoldernameSavedqueryString { + + public static void main(String[] args) throws Exception { + syncCreateSavedQueryFoldernameSavedqueryString(); + } + + public static void syncCreateSavedQueryFoldernameSavedqueryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + SavedQuery response = assetServiceClient.createSavedQuery(parent, savedQuery, savedQueryId); + } + } +} +// [END asset_v1_generated_assetserviceclient_createsavedquery_foldernamesavedquerystring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryOrganizationnameSavedqueryString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryOrganizationnameSavedqueryString.java new file mode 100644 index 000000000..3bd74b81d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryOrganizationnameSavedqueryString.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START +// asset_v1_generated_assetserviceclient_createsavedquery_organizationnamesavedquerystring_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.OrganizationName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncCreateSavedQueryOrganizationnameSavedqueryString { + + public static void main(String[] args) throws Exception { + syncCreateSavedQueryOrganizationnameSavedqueryString(); + } + + public static void syncCreateSavedQueryOrganizationnameSavedqueryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + SavedQuery response = assetServiceClient.createSavedQuery(parent, savedQuery, savedQueryId); + } + } +} +// [END +// asset_v1_generated_assetserviceclient_createsavedquery_organizationnamesavedquerystring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryProjectnameSavedqueryString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryProjectnameSavedqueryString.java new file mode 100644 index 000000000..7546c6611 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryProjectnameSavedqueryString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createsavedquery_projectnamesavedquerystring_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncCreateSavedQueryProjectnameSavedqueryString { + + public static void main(String[] args) throws Exception { + syncCreateSavedQueryProjectnameSavedqueryString(); + } + + public static void syncCreateSavedQueryProjectnameSavedqueryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + SavedQuery response = assetServiceClient.createSavedQuery(parent, savedQuery, savedQueryId); + } + } +} +// [END asset_v1_generated_assetserviceclient_createsavedquery_projectnamesavedquerystring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryStringSavedqueryString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryStringSavedqueryString.java new file mode 100644 index 000000000..34b2811eb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/createsavedquery/SyncCreateSavedQueryStringSavedqueryString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_createsavedquery_stringsavedquerystring_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncCreateSavedQueryStringSavedqueryString { + + public static void main(String[] args) throws Exception { + syncCreateSavedQueryStringSavedqueryString(); + } + + public static void syncCreateSavedQueryStringSavedqueryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + String savedQueryId = "savedQueryId378086268"; + SavedQuery response = assetServiceClient.createSavedQuery(parent, savedQuery, savedQueryId); + } + } +} +// [END asset_v1_generated_assetserviceclient_createsavedquery_stringsavedquerystring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/AsyncDeleteFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/AsyncDeleteFeed.java new file mode 100644 index 000000000..e27968302 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/AsyncDeleteFeed.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletefeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.DeleteFeedRequest; +import com.google.cloud.asset.v1.FeedName; +import com.google.protobuf.Empty; + +public class AsyncDeleteFeed { + + public static void main(String[] args) throws Exception { + asyncDeleteFeed(); + } + + public static void asyncDeleteFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + DeleteFeedRequest request = + DeleteFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + ApiFuture future = assetServiceClient.deleteFeedCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletefeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeed.java new file mode 100644 index 000000000..8440342be --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeed.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletefeed_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.DeleteFeedRequest; +import com.google.cloud.asset.v1.FeedName; + +public class SyncDeleteFeed { + + public static void main(String[] args) throws Exception { + syncDeleteFeed(); + } + + public static void syncDeleteFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + DeleteFeedRequest request = + DeleteFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + assetServiceClient.deleteFeed(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletefeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java new file mode 100644 index 000000000..a274a4162 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletefeed_feedname_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.FeedName; + +public class SyncDeleteFeedFeedname { + + public static void main(String[] args) throws Exception { + syncDeleteFeedFeedname(); + } + + public static void syncDeleteFeedFeedname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + assetServiceClient.deleteFeed(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletefeed_feedname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedString.java new file mode 100644 index 000000000..19d861743 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletefeed/SyncDeleteFeedString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletefeed_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.FeedName; + +public class SyncDeleteFeedString { + + public static void main(String[] args) throws Exception { + syncDeleteFeedString(); + } + + public static void syncDeleteFeedString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString(); + assetServiceClient.deleteFeed(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletefeed_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/AsyncDeleteSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/AsyncDeleteSavedQuery.java new file mode 100644 index 000000000..91369d5fc --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/AsyncDeleteSavedQuery.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletesavedquery_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.DeleteSavedQueryRequest; +import com.google.cloud.asset.v1.SavedQueryName; +import com.google.protobuf.Empty; + +public class AsyncDeleteSavedQuery { + + public static void main(String[] args) throws Exception { + asyncDeleteSavedQuery(); + } + + public static void asyncDeleteSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + DeleteSavedQueryRequest request = + DeleteSavedQueryRequest.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .build(); + ApiFuture future = assetServiceClient.deleteSavedQueryCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletesavedquery_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuery.java new file mode 100644 index 000000000..f767317fa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuery.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletesavedquery_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.DeleteSavedQueryRequest; +import com.google.cloud.asset.v1.SavedQueryName; + +public class SyncDeleteSavedQuery { + + public static void main(String[] args) throws Exception { + syncDeleteSavedQuery(); + } + + public static void syncDeleteSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + DeleteSavedQueryRequest request = + DeleteSavedQueryRequest.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .build(); + assetServiceClient.deleteSavedQuery(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletesavedquery_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuerySavedqueryname.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuerySavedqueryname.java new file mode 100644 index 000000000..f07529793 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQuerySavedqueryname.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletesavedquery_savedqueryname_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQueryName; + +public class SyncDeleteSavedQuerySavedqueryname { + + public static void main(String[] args) throws Exception { + syncDeleteSavedQuerySavedqueryname(); + } + + public static void syncDeleteSavedQuerySavedqueryname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); + assetServiceClient.deleteSavedQuery(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletesavedquery_savedqueryname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQueryString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQueryString.java new file mode 100644 index 000000000..8eaddfb88 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/deletesavedquery/SyncDeleteSavedQueryString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_deletesavedquery_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQueryName; + +public class SyncDeleteSavedQueryString { + + public static void main(String[] args) throws Exception { + syncDeleteSavedQueryString(); + } + + public static void syncDeleteSavedQueryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString(); + assetServiceClient.deleteSavedQuery(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_deletesavedquery_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssets.java new file mode 100644 index 000000000..588b978cd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssets.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_exportassets_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.ExportAssetsRequest; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.OutputConfig; +import com.google.longrunning.Operation; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class AsyncExportAssets { + + public static void main(String[] args) throws Exception { + asyncExportAssets(); + } + + public static void asyncExportAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ExportAssetsRequest request = + ExportAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setOutputConfig(OutputConfig.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + ApiFuture future = assetServiceClient.exportAssetsCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_exportassets_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssetsLRO.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssetsLRO.java new file mode 100644 index 000000000..e2387504c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/AsyncExportAssetsLRO.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_exportassets_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.ExportAssetsRequest; +import com.google.cloud.asset.v1.ExportAssetsResponse; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.OutputConfig; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class AsyncExportAssetsLRO { + + public static void main(String[] args) throws Exception { + asyncExportAssetsLRO(); + } + + public static void asyncExportAssetsLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ExportAssetsRequest request = + ExportAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setOutputConfig(OutputConfig.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + OperationFuture future = + assetServiceClient.exportAssetsOperationCallable().futureCall(request); + // Do something. + ExportAssetsResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_exportassets_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/SyncExportAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/SyncExportAssets.java new file mode 100644 index 000000000..00daae5c8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/exportassets/SyncExportAssets.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_exportassets_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.ExportAssetsRequest; +import com.google.cloud.asset.v1.ExportAssetsResponse; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.OutputConfig; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class SyncExportAssets { + + public static void main(String[] args) throws Exception { + syncExportAssets(); + } + + public static void syncExportAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ExportAssetsRequest request = + ExportAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setOutputConfig(OutputConfig.newBuilder().build()) + .addAllRelationshipTypes(new ArrayList()) + .build(); + ExportAssetsResponse response = assetServiceClient.exportAssetsAsync(request).get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_exportassets_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/AsyncGetFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/AsyncGetFeed.java new file mode 100644 index 000000000..d4599664a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/AsyncGetFeed.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getfeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.FeedName; +import com.google.cloud.asset.v1.GetFeedRequest; + +public class AsyncGetFeed { + + public static void main(String[] args) throws Exception { + asyncGetFeed(); + } + + public static void asyncGetFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + GetFeedRequest request = + GetFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + ApiFuture future = assetServiceClient.getFeedCallable().futureCall(request); + // Do something. + Feed response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_getfeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeed.java new file mode 100644 index 000000000..528af4aec --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeed.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getfeed_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.FeedName; +import com.google.cloud.asset.v1.GetFeedRequest; + +public class SyncGetFeed { + + public static void main(String[] args) throws Exception { + syncGetFeed(); + } + + public static void syncGetFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + GetFeedRequest request = + GetFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + Feed response = assetServiceClient.getFeed(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_getfeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedFeedname.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedFeedname.java new file mode 100644 index 000000000..1a690bf44 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedFeedname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getfeed_feedname_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.FeedName; + +public class SyncGetFeedFeedname { + + public static void main(String[] args) throws Exception { + syncGetFeedFeedname(); + } + + public static void syncGetFeedFeedname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + Feed response = assetServiceClient.getFeed(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_getfeed_feedname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedString.java new file mode 100644 index 000000000..5a9974201 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getfeed/SyncGetFeedString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getfeed_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.FeedName; + +public class SyncGetFeedString { + + public static void main(String[] args) throws Exception { + syncGetFeedString(); + } + + public static void syncGetFeedString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString(); + Feed response = assetServiceClient.getFeed(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_getfeed_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/AsyncGetSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/AsyncGetSavedQuery.java new file mode 100644 index 000000000..9dd204955 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/AsyncGetSavedQuery.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getsavedquery_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.GetSavedQueryRequest; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.SavedQueryName; + +public class AsyncGetSavedQuery { + + public static void main(String[] args) throws Exception { + asyncGetSavedQuery(); + } + + public static void asyncGetSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + GetSavedQueryRequest request = + GetSavedQueryRequest.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .build(); + ApiFuture future = assetServiceClient.getSavedQueryCallable().futureCall(request); + // Do something. + SavedQuery response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_getsavedquery_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuery.java new file mode 100644 index 000000000..658a1c08a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuery.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getsavedquery_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.GetSavedQueryRequest; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.SavedQueryName; + +public class SyncGetSavedQuery { + + public static void main(String[] args) throws Exception { + syncGetSavedQuery(); + } + + public static void syncGetSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + GetSavedQueryRequest request = + GetSavedQueryRequest.newBuilder() + .setName( + SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString()) + .build(); + SavedQuery response = assetServiceClient.getSavedQuery(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_getsavedquery_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuerySavedqueryname.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuerySavedqueryname.java new file mode 100644 index 000000000..1fea3ea3e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQuerySavedqueryname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getsavedquery_savedqueryname_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.SavedQueryName; + +public class SyncGetSavedQuerySavedqueryname { + + public static void main(String[] args) throws Exception { + syncGetSavedQuerySavedqueryname(); + } + + public static void syncGetSavedQuerySavedqueryname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SavedQueryName name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]"); + SavedQuery response = assetServiceClient.getSavedQuery(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_getsavedquery_savedqueryname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQueryString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQueryString.java new file mode 100644 index 000000000..079017472 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/getsavedquery/SyncGetSavedQueryString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_getsavedquery_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.SavedQueryName; + +public class SyncGetSavedQueryString { + + public static void main(String[] args) throws Exception { + syncGetSavedQueryString(); + } + + public static void syncGetSavedQueryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String name = SavedQueryName.ofProjectSavedQueryName("[PROJECT]", "[SAVED_QUERY]").toString(); + SavedQuery response = assetServiceClient.getSavedQuery(name); + } + } +} +// [END asset_v1_generated_assetserviceclient_getsavedquery_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssets.java new file mode 100644 index 000000000..9a621b94a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssets.java @@ -0,0 +1,57 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listassets_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.Asset; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.ListAssetsRequest; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class AsyncListAssets { + + public static void main(String[] args) throws Exception { + asyncListAssets(); + } + + public static void asyncListAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .addAllRelationshipTypes(new ArrayList()) + .build(); + ApiFuture future = assetServiceClient.listAssetsPagedCallable().futureCall(request); + // Do something. + for (Asset element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listassets_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssetsPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssetsPaged.java new file mode 100644 index 000000000..fe1939e01 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/AsyncListAssetsPaged.java @@ -0,0 +1,65 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listassets_paged_async] +import com.google.cloud.asset.v1.Asset; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.ListAssetsRequest; +import com.google.cloud.asset.v1.ListAssetsResponse; +import com.google.common.base.Strings; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class AsyncListAssetsPaged { + + public static void main(String[] args) throws Exception { + asyncListAssetsPaged(); + } + + public static void asyncListAssetsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .addAllRelationshipTypes(new ArrayList()) + .build(); + while (true) { + ListAssetsResponse response = assetServiceClient.listAssetsCallable().call(request); + for (Asset element : response.getAssetsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listassets_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssets.java new file mode 100644 index 000000000..8e5e16bb3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssets.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listassets_sync] +import com.google.cloud.asset.v1.Asset; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ContentType; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.ListAssetsRequest; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class SyncListAssets { + + public static void main(String[] args) throws Exception { + syncListAssets(); + } + + public static void syncListAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent(FolderName.of("[FOLDER]").toString()) + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .addAllRelationshipTypes(new ArrayList()) + .build(); + for (Asset element : assetServiceClient.listAssets(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listassets_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsResourcename.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsResourcename.java new file mode 100644 index 000000000..df1f3a6a2 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsResourcename.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listassets_resourcename_sync] +import com.google.api.resourcenames.ResourceName; +import com.google.cloud.asset.v1.Asset; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.FolderName; + +public class SyncListAssetsResourcename { + + public static void main(String[] args) throws Exception { + syncListAssetsResourcename(); + } + + public static void syncListAssetsResourcename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ResourceName parent = FolderName.of("[FOLDER]"); + for (Asset element : assetServiceClient.listAssets(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listassets_resourcename_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsString.java new file mode 100644 index 000000000..b8ef3a25f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listassets/SyncListAssetsString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listassets_string_sync] +import com.google.cloud.asset.v1.Asset; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.FeedName; + +public class SyncListAssetsString { + + public static void main(String[] args) throws Exception { + syncListAssetsString(); + } + + public static void syncListAssetsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString(); + for (Asset element : assetServiceClient.listAssets(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listassets_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/AsyncListFeeds.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/AsyncListFeeds.java new file mode 100644 index 000000000..572fd6c16 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/AsyncListFeeds.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listfeeds_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ListFeedsRequest; +import com.google.cloud.asset.v1.ListFeedsResponse; + +public class AsyncListFeeds { + + public static void main(String[] args) throws Exception { + asyncListFeeds(); + } + + public static void asyncListFeeds() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListFeedsRequest request = + ListFeedsRequest.newBuilder().setParent("parent-995424086").build(); + ApiFuture future = + assetServiceClient.listFeedsCallable().futureCall(request); + // Do something. + ListFeedsResponse response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_listfeeds_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeeds.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeeds.java new file mode 100644 index 000000000..a53be62fe --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeeds.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listfeeds_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ListFeedsRequest; +import com.google.cloud.asset.v1.ListFeedsResponse; + +public class SyncListFeeds { + + public static void main(String[] args) throws Exception { + syncListFeeds(); + } + + public static void syncListFeeds() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListFeedsRequest request = + ListFeedsRequest.newBuilder().setParent("parent-995424086").build(); + ListFeedsResponse response = assetServiceClient.listFeeds(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_listfeeds_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeedsString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeedsString.java new file mode 100644 index 000000000..a5f1a7afd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listfeeds/SyncListFeedsString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listfeeds_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ListFeedsResponse; + +public class SyncListFeedsString { + + public static void main(String[] args) throws Exception { + syncListFeedsString(); + } + + public static void syncListFeedsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = "parent-995424086"; + ListFeedsResponse response = assetServiceClient.listFeeds(parent); + } + } +} +// [END asset_v1_generated_assetserviceclient_listfeeds_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueries.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueries.java new file mode 100644 index 000000000..a42037fb8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueries.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ListSavedQueriesRequest; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class AsyncListSavedQueries { + + public static void main(String[] args) throws Exception { + asyncListSavedQueries(); + } + + public static void asyncListSavedQueries() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListSavedQueriesRequest request = + ListSavedQueriesRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setFilter("filter-1274492040") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + assetServiceClient.listSavedQueriesPagedCallable().futureCall(request); + // Do something. + for (SavedQuery element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueriesPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueriesPaged.java new file mode 100644 index 000000000..2e4c5a5ec --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/AsyncListSavedQueriesPaged.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_paged_async] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ListSavedQueriesRequest; +import com.google.cloud.asset.v1.ListSavedQueriesResponse; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.common.base.Strings; + +public class AsyncListSavedQueriesPaged { + + public static void main(String[] args) throws Exception { + asyncListSavedQueriesPaged(); + } + + public static void asyncListSavedQueriesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListSavedQueriesRequest request = + ListSavedQueriesRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setFilter("filter-1274492040") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListSavedQueriesResponse response = + assetServiceClient.listSavedQueriesCallable().call(request); + for (SavedQuery element : response.getSavedQueriesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueries.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueries.java new file mode 100644 index 000000000..fba5e09f9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueries.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ListSavedQueriesRequest; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncListSavedQueries { + + public static void main(String[] args) throws Exception { + syncListSavedQueries(); + } + + public static void syncListSavedQueries() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListSavedQueriesRequest request = + ListSavedQueriesRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setFilter("filter-1274492040") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (SavedQuery element : assetServiceClient.listSavedQueries(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesFoldername.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesFoldername.java new file mode 100644 index 000000000..e31dfc779 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesFoldername.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_foldername_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.FolderName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncListSavedQueriesFoldername { + + public static void main(String[] args) throws Exception { + syncListSavedQueriesFoldername(); + } + + public static void syncListSavedQueriesFoldername() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + for (SavedQuery element : assetServiceClient.listSavedQueries(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_foldername_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesOrganizationname.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesOrganizationname.java new file mode 100644 index 000000000..b8bbd25a8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesOrganizationname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_organizationname_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.OrganizationName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncListSavedQueriesOrganizationname { + + public static void main(String[] args) throws Exception { + syncListSavedQueriesOrganizationname(); + } + + public static void syncListSavedQueriesOrganizationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + for (SavedQuery element : assetServiceClient.listSavedQueries(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_organizationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesProjectname.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesProjectname.java new file mode 100644 index 000000000..4a6f90181 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesProjectname.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_projectname_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncListSavedQueriesProjectname { + + public static void main(String[] args) throws Exception { + syncListSavedQueriesProjectname(); + } + + public static void syncListSavedQueriesProjectname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + for (SavedQuery element : assetServiceClient.listSavedQueries(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_projectname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesString.java new file mode 100644 index 000000000..d2e1c665e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/listsavedqueries/SyncListSavedQueriesString.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_listsavedqueries_string_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ProjectName; +import com.google.cloud.asset.v1.SavedQuery; + +public class SyncListSavedQueriesString { + + public static void main(String[] args) throws Exception { + syncListSavedQueriesString(); + } + + public static void syncListSavedQueriesString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + for (SavedQuery element : assetServiceClient.listSavedQueries(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_listsavedqueries_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java new file mode 100644 index 000000000..d45ededa0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchalliampolicies_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicySearchResult; +import com.google.cloud.asset.v1.SearchAllIamPoliciesRequest; +import java.util.ArrayList; + +public class AsyncSearchAllIamPolicies { + + public static void main(String[] args) throws Exception { + asyncSearchAllIamPolicies(); + } + + public static void asyncSearchAllIamPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SearchAllIamPoliciesRequest request = + SearchAllIamPoliciesRequest.newBuilder() + .setScope("scope109264468") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .addAllAssetTypes(new ArrayList()) + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + assetServiceClient.searchAllIamPoliciesPagedCallable().futureCall(request); + // Do something. + for (IamPolicySearchResult element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchalliampolicies_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java new file mode 100644 index 000000000..eee7d0b8e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchalliampolicies_paged_async] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicySearchResult; +import com.google.cloud.asset.v1.SearchAllIamPoliciesRequest; +import com.google.cloud.asset.v1.SearchAllIamPoliciesResponse; +import com.google.common.base.Strings; +import java.util.ArrayList; + +public class AsyncSearchAllIamPoliciesPaged { + + public static void main(String[] args) throws Exception { + asyncSearchAllIamPoliciesPaged(); + } + + public static void asyncSearchAllIamPoliciesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SearchAllIamPoliciesRequest request = + SearchAllIamPoliciesRequest.newBuilder() + .setScope("scope109264468") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .addAllAssetTypes(new ArrayList()) + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + SearchAllIamPoliciesResponse response = + assetServiceClient.searchAllIamPoliciesCallable().call(request); + for (IamPolicySearchResult element : response.getResultsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchalliampolicies_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java new file mode 100644 index 000000000..e2435d6d3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchalliampolicies_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicySearchResult; +import com.google.cloud.asset.v1.SearchAllIamPoliciesRequest; +import java.util.ArrayList; + +public class SyncSearchAllIamPolicies { + + public static void main(String[] args) throws Exception { + syncSearchAllIamPolicies(); + } + + public static void syncSearchAllIamPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SearchAllIamPoliciesRequest request = + SearchAllIamPoliciesRequest.newBuilder() + .setScope("scope109264468") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .addAllAssetTypes(new ArrayList()) + .setOrderBy("orderBy-1207110587") + .build(); + for (IamPolicySearchResult element : + assetServiceClient.searchAllIamPolicies(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchalliampolicies_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java new file mode 100644 index 000000000..0cccfb6e1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchalliampolicies_stringstring_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.IamPolicySearchResult; + +public class SyncSearchAllIamPoliciesStringString { + + public static void main(String[] args) throws Exception { + syncSearchAllIamPoliciesStringString(); + } + + public static void syncSearchAllIamPoliciesStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String scope = "scope109264468"; + String query = "query107944136"; + for (IamPolicySearchResult element : + assetServiceClient.searchAllIamPolicies(scope, query).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchalliampolicies_stringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResources.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResources.java new file mode 100644 index 000000000..9f0cec76c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResources.java @@ -0,0 +1,56 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchallresources_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ResourceSearchResult; +import com.google.cloud.asset.v1.SearchAllResourcesRequest; +import com.google.protobuf.FieldMask; +import java.util.ArrayList; + +public class AsyncSearchAllResources { + + public static void main(String[] args) throws Exception { + asyncSearchAllResources(); + } + + public static void asyncSearchAllResources() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setOrderBy("orderBy-1207110587") + .setReadMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + assetServiceClient.searchAllResourcesPagedCallable().futureCall(request); + // Do something. + for (ResourceSearchResult element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchallresources_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java new file mode 100644 index 000000000..ad668a9da --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java @@ -0,0 +1,64 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchallresources_paged_async] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ResourceSearchResult; +import com.google.cloud.asset.v1.SearchAllResourcesRequest; +import com.google.cloud.asset.v1.SearchAllResourcesResponse; +import com.google.common.base.Strings; +import com.google.protobuf.FieldMask; +import java.util.ArrayList; + +public class AsyncSearchAllResourcesPaged { + + public static void main(String[] args) throws Exception { + asyncSearchAllResourcesPaged(); + } + + public static void asyncSearchAllResourcesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setOrderBy("orderBy-1207110587") + .setReadMask(FieldMask.newBuilder().build()) + .build(); + while (true) { + SearchAllResourcesResponse response = + assetServiceClient.searchAllResourcesCallable().call(request); + for (ResourceSearchResult element : response.getResultsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchallresources_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResources.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResources.java new file mode 100644 index 000000000..cff5d56c6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResources.java @@ -0,0 +1,53 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchallresources_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ResourceSearchResult; +import com.google.cloud.asset.v1.SearchAllResourcesRequest; +import com.google.protobuf.FieldMask; +import java.util.ArrayList; + +public class SyncSearchAllResources { + + public static void main(String[] args) throws Exception { + syncSearchAllResources(); + } + + public static void syncSearchAllResources() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setOrderBy("orderBy-1207110587") + .setReadMask(FieldMask.newBuilder().build()) + .build(); + for (ResourceSearchResult element : + assetServiceClient.searchAllResources(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchallresources_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java new file mode 100644 index 000000000..aa23171f3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_searchallresources_stringstringliststring_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.ResourceSearchResult; +import java.util.ArrayList; +import java.util.List; + +public class SyncSearchAllResourcesStringStringListstring { + + public static void main(String[] args) throws Exception { + syncSearchAllResourcesStringStringListstring(); + } + + public static void syncSearchAllResourcesStringStringListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String scope = "scope109264468"; + String query = "query107944136"; + List assetTypes = new ArrayList<>(); + for (ResourceSearchResult element : + assetServiceClient.searchAllResources(scope, query, assetTypes).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1_generated_assetserviceclient_searchallresources_stringstringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/AsyncUpdateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/AsyncUpdateFeed.java new file mode 100644 index 000000000..b114d7831 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/AsyncUpdateFeed.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_updatefeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.UpdateFeedRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateFeed { + + public static void main(String[] args) throws Exception { + asyncUpdateFeed(); + } + + public static void asyncUpdateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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 future = assetServiceClient.updateFeedCallable().futureCall(request); + // Do something. + Feed response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_updatefeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeed.java new file mode 100644 index 000000000..76211f58e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeed.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_updatefeed_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; +import com.google.cloud.asset.v1.UpdateFeedRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateFeed { + + public static void main(String[] args) throws Exception { + syncUpdateFeed(); + } + + public static void syncUpdateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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); + } + } +} +// [END asset_v1_generated_assetserviceclient_updatefeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java new file mode 100644 index 000000000..a3b846411 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_updatefeed_feed_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.Feed; + +public class SyncUpdateFeedFeed { + + public static void main(String[] args) throws Exception { + syncUpdateFeedFeed(); + } + + public static void syncUpdateFeedFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + Feed feed = Feed.newBuilder().build(); + Feed response = assetServiceClient.updateFeed(feed); + } + } +} +// [END asset_v1_generated_assetserviceclient_updatefeed_feed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/AsyncUpdateSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/AsyncUpdateSavedQuery.java new file mode 100644 index 000000000..cf6f4cc85 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/AsyncUpdateSavedQuery.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_updatesavedquery_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.UpdateSavedQueryRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateSavedQuery { + + public static void main(String[] args) throws Exception { + asyncUpdateSavedQuery(); + } + + public static void asyncUpdateSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + UpdateSavedQueryRequest request = + UpdateSavedQueryRequest.newBuilder() + .setSavedQuery(SavedQuery.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + assetServiceClient.updateSavedQueryCallable().futureCall(request); + // Do something. + SavedQuery response = future.get(); + } + } +} +// [END asset_v1_generated_assetserviceclient_updatesavedquery_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuery.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuery.java new file mode 100644 index 000000000..50aaa23dd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuery.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_updatesavedquery_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.cloud.asset.v1.UpdateSavedQueryRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateSavedQuery { + + public static void main(String[] args) throws Exception { + syncUpdateSavedQuery(); + } + + public static void syncUpdateSavedQuery() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + UpdateSavedQueryRequest request = + UpdateSavedQueryRequest.newBuilder() + .setSavedQuery(SavedQuery.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + SavedQuery response = assetServiceClient.updateSavedQuery(request); + } + } +} +// [END asset_v1_generated_assetserviceclient_updatesavedquery_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuerySavedqueryFieldmask.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuerySavedqueryFieldmask.java new file mode 100644 index 000000000..628cc28d8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetserviceclient/updatesavedquery/SyncUpdateSavedQuerySavedqueryFieldmask.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetserviceclient_updatesavedquery_savedqueryfieldmask_sync] +import com.google.cloud.asset.v1.AssetServiceClient; +import com.google.cloud.asset.v1.SavedQuery; +import com.google.protobuf.FieldMask; + +public class SyncUpdateSavedQuerySavedqueryFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateSavedQuerySavedqueryFieldmask(); + } + + public static void syncUpdateSavedQuerySavedqueryFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SavedQuery savedQuery = SavedQuery.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + SavedQuery response = assetServiceClient.updateSavedQuery(savedQuery, updateMask); + } + } +} +// [END asset_v1_generated_assetserviceclient_updatesavedquery_savedqueryfieldmask_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/assetservicesettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java b/samples/snippets/generated/com/google/cloud/asset/v1/assetservicesettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java new file mode 100644 index 000000000..b405d726e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/assetservicesettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.samples; + +// [START asset_v1_generated_assetservicesettings_batchgetassetshistory_sync] +import com.google.cloud.asset.v1.AssetServiceSettings; +import java.time.Duration; + +public class SyncBatchGetAssetsHistory { + + public static void main(String[] args) throws Exception { + syncBatchGetAssetsHistory(); + } + + public static void syncBatchGetAssetsHistory() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings.Builder assetServiceSettingsBuilder = AssetServiceSettings.newBuilder(); + assetServiceSettingsBuilder + .batchGetAssetsHistorySettings() + .setRetrySettings( + assetServiceSettingsBuilder + .batchGetAssetsHistorySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1_generated_assetservicesettings_batchgetassetshistory_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1/stub/assetservicestubsettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java b/samples/snippets/generated/com/google/cloud/asset/v1/stub/assetservicestubsettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java new file mode 100644 index 000000000..f6e4d0f47 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1/stub/assetservicestubsettings/batchgetassetshistory/SyncBatchGetAssetsHistory.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1.stub.samples; + +// [START asset_v1_generated_assetservicestubsettings_batchgetassetshistory_sync] +import com.google.cloud.asset.v1.stub.AssetServiceStubSettings; +import java.time.Duration; + +public class SyncBatchGetAssetsHistory { + + public static void main(String[] args) throws Exception { + syncBatchGetAssetsHistory(); + } + + public static void syncBatchGetAssetsHistory() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceStubSettings.Builder assetServiceSettingsBuilder = + AssetServiceStubSettings.newBuilder(); + assetServiceSettingsBuilder + .batchGetAssetsHistorySettings() + .setRetrySettings( + assetServiceSettingsBuilder + .batchGetAssetsHistorySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceStubSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1_generated_assetservicestubsettings_batchgetassetshistory_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000..377507272 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000..78b6bb4e9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.AssetServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000..31269eaf0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_create_setendpoint_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java new file mode 100644 index 000000000..42894a76a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPolicies.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.IamPolicySearchResult; +import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesRequest; + +public class AsyncSearchAllIamPolicies { + + public static void main(String[] args) throws Exception { + asyncSearchAllIamPolicies(); + } + + public static void asyncSearchAllIamPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SearchAllIamPoliciesRequest request = + SearchAllIamPoliciesRequest.newBuilder() + .setScope("scope109264468") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + assetServiceClient.searchAllIamPoliciesPagedCallable().futureCall(request); + // Do something. + for (IamPolicySearchResult element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java new file mode 100644 index 000000000..6067e08e6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/AsyncSearchAllIamPoliciesPaged.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_paged_async] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.IamPolicySearchResult; +import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesRequest; +import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesResponse; +import com.google.common.base.Strings; + +public class AsyncSearchAllIamPoliciesPaged { + + public static void main(String[] args) throws Exception { + asyncSearchAllIamPoliciesPaged(); + } + + public static void asyncSearchAllIamPoliciesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SearchAllIamPoliciesRequest request = + SearchAllIamPoliciesRequest.newBuilder() + .setScope("scope109264468") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + SearchAllIamPoliciesResponse response = + assetServiceClient.searchAllIamPoliciesCallable().call(request); + for (IamPolicySearchResult element : response.getResultsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java new file mode 100644 index 000000000..fd79d9d91 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPolicies.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.IamPolicySearchResult; +import com.google.cloud.asset.v1p1beta1.SearchAllIamPoliciesRequest; + +public class SyncSearchAllIamPolicies { + + public static void main(String[] args) throws Exception { + syncSearchAllIamPolicies(); + } + + public static void syncSearchAllIamPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + SearchAllIamPoliciesRequest request = + SearchAllIamPoliciesRequest.newBuilder() + .setScope("scope109264468") + .setQuery("query107944136") + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (IamPolicySearchResult element : + assetServiceClient.searchAllIamPolicies(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java new file mode 100644 index 000000000..95410dbf5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchalliampolicies/SyncSearchAllIamPoliciesStringString.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_stringstring_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.IamPolicySearchResult; + +public class SyncSearchAllIamPoliciesStringString { + + public static void main(String[] args) throws Exception { + syncSearchAllIamPoliciesStringString(); + } + + public static void syncSearchAllIamPoliciesStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String scope = "scope109264468"; + String query = "query107944136"; + for (IamPolicySearchResult element : + assetServiceClient.searchAllIamPolicies(scope, query).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchalliampolicies_stringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResources.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResources.java new file mode 100644 index 000000000..82a4b934b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResources.java @@ -0,0 +1,54 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchallresources_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.SearchAllResourcesRequest; +import com.google.cloud.asset.v1p1beta1.StandardResourceMetadata; +import java.util.ArrayList; + +public class AsyncSearchAllResources { + + public static void main(String[] args) throws Exception { + asyncSearchAllResources(); + } + + public static void asyncSearchAllResources() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setOrderBy("orderBy-1207110587") + .build(); + ApiFuture future = + assetServiceClient.searchAllResourcesPagedCallable().futureCall(request); + // Do something. + for (StandardResourceMetadata element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchallresources_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java new file mode 100644 index 000000000..3c52e3a23 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/AsyncSearchAllResourcesPaged.java @@ -0,0 +1,62 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchallresources_paged_async] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.SearchAllResourcesRequest; +import com.google.cloud.asset.v1p1beta1.SearchAllResourcesResponse; +import com.google.cloud.asset.v1p1beta1.StandardResourceMetadata; +import com.google.common.base.Strings; +import java.util.ArrayList; + +public class AsyncSearchAllResourcesPaged { + + public static void main(String[] args) throws Exception { + asyncSearchAllResourcesPaged(); + } + + public static void asyncSearchAllResourcesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setOrderBy("orderBy-1207110587") + .build(); + while (true) { + SearchAllResourcesResponse response = + assetServiceClient.searchAllResourcesCallable().call(request); + for (StandardResourceMetadata element : response.getResultsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchallresources_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResources.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResources.java new file mode 100644 index 000000000..1eb9ab0db --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResources.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetserviceclient_searchallresources_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.SearchAllResourcesRequest; +import com.google.cloud.asset.v1p1beta1.StandardResourceMetadata; +import java.util.ArrayList; + +public class SyncSearchAllResources { + + public static void main(String[] args) throws Exception { + syncSearchAllResources(); + } + + public static void syncSearchAllResources() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setOrderBy("orderBy-1207110587") + .build(); + for (StandardResourceMetadata element : + assetServiceClient.searchAllResources(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchallresources_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java new file mode 100644 index 000000000..b57409a4e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetserviceclient/searchallresources/SyncSearchAllResourcesStringStringListstring.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START +// asset_v1p1beta1_generated_assetserviceclient_searchallresources_stringstringliststring_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceClient; +import com.google.cloud.asset.v1p1beta1.StandardResourceMetadata; +import java.util.ArrayList; +import java.util.List; + +public class SyncSearchAllResourcesStringStringListstring { + + public static void main(String[] args) throws Exception { + syncSearchAllResourcesStringStringListstring(); + } + + public static void syncSearchAllResourcesStringStringListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String scope = "scope109264468"; + String query = "query107944136"; + List assetTypes = new ArrayList<>(); + for (StandardResourceMetadata element : + assetServiceClient.searchAllResources(scope, query, assetTypes).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p1beta1_generated_assetserviceclient_searchallresources_stringstringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetservicesettings/searchallresources/SyncSearchAllResources.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetservicesettings/searchallresources/SyncSearchAllResources.java new file mode 100644 index 000000000..8133c5720 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/assetservicesettings/searchallresources/SyncSearchAllResources.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.samples; + +// [START asset_v1p1beta1_generated_assetservicesettings_searchallresources_sync] +import com.google.cloud.asset.v1p1beta1.AssetServiceSettings; +import java.time.Duration; + +public class SyncSearchAllResources { + + public static void main(String[] args) throws Exception { + syncSearchAllResources(); + } + + public static void syncSearchAllResources() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings.Builder assetServiceSettingsBuilder = AssetServiceSettings.newBuilder(); + assetServiceSettingsBuilder + .searchAllResourcesSettings() + .setRetrySettings( + assetServiceSettingsBuilder + .searchAllResourcesSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p1beta1_generated_assetservicesettings_searchallresources_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/stub/assetservicestubsettings/searchallresources/SyncSearchAllResources.java b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/stub/assetservicestubsettings/searchallresources/SyncSearchAllResources.java new file mode 100644 index 000000000..8c78a5c7a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p1beta1/stub/assetservicestubsettings/searchallresources/SyncSearchAllResources.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p1beta1.stub.samples; + +// [START asset_v1p1beta1_generated_assetservicestubsettings_searchallresources_sync] +import com.google.cloud.asset.v1p1beta1.stub.AssetServiceStubSettings; +import java.time.Duration; + +public class SyncSearchAllResources { + + public static void main(String[] args) throws Exception { + syncSearchAllResources(); + } + + public static void syncSearchAllResources() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceStubSettings.Builder assetServiceSettingsBuilder = + AssetServiceStubSettings.newBuilder(); + assetServiceSettingsBuilder + .searchAllResourcesSettings() + .setRetrySettings( + assetServiceSettingsBuilder + .searchAllResourcesSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceStubSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p1beta1_generated_assetservicestubsettings_searchallresources_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000..cc76e638d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p2beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000..82a5b4d07 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.AssetServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000..31b10d173 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_create_setendpoint_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p2beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/AsyncCreateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/AsyncCreateFeed.java new file mode 100644 index 000000000..2cb506150 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/AsyncCreateFeed.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_createfeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.CreateFeedRequest; +import com.google.cloud.asset.v1p2beta1.Feed; + +public class AsyncCreateFeed { + + public static void main(String[] args) throws Exception { + asyncCreateFeed(); + } + + public static void asyncCreateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + CreateFeedRequest request = + CreateFeedRequest.newBuilder() + .setParent("parent-995424086") + .setFeedId("feedId-1278410919") + .setFeed(Feed.newBuilder().build()) + .build(); + ApiFuture future = assetServiceClient.createFeedCallable().futureCall(request); + // Do something. + Feed response = future.get(); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_createfeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeed.java new file mode 100644 index 000000000..b1bcf12e5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeed.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_createfeed_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.CreateFeedRequest; +import com.google.cloud.asset.v1p2beta1.Feed; + +public class SyncCreateFeed { + + public static void main(String[] args) throws Exception { + syncCreateFeed(); + } + + public static void syncCreateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + CreateFeedRequest request = + CreateFeedRequest.newBuilder() + .setParent("parent-995424086") + .setFeedId("feedId-1278410919") + .setFeed(Feed.newBuilder().build()) + .build(); + Feed response = assetServiceClient.createFeed(request); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_createfeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeedString.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeedString.java new file mode 100644 index 000000000..e7ad2e58f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/createfeed/SyncCreateFeedString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_createfeed_string_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; + +public class SyncCreateFeedString { + + public static void main(String[] args) throws Exception { + syncCreateFeedString(); + } + + public static void syncCreateFeedString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = "parent-995424086"; + Feed response = assetServiceClient.createFeed(parent); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_createfeed_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/AsyncDeleteFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/AsyncDeleteFeed.java new file mode 100644 index 000000000..2ebf50c6b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/AsyncDeleteFeed.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_deletefeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.DeleteFeedRequest; +import com.google.cloud.asset.v1p2beta1.FeedName; +import com.google.protobuf.Empty; + +public class AsyncDeleteFeed { + + public static void main(String[] args) throws Exception { + asyncDeleteFeed(); + } + + public static void asyncDeleteFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + DeleteFeedRequest request = + DeleteFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + ApiFuture future = assetServiceClient.deleteFeedCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_deletefeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeed.java new file mode 100644 index 000000000..adfe58284 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeed.java @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_deletefeed_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.DeleteFeedRequest; +import com.google.cloud.asset.v1p2beta1.FeedName; + +public class SyncDeleteFeed { + + public static void main(String[] args) throws Exception { + syncDeleteFeed(); + } + + public static void syncDeleteFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + DeleteFeedRequest request = + DeleteFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + assetServiceClient.deleteFeed(request); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_deletefeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java new file mode 100644 index 000000000..187733cda --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedFeedname.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_deletefeed_feedname_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.FeedName; + +public class SyncDeleteFeedFeedname { + + public static void main(String[] args) throws Exception { + syncDeleteFeedFeedname(); + } + + public static void syncDeleteFeedFeedname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + assetServiceClient.deleteFeed(name); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_deletefeed_feedname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedString.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedString.java new file mode 100644 index 000000000..e58feaba9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/deletefeed/SyncDeleteFeedString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_deletefeed_string_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.FeedName; + +public class SyncDeleteFeedString { + + public static void main(String[] args) throws Exception { + syncDeleteFeedString(); + } + + public static void syncDeleteFeedString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString(); + assetServiceClient.deleteFeed(name); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_deletefeed_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/AsyncGetFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/AsyncGetFeed.java new file mode 100644 index 000000000..349a00d8b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/AsyncGetFeed.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_getfeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.FeedName; +import com.google.cloud.asset.v1p2beta1.GetFeedRequest; + +public class AsyncGetFeed { + + public static void main(String[] args) throws Exception { + asyncGetFeed(); + } + + public static void asyncGetFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + GetFeedRequest request = + GetFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + ApiFuture future = assetServiceClient.getFeedCallable().futureCall(request); + // Do something. + Feed response = future.get(); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_getfeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeed.java new file mode 100644 index 000000000..a515c3dd0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeed.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_getfeed_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.FeedName; +import com.google.cloud.asset.v1p2beta1.GetFeedRequest; + +public class SyncGetFeed { + + public static void main(String[] args) throws Exception { + syncGetFeed(); + } + + public static void syncGetFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + GetFeedRequest request = + GetFeedRequest.newBuilder() + .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) + .build(); + Feed response = assetServiceClient.getFeed(request); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_getfeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedFeedname.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedFeedname.java new file mode 100644 index 000000000..8f7667886 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedFeedname.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_getfeed_feedname_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.FeedName; + +public class SyncGetFeedFeedname { + + public static void main(String[] args) throws Exception { + syncGetFeedFeedname(); + } + + public static void syncGetFeedFeedname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + Feed response = assetServiceClient.getFeed(name); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_getfeed_feedname_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedString.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedString.java new file mode 100644 index 000000000..c9048b164 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/getfeed/SyncGetFeedString.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_getfeed_string_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.FeedName; + +public class SyncGetFeedString { + + public static void main(String[] args) throws Exception { + syncGetFeedString(); + } + + public static void syncGetFeedString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString(); + Feed response = assetServiceClient.getFeed(name); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_getfeed_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/AsyncListFeeds.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/AsyncListFeeds.java new file mode 100644 index 000000000..8fe82daa0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/AsyncListFeeds.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_listfeeds_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.ListFeedsRequest; +import com.google.cloud.asset.v1p2beta1.ListFeedsResponse; + +public class AsyncListFeeds { + + public static void main(String[] args) throws Exception { + asyncListFeeds(); + } + + public static void asyncListFeeds() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListFeedsRequest request = + ListFeedsRequest.newBuilder().setParent("parent-995424086").build(); + ApiFuture future = + assetServiceClient.listFeedsCallable().futureCall(request); + // Do something. + ListFeedsResponse response = future.get(); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_listfeeds_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeeds.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeeds.java new file mode 100644 index 000000000..9637ad8a9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeeds.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_listfeeds_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.ListFeedsRequest; +import com.google.cloud.asset.v1p2beta1.ListFeedsResponse; + +public class SyncListFeeds { + + public static void main(String[] args) throws Exception { + syncListFeeds(); + } + + public static void syncListFeeds() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListFeedsRequest request = + ListFeedsRequest.newBuilder().setParent("parent-995424086").build(); + ListFeedsResponse response = assetServiceClient.listFeeds(request); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_listfeeds_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeedsString.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeedsString.java new file mode 100644 index 000000000..3d2727362 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/listfeeds/SyncListFeedsString.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_listfeeds_string_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.ListFeedsResponse; + +public class SyncListFeedsString { + + public static void main(String[] args) throws Exception { + syncListFeedsString(); + } + + public static void syncListFeedsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + String parent = "parent-995424086"; + ListFeedsResponse response = assetServiceClient.listFeeds(parent); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_listfeeds_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/AsyncUpdateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/AsyncUpdateFeed.java new file mode 100644 index 000000000..b2ec087bb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/AsyncUpdateFeed.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_updatefeed_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.UpdateFeedRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateFeed { + + public static void main(String[] args) throws Exception { + asyncUpdateFeed(); + } + + public static void asyncUpdateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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 future = assetServiceClient.updateFeedCallable().futureCall(request); + // Do something. + Feed response = future.get(); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_updatefeed_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeed.java new file mode 100644 index 000000000..cc754df89 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeed.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_updatefeed_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; +import com.google.cloud.asset.v1p2beta1.UpdateFeedRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateFeed { + + public static void main(String[] args) throws Exception { + syncUpdateFeed(); + } + + public static void syncUpdateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // 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); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_updatefeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java new file mode 100644 index 000000000..1eae03c2e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetserviceclient/updatefeed/SyncUpdateFeedFeed.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetserviceclient_updatefeed_feed_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceClient; +import com.google.cloud.asset.v1p2beta1.Feed; + +public class SyncUpdateFeedFeed { + + public static void main(String[] args) throws Exception { + syncUpdateFeedFeed(); + } + + public static void syncUpdateFeedFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + Feed feed = Feed.newBuilder().build(); + Feed response = assetServiceClient.updateFeed(feed); + } + } +} +// [END asset_v1p2beta1_generated_assetserviceclient_updatefeed_feed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetservicesettings/createfeed/SyncCreateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetservicesettings/createfeed/SyncCreateFeed.java new file mode 100644 index 000000000..ec9f8554a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/assetservicesettings/createfeed/SyncCreateFeed.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.samples; + +// [START asset_v1p2beta1_generated_assetservicesettings_createfeed_sync] +import com.google.cloud.asset.v1p2beta1.AssetServiceSettings; +import java.time.Duration; + +public class SyncCreateFeed { + + public static void main(String[] args) throws Exception { + syncCreateFeed(); + } + + public static void syncCreateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings.Builder assetServiceSettingsBuilder = AssetServiceSettings.newBuilder(); + assetServiceSettingsBuilder + .createFeedSettings() + .setRetrySettings( + assetServiceSettingsBuilder + .createFeedSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p2beta1_generated_assetservicesettings_createfeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/stub/assetservicestubsettings/createfeed/SyncCreateFeed.java b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/stub/assetservicestubsettings/createfeed/SyncCreateFeed.java new file mode 100644 index 000000000..691f08553 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p2beta1/stub/assetservicestubsettings/createfeed/SyncCreateFeed.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p2beta1.stub.samples; + +// [START asset_v1p2beta1_generated_assetservicestubsettings_createfeed_sync] +import com.google.cloud.asset.v1p2beta1.stub.AssetServiceStubSettings; +import java.time.Duration; + +public class SyncCreateFeed { + + public static void main(String[] args) throws Exception { + syncCreateFeed(); + } + + public static void syncCreateFeed() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceStubSettings.Builder assetServiceSettingsBuilder = + AssetServiceStubSettings.newBuilder(); + assetServiceSettingsBuilder + .createFeedSettings() + .setRetrySettings( + assetServiceSettingsBuilder + .createFeedSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceStubSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p2beta1_generated_assetservicestubsettings_createfeed_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java new file mode 100644 index 000000000..7989ca648 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/AsyncAnalyzeIamPolicy.java @@ -0,0 +1,48 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_analyzeiampolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p4beta1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1p4beta1.AnalyzeIamPolicyResponse; +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisQuery; + +public class AsyncAnalyzeIamPolicy { + + public static void main(String[] args) throws Exception { + asyncAnalyzeIamPolicy(); + } + + public static void asyncAnalyzeIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOptions(AnalyzeIamPolicyRequest.Options.newBuilder().build()) + .build(); + ApiFuture future = + assetServiceClient.analyzeIamPolicyCallable().futureCall(request); + // Do something. + AnalyzeIamPolicyResponse response = future.get(); + } + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_analyzeiampolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java new file mode 100644 index 000000000..93c160354 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/analyzeiampolicy/SyncAnalyzeIamPolicy.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_analyzeiampolicy_sync] +import com.google.cloud.asset.v1p4beta1.AnalyzeIamPolicyRequest; +import com.google.cloud.asset.v1p4beta1.AnalyzeIamPolicyResponse; +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisQuery; + +public class SyncAnalyzeIamPolicy { + + public static void main(String[] args) throws Exception { + syncAnalyzeIamPolicy(); + } + + public static void syncAnalyzeIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + AnalyzeIamPolicyRequest request = + AnalyzeIamPolicyRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOptions(AnalyzeIamPolicyRequest.Options.newBuilder().build()) + .build(); + AnalyzeIamPolicyResponse response = assetServiceClient.analyzeIamPolicy(request); + } + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_analyzeiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000..ae8e5fa2d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p4beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000..f7e5247f0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.AssetServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000..0b5a060f5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_create_setendpoint_sync] +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p4beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysis.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysis.java new file mode 100644 index 000000000..4a05950b5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysis.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_exportiampolicyanalysis_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisRequest; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisOutputConfig; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisQuery; +import com.google.longrunning.Operation; + +public class AsyncExportIamPolicyAnalysis { + + public static void main(String[] args) throws Exception { + asyncExportIamPolicyAnalysis(); + } + + public static void asyncExportIamPolicyAnalysis() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ExportIamPolicyAnalysisRequest request = + ExportIamPolicyAnalysisRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOptions(ExportIamPolicyAnalysisRequest.Options.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + ApiFuture future = + assetServiceClient.exportIamPolicyAnalysisCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_exportiampolicyanalysis_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysisLRO.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysisLRO.java new file mode 100644 index 000000000..275350c9d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/AsyncExportIamPolicyAnalysisLRO.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_exportiampolicyanalysis_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisRequest; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisResponse; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisOutputConfig; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisQuery; + +public class AsyncExportIamPolicyAnalysisLRO { + + public static void main(String[] args) throws Exception { + asyncExportIamPolicyAnalysisLRO(); + } + + public static void asyncExportIamPolicyAnalysisLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ExportIamPolicyAnalysisRequest request = + ExportIamPolicyAnalysisRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOptions(ExportIamPolicyAnalysisRequest.Options.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + OperationFuture future = + assetServiceClient.exportIamPolicyAnalysisOperationCallable().futureCall(request); + // Do something. + ExportIamPolicyAnalysisResponse response = future.get(); + } + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_exportiampolicyanalysis_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/SyncExportIamPolicyAnalysis.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/SyncExportIamPolicyAnalysis.java new file mode 100644 index 000000000..2999d8e6f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetserviceclient/exportiampolicyanalysis/SyncExportIamPolicyAnalysis.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetserviceclient_exportiampolicyanalysis_sync] +import com.google.cloud.asset.v1p4beta1.AssetServiceClient; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisRequest; +import com.google.cloud.asset.v1p4beta1.ExportIamPolicyAnalysisResponse; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisOutputConfig; +import com.google.cloud.asset.v1p4beta1.IamPolicyAnalysisQuery; + +public class SyncExportIamPolicyAnalysis { + + public static void main(String[] args) throws Exception { + syncExportIamPolicyAnalysis(); + } + + public static void syncExportIamPolicyAnalysis() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ExportIamPolicyAnalysisRequest request = + ExportIamPolicyAnalysisRequest.newBuilder() + .setAnalysisQuery(IamPolicyAnalysisQuery.newBuilder().build()) + .setOptions(ExportIamPolicyAnalysisRequest.Options.newBuilder().build()) + .setOutputConfig(IamPolicyAnalysisOutputConfig.newBuilder().build()) + .build(); + ExportIamPolicyAnalysisResponse response = + assetServiceClient.exportIamPolicyAnalysisAsync(request).get(); + } + } +} +// [END asset_v1p4beta1_generated_assetserviceclient_exportiampolicyanalysis_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetservicesettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetservicesettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java new file mode 100644 index 000000000..ae4e828d4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/assetservicesettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.samples; + +// [START asset_v1p4beta1_generated_assetservicesettings_analyzeiampolicy_sync] +import com.google.cloud.asset.v1p4beta1.AssetServiceSettings; +import java.time.Duration; + +public class SyncAnalyzeIamPolicy { + + public static void main(String[] args) throws Exception { + syncAnalyzeIamPolicy(); + } + + public static void syncAnalyzeIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings.Builder assetServiceSettingsBuilder = AssetServiceSettings.newBuilder(); + assetServiceSettingsBuilder + .analyzeIamPolicySettings() + .setRetrySettings( + assetServiceSettingsBuilder + .analyzeIamPolicySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p4beta1_generated_assetservicesettings_analyzeiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/stub/assetservicestubsettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/stub/assetservicestubsettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java new file mode 100644 index 000000000..f47d6a877 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p4beta1/stub/assetservicestubsettings/analyzeiampolicy/SyncAnalyzeIamPolicy.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p4beta1.stub.samples; + +// [START asset_v1p4beta1_generated_assetservicestubsettings_analyzeiampolicy_sync] +import com.google.cloud.asset.v1p4beta1.stub.AssetServiceStubSettings; +import java.time.Duration; + +public class SyncAnalyzeIamPolicy { + + public static void main(String[] args) throws Exception { + syncAnalyzeIamPolicy(); + } + + public static void syncAnalyzeIamPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceStubSettings.Builder assetServiceSettingsBuilder = + AssetServiceStubSettings.newBuilder(); + assetServiceSettingsBuilder + .analyzeIamPolicySettings() + .setRetrySettings( + assetServiceSettingsBuilder + .analyzeIamPolicySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceStubSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p4beta1_generated_assetservicestubsettings_analyzeiampolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000..7a29d8f60 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.asset.v1p5beta1.AssetServiceClient; +import com.google.cloud.asset.v1p5beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p5beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p5beta1_generated_assetserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000..329e6edc9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.asset.v1p5beta1.AssetServiceClient; +import com.google.cloud.asset.v1p5beta1.AssetServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder() + .setTransportChannelProvider( + AssetServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p5beta1_generated_assetserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000..b62c28d12 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetserviceclient_create_setendpoint_sync] +import com.google.cloud.asset.v1p5beta1.AssetServiceClient; +import com.google.cloud.asset.v1p5beta1.AssetServiceSettings; +import com.google.cloud.asset.v1p5beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings assetServiceSettings = + AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); + } +} +// [END asset_v1p5beta1_generated_assetserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssets.java new file mode 100644 index 000000000..9361e6959 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssets.java @@ -0,0 +1,55 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetserviceclient_listassets_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.asset.v1p5beta1.Asset; +import com.google.cloud.asset.v1p5beta1.AssetServiceClient; +import com.google.cloud.asset.v1p5beta1.ContentType; +import com.google.cloud.asset.v1p5beta1.ListAssetsRequest; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class AsyncListAssets { + + public static void main(String[] args) throws Exception { + asyncListAssets(); + } + + public static void asyncListAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent("parent-995424086") + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = assetServiceClient.listAssetsPagedCallable().futureCall(request); + // Do something. + for (Asset element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p5beta1_generated_assetserviceclient_listassets_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssetsPaged.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssetsPaged.java new file mode 100644 index 000000000..91d535698 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/AsyncListAssetsPaged.java @@ -0,0 +1,63 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetserviceclient_listassets_paged_async] +import com.google.cloud.asset.v1p5beta1.Asset; +import com.google.cloud.asset.v1p5beta1.AssetServiceClient; +import com.google.cloud.asset.v1p5beta1.ContentType; +import com.google.cloud.asset.v1p5beta1.ListAssetsRequest; +import com.google.cloud.asset.v1p5beta1.ListAssetsResponse; +import com.google.common.base.Strings; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class AsyncListAssetsPaged { + + public static void main(String[] args) throws Exception { + asyncListAssetsPaged(); + } + + public static void asyncListAssetsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent("parent-995424086") + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListAssetsResponse response = assetServiceClient.listAssetsCallable().call(request); + for (Asset element : response.getAssetsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END asset_v1p5beta1_generated_assetserviceclient_listassets_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/SyncListAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/SyncListAssets.java new file mode 100644 index 000000000..65071790c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetserviceclient/listassets/SyncListAssets.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetserviceclient_listassets_sync] +import com.google.cloud.asset.v1p5beta1.Asset; +import com.google.cloud.asset.v1p5beta1.AssetServiceClient; +import com.google.cloud.asset.v1p5beta1.ContentType; +import com.google.cloud.asset.v1p5beta1.ListAssetsRequest; +import com.google.protobuf.Timestamp; +import java.util.ArrayList; + +public class SyncListAssets { + + public static void main(String[] args) throws Exception { + syncListAssets(); + } + + public static void syncListAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder() + .setParent("parent-995424086") + .setReadTime(Timestamp.newBuilder().build()) + .addAllAssetTypes(new ArrayList()) + .setContentType(ContentType.forNumber(0)) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Asset element : assetServiceClient.listAssets(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END asset_v1p5beta1_generated_assetserviceclient_listassets_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetservicesettings/listassets/SyncListAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetservicesettings/listassets/SyncListAssets.java new file mode 100644 index 000000000..2712faff8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/assetservicesettings/listassets/SyncListAssets.java @@ -0,0 +1,45 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.samples; + +// [START asset_v1p5beta1_generated_assetservicesettings_listassets_sync] +import com.google.cloud.asset.v1p5beta1.AssetServiceSettings; +import java.time.Duration; + +public class SyncListAssets { + + public static void main(String[] args) throws Exception { + syncListAssets(); + } + + public static void syncListAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceSettings.Builder assetServiceSettingsBuilder = AssetServiceSettings.newBuilder(); + assetServiceSettingsBuilder + .listAssetsSettings() + .setRetrySettings( + assetServiceSettingsBuilder + .listAssetsSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p5beta1_generated_assetservicesettings_listassets_sync] diff --git a/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/stub/assetservicestubsettings/listassets/SyncListAssets.java b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/stub/assetservicestubsettings/listassets/SyncListAssets.java new file mode 100644 index 000000000..f1482a4d6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/asset/v1p5beta1/stub/assetservicestubsettings/listassets/SyncListAssets.java @@ -0,0 +1,46 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.asset.v1p5beta1.stub.samples; + +// [START asset_v1p5beta1_generated_assetservicestubsettings_listassets_sync] +import com.google.cloud.asset.v1p5beta1.stub.AssetServiceStubSettings; +import java.time.Duration; + +public class SyncListAssets { + + public static void main(String[] args) throws Exception { + syncListAssets(); + } + + public static void syncListAssets() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + AssetServiceStubSettings.Builder assetServiceSettingsBuilder = + AssetServiceStubSettings.newBuilder(); + assetServiceSettingsBuilder + .listAssetsSettings() + .setRetrySettings( + assetServiceSettingsBuilder + .listAssetsSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + AssetServiceStubSettings assetServiceSettings = assetServiceSettingsBuilder.build(); + } +} +// [END asset_v1p5beta1_generated_assetservicestubsettings_listassets_sync]