diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 42e6dec649..dbf5754794 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,8 +49,7 @@ jobs: run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress --test_output=errors - name: Integration Tests - # TODO(miraleung): Change this to //test/integration/... after the monolith rule removal. - run: bazel --batch test //test/integration:asset //test/integration:compute //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:pubsub //test/integration:redis //test/integration:library --noshow_progress + run: bazel --batch test //test/integration/... - uses: actions/upload-artifact@v2 if: ${{ failure() }} diff --git a/WORKSPACE b/WORKSPACE index bce7a60448..7468b3246d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -69,7 +69,7 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() # Bazel rules. -_rules_gapic_version = "0.5.4" +_rules_gapic_version = "0.5.5" http_archive( name = "rules_gapic", @@ -78,14 +78,6 @@ http_archive( ) # Java dependencies. -# Import the monolith so we can transitively use its gapic rules for googleapis. -# TODO: Remove this after this dep has been removed from googleapis' switched_rules_by_language. -http_archive( - name = "com_google_api_codegen", - strip_prefix = "gapic-generator-2.11.1", - urls = ["https://github.com/googleapis/gapic-generator/archive/v2.11.1.zip"], -) - load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language") switched_rules_by_language( @@ -101,6 +93,6 @@ grpc_java_repositories() http_archive( name = "com_google_disco_to_proto3_converter", - strip_prefix = "disco-to-proto3-converter-1839f6aca5e968e59b7acc03e7018b0fda8c480b", - urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/1839f6aca5e968e59b7acc03e7018b0fda8c480b.zip"], + strip_prefix = "disco-to-proto3-converter-4b0956884b1aa9b367cf41488b622dc12eb16652", + urls = ["https://github.com/googleapis/disco-to-proto3-converter/archive/4b0956884b1aa9b367cf41488b622dc12eb16652.zip"], ) diff --git a/dependencies.properties b/dependencies.properties index 7a8357ca63..75e53a6461 100644 --- a/dependencies.properties +++ b/dependencies.properties @@ -4,7 +4,7 @@ # The properties format is the following: # [.]= -# Target workspace name: com_google_api_codegen +# Target workspace name: gapic_generator_java # Versions only, for dependencies which actual artifacts differ between Bazel and Gradle version.com_google_protobuf=3.15.8 @@ -32,7 +32,7 @@ maven.org_threeten_threetenbp=org.threeten:threetenbp:1.3.3 # Testing. maven.junit_junit=junit:junit:4.13.1 -# This hamcrest-core dependency is for running JUnit test manually, before JUnit 4.11 it's wrapped along with JUnit package. +# This hamcrest-core dependency is for running JUnit test manually, before JUnit 4.11 it's wrapped along with JUnit package. # But now it has to be explicitly added. maven.org_hamcrest_hamcrest_core=org.hamcrest:hamcrest-core:1.3 maven.org_mockito_mockito_core=org.mockito:mockito-core:2.21.0 diff --git a/repositories.bzl b/repositories.bzl index 2c884f2701..76d3335218 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -59,18 +59,18 @@ def gapic_generator_java_repositories(): _maybe( http_archive, name = "com_google_googleapis", - strip_prefix = "googleapis-f5ce261910c373fdd96bdaa47173f5604562876f", + strip_prefix = "googleapis-2c1d1b27646cba6f14b760b635f29fafc5a74ca6", urls = [ - "https://github.com/googleapis/googleapis/archive/f5ce261910c373fdd96bdaa47173f5604562876f.zip", + "https://github.com/googleapis/googleapis/archive/2c1d1b27646cba6f14b760b635f29fafc5a74ca6.zip", ], ) _maybe( http_archive, name = "com_google_googleapis_discovery", - strip_prefix = "googleapis-discovery-6a189a8bada35e2657a67b903cad7fee649f2dbc", + strip_prefix = "googleapis-discovery-abf4cec1ce9e02e4d7d650bf66137c347cdd0d44", urls = [ - "https://github.com/googleapis/googleapis-discovery/archive/6a189a8bada35e2657a67b903cad7fee649f2dbc.zip", + "https://github.com/googleapis/googleapis-discovery/archive/abf4cec1ce9e02e4d7d650bf66137c347cdd0d44.zip", ], ) diff --git a/test/integration/BUILD.bazel b/test/integration/BUILD.bazel index 93b90f2041..84463a5614 100644 --- a/test/integration/BUILD.bazel +++ b/test/integration/BUILD.bazel @@ -36,15 +36,15 @@ INTEGRATION_TEST_LIBRARIES = [ # Keys must match the values in INTEGRATION_TEST_LIBRARIES above. API_GAPIC_TARGETS = { - "asset": ":asset_java_gapic", - "credentials": ":credentials_java_gapic", + "asset": "@com_google_googleapis//google/cloud/asset/v1:asset_java_gapic", + "credentials": "@com_google_googleapis//google/iam/credentials/v1:credentials_java_gapic", "iam": ":iam_java_gapic", # Googleapis' LRO does not have a Java Gapic. "kms": ":kms_java_gapic", # Local target because mixins are not rolled out yet. "pubsub": ":pubsub_java_gapic", - "logging": ":logging_java_gapic", - "redis": ":redis_java_gapic", - "library": ":library_java_gapic", - "compute": ":compute_small_java_gapic", + "logging": "@com_google_googleapis//google/logging/v2:logging_java_gapic", + "redis": "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_gapic", + "library": "@com_google_googleapis//google/example/library/v1:library_java_gapic", + "compute": "@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_java_gapic", } [integration_test( @@ -59,161 +59,9 @@ API_GAPIC_TARGETS = { target = API_GAPIC_TARGETS[lib_name], ) for lib_name in INTEGRATION_TEST_LIBRARIES] -################################################### -# Temporary proto_with_info definitions for -# monolith depdency removal. -# Remove this section when the monolith rule deps are -# out of googleapis. -################################################### -proto_library_with_info( - name = "asset_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/cloud/asset/v1:asset_proto", - ], -) - -proto_library_with_info( - name = "credentials_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/iam/credentials/v1:credentials_proto", - ], -) - -proto_library_with_info( - name = "logging_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/logging/v2:logging_proto", - ], -) - -proto_library_with_info( - name = "pubsub_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/iam/v1:iam_policy_proto", - "@com_google_googleapis//google/iam/v1:policy_proto", - "@com_google_googleapis//google/pubsub/v1:pubsub_proto", - ], -) - -proto_library_with_info( - name = "redis_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/cloud/redis/v1beta1:redis_proto", - ], -) - -proto_library_with_info( - name = "iam_proto_with_info", - deps = [ - "@com_google_googleapis//google/iam/v1:iam_policy_proto", - "@com_google_googleapis//google/iam/v1:options_proto", - "@com_google_googleapis//google/iam/v1:policy_proto", - ], -) - -proto_library_with_info( - name = "library_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis//google/example/library/v1:library_proto", - ], -) - -proto_library_with_info( - name = "compute_small_proto_with_info", - deps = [ - "@com_google_googleapis//google/cloud:common_resources_proto", - "@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_proto", - ], -) - -java_gapic_library( - name = "compute_small_java_gapic", - srcs = [":compute_small_proto_with_info"], - test_deps = [], - transport = "rest", - deps = [ - "@com_google_googleapis_discovery//google/cloud/compute/v1:compute_small_java_proto", - ], -) - -java_gapic_library( - name = "asset_java_gapic", - srcs = [":asset_proto_with_info"], - grpc_service_config = "@com_google_googleapis//google/cloud/asset/v1:cloudasset_grpc_service_config.json", - test_deps = [ - "@com_google_googleapis//google/cloud/asset/v1:asset_java_grpc", - "@com_google_googleapis//google/iam/v1:iam_java_grpc", - ], - deps = [ - "@com_google_googleapis//google/cloud/asset/v1:asset_java_proto", - "@com_google_googleapis//google/iam/v1:iam_java_proto", - "@com_google_googleapis//google/identity/accesscontextmanager/v1:accesscontextmanager_proto", - ], -) - -java_gapic_library( - name = "credentials_java_gapic", - srcs = [":credentials_proto_with_info"], - grpc_service_config = "@com_google_googleapis//google/iam/credentials/v1:iamcredentials_grpc_service_config.json", - test_deps = [ - "@com_google_googleapis//google/iam/credentials/v1:credentials_java_grpc", - ], - deps = [ - "@com_google_googleapis//google/iam/credentials/v1:credentials_java_proto", - ], -) - -java_gapic_library( - name = "logging_java_gapic", - srcs = [":logging_proto_with_info"], - gapic_yaml = "@com_google_googleapis//google/logging/v2:logging_gapic.yaml", - grpc_service_config = "@com_google_googleapis//google/logging/v2:logging_grpc_service_config.json", - test_deps = [ - "@com_google_googleapis//google/logging/v2:logging_java_grpc", - ], - deps = [ - "@com_google_googleapis//google/api:api_java_proto", - "@com_google_googleapis//google/logging/v2:logging_java_proto", - ], -) - -java_gapic_library( - name = "redis_java_gapic", - srcs = [":redis_proto_with_info"], - gapic_yaml = "@com_google_googleapis//google/cloud/redis/v1beta1:redis_gapic.yaml", - grpc_service_config = "@com_google_googleapis//google/cloud/redis/v1beta1:redis_grpc_service_config.json", - test_deps = [ - "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_grpc", - ], - deps = [ - "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_proto", - ], -) - -java_gapic_library( - name = "library_java_gapic", - srcs = [":library_proto_with_info"], - gapic_yaml = "@com_google_googleapis//google/example/library/v1:library_example_gapic.yaml", - grpc_service_config = "@com_google_googleapis//google/example/library/v1:library_grpc_service_config.json", - test_deps = [ - "@com_google_googleapis//google/example/library/v1:library_java_grpc", - ], - deps = [ - "@com_google_googleapis//google/example/library/v1:library_java_proto", - ], -) #################################################### # API Library Rules #################################################### -# These will eventually go away once more APIs in googleapis have been migrated to the -# microgenerator. - # Asset API. java_gapic_test( name = "asset_java_gapic_test_suite", @@ -319,7 +167,7 @@ java_gapic_assembly_gradle_pkg( # IAM (for a standalone mixed-in API). java_gapic_library( name = "iam_java_gapic", - srcs = [":iam_proto_with_info"], + srcs = ["@com_google_googleapis//google/iam/v1:iam_proto_with_info"], grpc_service_config = "iam_grpc_service_config.json", test_deps = [ "@com_google_googleapis//google/iam/v1:iam_java_grpc", @@ -431,10 +279,9 @@ java_gapic_assembly_gradle_pkg( ) # PubSub -# TODO: Remove some of these targets when PubSub has been migrated in googleapis. java_gapic_library( name = "pubsub_java_gapic", - srcs = [":pubsub_proto_with_info"], + srcs = ["@com_google_googleapis//google/pubsub/v1:pubsub_proto_with_info"], gapic_yaml = "@com_google_googleapis//google/pubsub/v1:pubsub_gapic.yaml", grpc_service_config = "@com_google_googleapis//google/pubsub/v1:pubsub_grpc_service_config.json", # For the IAM mixin. diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClient.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClient.java index f1bbf06c9f..b659920969 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClient.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClient.java @@ -28,6 +28,7 @@ import com.google.api.gax.rpc.OperationCallable; import com.google.api.gax.rpc.PageContext; import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.resourcenames.ResourceName; import com.google.cloud.asset.v1.stub.AssetServiceStub; import com.google.cloud.asset.v1.stub.AssetServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; @@ -271,6 +272,154 @@ public final UnaryCallable exportAssetsCallable( return stub.exportAssetsCallable(); } + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists assets with time and resource types and returns paged results in response. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
+   *   for (Asset element : assetServiceClient.listAssets(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param parent Required. Name of the organization or project the assets belong to. Format: + * "organizations/[organization-number]" (such as "organizations/123"), + * "projects/[project-id]" (such as "projects/my-project-id"), or "projects/[project-number]" + * (such as "projects/12345"). + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListAssetsPagedResponse listAssets(ResourceName parent) { + ListAssetsRequest request = + ListAssetsRequest.newBuilder().setParent(parent == null ? null : parent.toString()).build(); + return listAssets(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists assets with time and resource types and returns paged results in response. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   String parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString();
+   *   for (Asset element : assetServiceClient.listAssets(parent).iterateAll()) {
+   *     // doThingsWith(element);
+   *   }
+   * }
+   * }
+ * + * @param parent Required. Name of the organization or project the assets belong to. Format: + * "organizations/[organization-number]" (such as "organizations/123"), + * "projects/[project-id]" (such as "projects/my-project-id"), or "projects/[project-number]" + * (such as "projects/12345"). + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListAssetsPagedResponse listAssets(String parent) { + ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent).build(); + return listAssets(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists assets with time and resource types and returns paged results in response. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   ListAssetsRequest request =
+   *       ListAssetsRequest.newBuilder()
+   *           .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
+   *           .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);
+   *   }
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ListAssetsPagedResponse listAssets(ListAssetsRequest request) { + return listAssetsPagedCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists assets with time and resource types and returns paged results in response. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   ListAssetsRequest request =
+   *       ListAssetsRequest.newBuilder()
+   *           .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
+   *           .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);
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listAssetsPagedCallable() { + return stub.listAssetsPagedCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Lists assets with time and resource types and returns paged results in response. + * + *

Sample code: + * + *

{@code
+   * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
+   *   ListAssetsRequest request =
+   *       ListAssetsRequest.newBuilder()
+   *           .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
+   *           .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.getResponsesList()) {
+   *       // doThingsWith(element);
+   *     }
+   *     String nextPageToken = response.getNextPageToken();
+   *     if (!Strings.isNullOrEmpty(nextPageToken)) {
+   *       request = request.toBuilder().setPageToken(nextPageToken).build();
+   *     } else {
+   *       break;
+   *     }
+   *   }
+   * }
+   * }
+ */ + public final UnaryCallable listAssetsCallable() { + return stub.listAssetsCallable(); + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Batch gets the update history of assets that overlap a time window. For IAM_POLICY content, @@ -747,7 +896,7 @@ public final UnaryCallable deleteFeedCallable() { * * @param scope Required. A scope can be a project, a folder, or an organization. The search is * limited to the resources within the `scope`. The caller must be granted the - * [`cloudasset.assets.searchAllResources`](http://cloud.google.com/asset-inventory/docs/access-control#required_permissions) + * [`cloudasset.assets.searchAllResources`](https://cloud.google.com/asset-inventory/docs/access-control#required_permissions) * permission on the desired scope. *

The allowed values are: *

    @@ -758,32 +907,36 @@ public final UnaryCallable deleteFeedCallable() { *
* * @param query Optional. The query statement. See [how to construct a - * query](http://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query) + * query](https://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query) * for more information. If not specified or empty, it will search all the resources within - * the specified `scope`. Note that the query string is compared against each Cloud IAM policy - * binding, including its members, roles, and Cloud IAM conditions. The returned Cloud IAM - * policies will only contain the bindings that match your query. To learn more about the IAM - * policy structure, see [IAM policy - * doc](https://cloud.google.com/iam/docs/policies#structure). + * the specified `scope`. *

Examples: *

    *
  • `name:Important` to find Cloud resources whose name contains "Important" as a word. + *
  • `name=Important` to find the Cloud resource whose name is exactly "Important". *
  • `displayName:Impor*` to find Cloud resources whose display name contains "Impor" - * as a prefix. - *
  • `description:*por*` to find Cloud resources whose description contains "por" - * as a substring. - *
  • `location:us-west*` to find Cloud resources whose location is prefixed with - * "us-west". + * as a prefix of any word in the field. + *
  • `location:us-west*` to find Cloud resources whose location contains both "us" and + * "west" as prefixes. *
  • `labels:prod` to find Cloud resources whose labels contain "prod" as a key or value. *
  • `labels.env:prod` to find Cloud resources that have a label "env" and its value is * "prod". *
  • `labels.env:*` to find Cloud resources that have a label "env". + *
  • `kmsKey:key` to find Cloud resources encrypted with a customer-managed encryption key + * whose name contains the word "key". + *
  • `state:ACTIVE` to find Cloud resources whose state contains "ACTIVE" as a word. + *
  • `NOT state:ACTIVE` to find {{gcp_name}} resources whose state doesn't contain + * "ACTIVE" as a word. + *
  • `createTime<1609459200` to find Cloud resources that were created before + * "2021-01-01 00:00:00 UTC". 1609459200 is the epoch timestamp of "2021-01-01 00:00:00 + * UTC" in seconds. + *
  • `updateTime>1609459200` to find Cloud resources that were updated after + * "2021-01-01 00:00:00 UTC". 1609459200 is the epoch timestamp of "2021-01-01 00:00:00 + * UTC" in seconds. *
  • `Important` to find Cloud resources that contain "Important" as a word in any of the * searchable fields. - *
  • `Impor*` to find Cloud resources that contain "Impor" as a prefix in any of the - * searchable fields. - *
  • `*por*` to find Cloud resources that contain "por" as a substring in any of - * the searchable fields. + *
  • `Impor*` to find Cloud resources that contain "Impor" as a prefix of any word in + * any of the searchable fields. *
  • `Important location:(us-west1 OR global)` to find Cloud resources that contain * "Important" as a word in any of the searchable fields and are also located in the * "us-west1" region or the "global" location. @@ -792,6 +945,16 @@ public final UnaryCallable deleteFeedCallable() { * @param assetTypes Optional. A list of asset types that this request searches for. If empty, it * will search all the [searchable asset * types](https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types). + *

    Regular expressions are also supported. For example: + *

      + *
    • "compute.googleapis.com.*" snapshots resources whose asset type starts with + * "compute.googleapis.com". + *
    • ".*Instance" snapshots resources whose asset type ends with "Instance". + *
    • ".*Instance.*" snapshots resources whose asset type contains "Instance". + *
    + *

    See [RE2](https://github.com/google/re2/wiki/Syntax) for all supported regular + * expression syntax. If the regular expression does not match any supported asset type, an + * INVALID_ARGUMENT error will be returned. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final SearchAllResourcesPagedResponse searchAllResources( @@ -933,7 +1096,7 @@ public final SearchAllResourcesPagedResponse searchAllResources( * * @param scope Required. A scope can be a project, a folder, or an organization. The search is * limited to the IAM policies within the `scope`. The caller must be granted the - * [`cloudasset.assets.searchAllIamPolicies`](http://cloud.google.com/asset-inventory/docs/access-control#required_permissions) + * [`cloudasset.assets.searchAllIamPolicies`](https://cloud.google.com/asset-inventory/docs/access-control#required_permissions) * permission on the desired scope. *

    The allowed values are: *

      @@ -946,23 +1109,33 @@ public final SearchAllResourcesPagedResponse searchAllResources( * @param query Optional. The query statement. See [how to construct a * query](https://cloud.google.com/asset-inventory/docs/searching-iam-policies#how_to_construct_a_query) * for more information. If not specified or empty, it will search all the IAM policies within - * the specified `scope`. + * the specified `scope`. Note that the query string is compared against each Cloud IAM policy + * binding, including its members, roles, and Cloud IAM conditions. The returned Cloud IAM + * policies will only contain the bindings that match your query. To learn more about the IAM + * policy structure, see [IAM policy + * doc](https://cloud.google.com/iam/docs/policies#structure). *

      Examples: *

        *
      • `policy:amy{@literal @}gmail.com` to find IAM policy bindings that specify user * "amy{@literal @}gmail.com". *
      • `policy:roles/compute.admin` to find IAM policy bindings that specify the Compute * Admin role. + *
      • `policy:comp*` to find IAM policy bindings that contain "comp" as a prefix of any + * word in the binding. *
      • `policy.role.permissions:storage.buckets.update` to find IAM policy bindings that * specify a role containing "storage.buckets.update" permission. Note that if callers * don't have `iam.roles.get` access to a role's included permissions, policy bindings * that specify this role will be dropped from the search results. + *
      • `policy.role.permissions:upd*` to find IAM policy bindings that specify a role + * containing "upd" as a prefix of any word in the role permission. Note that if callers + * don't have `iam.roles.get` access to a role's included permissions, policy bindings + * that specify this role will be dropped from the search results. *
      • `resource:organizations/123456` to find IAM policy bindings that are set on * "organizations/123456". + *
      • `resource=//cloudresourcemanager.googleapis.com/projects/myproject` to find IAM + * policy bindings that are set on the project named "myproject". *
      • `Important` to find IAM policy bindings that contain "Important" as a word in any of * the searchable fields (except for the included permissions). - *
      • `*por*` to find IAM policy bindings that contain "por" as a substring in any - * of the searchable fields (except for the included permissions). *
      • `resource:(instance1 OR instance2) policy:amy` to find IAM policy bindings that are * set on resources "instance1" or "instance2" and also specify user "amy". *
      @@ -1257,6 +1430,86 @@ public boolean awaitTermination(long duration, TimeUnit unit) throws Interrupted return stub.awaitTermination(duration, unit); } + public static class ListAssetsPagedResponse + extends AbstractPagedListResponse< + ListAssetsRequest, + ListAssetsResponse, + Asset, + ListAssetsPage, + ListAssetsFixedSizeCollection> { + + public static ApiFuture createAsync( + PageContext context, + ApiFuture futureResponse) { + ApiFuture futurePage = + ListAssetsPage.createEmptyPage().createPageAsync(context, futureResponse); + return ApiFutures.transform( + futurePage, + new ApiFunction() { + @Override + public ListAssetsPagedResponse apply(ListAssetsPage input) { + return new ListAssetsPagedResponse(input); + } + }, + MoreExecutors.directExecutor()); + } + + private ListAssetsPagedResponse(ListAssetsPage page) { + super(page, ListAssetsFixedSizeCollection.createEmptyCollection()); + } + } + + public static class ListAssetsPage + extends AbstractPage { + + private ListAssetsPage( + PageContext context, + ListAssetsResponse response) { + super(context, response); + } + + private static ListAssetsPage createEmptyPage() { + return new ListAssetsPage(null, null); + } + + @Override + protected ListAssetsPage createPage( + PageContext context, + ListAssetsResponse response) { + return new ListAssetsPage(context, response); + } + + @Override + public ApiFuture createPageAsync( + PageContext context, + ApiFuture futureResponse) { + return super.createPageAsync(context, futureResponse); + } + } + + public static class ListAssetsFixedSizeCollection + extends AbstractFixedSizeCollection< + ListAssetsRequest, + ListAssetsResponse, + Asset, + ListAssetsPage, + ListAssetsFixedSizeCollection> { + + private ListAssetsFixedSizeCollection(List pages, int collectionSize) { + super(pages, collectionSize); + } + + private static ListAssetsFixedSizeCollection createEmptyCollection() { + return new ListAssetsFixedSizeCollection(null, 0); + } + + @Override + protected ListAssetsFixedSizeCollection createCollection( + List pages, int collectionSize) { + return new ListAssetsFixedSizeCollection(pages, collectionSize); + } + } + public static class SearchAllResourcesPagedResponse extends AbstractPagedListResponse< SearchAllResourcesRequest, diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClientTest.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClientTest.java index 4149d36ad0..de8ca67414 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClientTest.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceClientTest.java @@ -16,6 +16,7 @@ package com.google.cloud.asset.v1; +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; @@ -27,6 +28,7 @@ import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.InvalidArgumentException; import com.google.api.gax.rpc.StatusCode; +import com.google.api.resourcenames.ResourceName; import com.google.common.collect.Lists; import com.google.longrunning.Operation; import com.google.protobuf.AbstractMessage; @@ -154,6 +156,94 @@ public void exportAssetsExceptionTest() throws Exception { } } + @Test + public void listAssetsTest() throws Exception { + Asset responsesElement = Asset.newBuilder().build(); + ListAssetsResponse expectedResponse = + ListAssetsResponse.newBuilder() + .setNextPageToken("") + .addAllAssets(Arrays.asList(responsesElement)) + .build(); + mockAssetService.addResponse(expectedResponse); + + ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + + 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 = mockAssetService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listAssetsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockAssetService.addException(exception); + + try { + ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]"); + 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(); + mockAssetService.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + 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 = mockAssetService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listAssetsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockAssetService.addException(exception); + + try { + String parent = "parent-995424086"; + client.listAssets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + @Test public void batchGetAssetsHistoryTest() throws Exception { BatchGetAssetsHistoryResponse expectedResponse = diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceSettings.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceSettings.java index 50c5dca652..6913dec708 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceSettings.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/AssetServiceSettings.java @@ -16,6 +16,7 @@ package com.google.cloud.asset.v1; +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; @@ -84,6 +85,12 @@ public UnaryCallSettings exportAssetsSettings() return ((AssetServiceStubSettings) getStubSettings()).exportAssetsOperationSettings(); } + /** Returns the object with the settings used for calls to listAssets. */ + public PagedCallSettings + listAssetsSettings() { + return ((AssetServiceStubSettings) getStubSettings()).listAssetsSettings(); + } + /** Returns the object with the settings used for calls to batchGetAssetsHistory. */ public UnaryCallSettings batchGetAssetsHistorySettings() { @@ -263,6 +270,12 @@ public UnaryCallSettings.Builder exportAssetsSet return getStubSettingsBuilder().exportAssetsOperationSettings(); } + /** Returns the builder for the settings used for calls to listAssets. */ + public PagedCallSettings.Builder + listAssetsSettings() { + return getStubSettingsBuilder().listAssetsSettings(); + } + /** Returns the builder for the settings used for calls to batchGetAssetsHistory. */ public UnaryCallSettings.Builder batchGetAssetsHistorySettings() { diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/MockAssetServiceImpl.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/MockAssetServiceImpl.java index 27b5f4021b..643691d8d4 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/MockAssetServiceImpl.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/MockAssetServiceImpl.java @@ -81,6 +81,27 @@ public void exportAssets( } } + @Override + public void listAssets( + ListAssetsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ListAssetsResponse) { + requests.add(request); + responseObserver.onNext(((ListAssetsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ListAssets, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ListAssetsResponse.class.getName(), + Exception.class.getName()))); + } + } + @Override public void batchGetAssetsHistory( BatchGetAssetsHistoryRequest request, diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/gapic_metadata.json b/test/integration/goldens/asset/com/google/cloud/asset/v1/gapic_metadata.json index d2c1608bb4..ea1187e7ac 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/gapic_metadata.json +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/gapic_metadata.json @@ -31,6 +31,9 @@ "GetFeed": { "methods": ["getFeed", "getFeed", "getFeed", "getFeedCallable"] }, + "ListAssets": { + "methods": ["listAssets", "listAssets", "listAssets", "listAssetsPagedCallable", "listAssetsCallable"] + }, "ListFeeds": { "methods": ["listFeeds", "listFeeds", "listFeedsCallable"] }, diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStub.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStub.java index b97b1874bb..462d7e2922 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStub.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStub.java @@ -16,6 +16,7 @@ package com.google.cloud.asset.v1.stub; +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; @@ -34,6 +35,8 @@ 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.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.SearchAllIamPoliciesRequest; @@ -68,6 +71,14 @@ public UnaryCallable exportAssetsCallable() { throw new UnsupportedOperationException("Not implemented: exportAssetsCallable()"); } + public UnaryCallable listAssetsPagedCallable() { + throw new UnsupportedOperationException("Not implemented: listAssetsPagedCallable()"); + } + + public UnaryCallable listAssetsCallable() { + throw new UnsupportedOperationException("Not implemented: listAssetsCallable()"); + } + public UnaryCallable batchGetAssetsHistoryCallable() { throw new UnsupportedOperationException("Not implemented: batchGetAssetsHistoryCallable()"); diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java index 52e7b84498..95b5de2ae8 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/AssetServiceStubSettings.java @@ -16,6 +16,7 @@ package com.google.cloud.asset.v1.stub; +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; @@ -49,6 +50,7 @@ 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.Asset; import com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest; import com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse; import com.google.cloud.asset.v1.CreateFeedRequest; @@ -58,6 +60,8 @@ import com.google.cloud.asset.v1.Feed; import com.google.cloud.asset.v1.GetFeedRequest; import com.google.cloud.asset.v1.IamPolicySearchResult; +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.ResourceSearchResult; @@ -119,6 +123,8 @@ public class AssetServiceStubSettings extends StubSettings exportAssetsOperationSettings; + private final PagedCallSettings + listAssetsSettings; private final UnaryCallSettings batchGetAssetsHistorySettings; private final UnaryCallSettings createFeedSettings; @@ -144,6 +150,42 @@ public class AssetServiceStubSettings extends StubSettings analyzeIamPolicyLongrunningOperationSettings; + private static final PagedListDescriptor + LIST_ASSETS_PAGE_STR_DESC = + new PagedListDescriptor() { + @Override + public String emptyToken() { + return ""; + } + + @Override + public ListAssetsRequest injectToken(ListAssetsRequest payload, String token) { + return ListAssetsRequest.newBuilder(payload).setPageToken(token).build(); + } + + @Override + public ListAssetsRequest injectPageSize(ListAssetsRequest payload, int pageSize) { + return ListAssetsRequest.newBuilder(payload).setPageSize(pageSize).build(); + } + + @Override + public Integer extractPageSize(ListAssetsRequest payload) { + return payload.getPageSize(); + } + + @Override + public String extractNextToken(ListAssetsResponse payload) { + return payload.getNextPageToken(); + } + + @Override + public Iterable extractResources(ListAssetsResponse payload) { + return payload.getAssetsList() == null + ? ImmutableList.of() + : payload.getAssetsList(); + } + }; + private static final PagedListDescriptor< SearchAllResourcesRequest, SearchAllResourcesResponse, ResourceSearchResult> SEARCH_ALL_RESOURCES_PAGE_STR_DESC = @@ -226,6 +268,23 @@ public Iterable extractResources( } }; + private static final PagedListResponseFactory< + ListAssetsRequest, ListAssetsResponse, ListAssetsPagedResponse> + LIST_ASSETS_PAGE_STR_FACT = + new PagedListResponseFactory< + ListAssetsRequest, ListAssetsResponse, ListAssetsPagedResponse>() { + @Override + public ApiFuture getFuturePagedResponse( + UnaryCallable callable, + ListAssetsRequest request, + ApiCallContext context, + ApiFuture futureResponse) { + PageContext pageContext = + PageContext.create(callable, LIST_ASSETS_PAGE_STR_DESC, request, context); + return ListAssetsPagedResponse.createAsync(pageContext, futureResponse); + } + }; + private static final PagedListResponseFactory< SearchAllResourcesRequest, SearchAllResourcesResponse, SearchAllResourcesPagedResponse> SEARCH_ALL_RESOURCES_PAGE_STR_FACT = @@ -285,6 +344,12 @@ public UnaryCallSettings exportAssetsSettings() return exportAssetsOperationSettings; } + /** Returns the object with the settings used for calls to listAssets. */ + public PagedCallSettings + listAssetsSettings() { + return listAssetsSettings; + } + /** Returns the object with the settings used for calls to batchGetAssetsHistory. */ public UnaryCallSettings batchGetAssetsHistorySettings() { @@ -429,6 +494,7 @@ protected AssetServiceStubSettings(Builder settingsBuilder) throws IOException { exportAssetsSettings = settingsBuilder.exportAssetsSettings().build(); exportAssetsOperationSettings = settingsBuilder.exportAssetsOperationSettings().build(); + listAssetsSettings = settingsBuilder.listAssetsSettings().build(); batchGetAssetsHistorySettings = settingsBuilder.batchGetAssetsHistorySettings().build(); createFeedSettings = settingsBuilder.createFeedSettings().build(); getFeedSettings = settingsBuilder.getFeedSettings().build(); @@ -451,6 +517,9 @@ public static class Builder extends StubSettings.Builder exportAssetsOperationSettings; + private final PagedCallSettings.Builder< + ListAssetsRequest, ListAssetsResponse, ListAssetsPagedResponse> + listAssetsSettings; private final UnaryCallSettings.Builder< BatchGetAssetsHistoryRequest, BatchGetAssetsHistoryResponse> batchGetAssetsHistorySettings; @@ -558,6 +627,7 @@ protected Builder(ClientContext clientContext) { exportAssetsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); exportAssetsOperationSettings = OperationCallSettings.newBuilder(); + listAssetsSettings = PagedCallSettings.newBuilder(LIST_ASSETS_PAGE_STR_FACT); batchGetAssetsHistorySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); createFeedSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); getFeedSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); @@ -574,6 +644,7 @@ protected Builder(ClientContext clientContext) { unaryMethodSettingsBuilders = ImmutableList.>of( exportAssetsSettings, + listAssetsSettings, batchGetAssetsHistorySettings, createFeedSettings, getFeedSettings, @@ -592,6 +663,7 @@ protected Builder(AssetServiceStubSettings settings) { exportAssetsSettings = settings.exportAssetsSettings.toBuilder(); exportAssetsOperationSettings = settings.exportAssetsOperationSettings.toBuilder(); + listAssetsSettings = settings.listAssetsSettings.toBuilder(); batchGetAssetsHistorySettings = settings.batchGetAssetsHistorySettings.toBuilder(); createFeedSettings = settings.createFeedSettings.toBuilder(); getFeedSettings = settings.getFeedSettings.toBuilder(); @@ -609,6 +681,7 @@ protected Builder(AssetServiceStubSettings settings) { unaryMethodSettingsBuilders = ImmutableList.>of( exportAssetsSettings, + listAssetsSettings, batchGetAssetsHistorySettings, createFeedSettings, getFeedSettings, @@ -640,6 +713,11 @@ private static Builder initDefaults(Builder builder) { .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params")); + builder + .listAssetsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_1_params")); + builder .batchGetAssetsHistorySettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_1_codes")) @@ -774,6 +852,12 @@ public UnaryCallSettings.Builder exportAssetsSet return exportAssetsOperationSettings; } + /** Returns the builder for the settings used for calls to listAssets. */ + public PagedCallSettings.Builder + listAssetsSettings() { + return listAssetsSettings; + } + /** Returns the builder for the settings used for calls to batchGetAssetsHistory. */ public UnaryCallSettings.Builder batchGetAssetsHistorySettings() { diff --git a/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java b/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java index 7fb9b4ba50..712d328088 100644 --- a/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java +++ b/test/integration/goldens/asset/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java @@ -16,6 +16,7 @@ package com.google.cloud.asset.v1.stub; +import static com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse; import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse; @@ -39,6 +40,8 @@ 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.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.SearchAllIamPoliciesRequest; @@ -74,6 +77,15 @@ public class GrpcAssetServiceStub extends AssetServiceStub { .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) .build(); + private static final MethodDescriptor + listAssetsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.asset.v1.AssetService/ListAssets") + .setRequestMarshaller(ProtoUtils.marshaller(ListAssetsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ListAssetsResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor batchGetAssetsHistoryMethodDescriptor = MethodDescriptor.newBuilder() @@ -172,6 +184,8 @@ public class GrpcAssetServiceStub extends AssetServiceStub { private final UnaryCallable exportAssetsCallable; private final OperationCallable exportAssetsOperationCallable; + private final UnaryCallable listAssetsCallable; + private final UnaryCallable listAssetsPagedCallable; private final UnaryCallable batchGetAssetsHistoryCallable; private final UnaryCallable createFeedCallable; @@ -252,6 +266,19 @@ public Map extract(ExportAssetsRequest request) { } }) .build(); + GrpcCallSettings listAssetsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(listAssetsMethodDescriptor) + .setParamsExtractor( + new RequestParamsExtractor() { + @Override + public Map extract(ListAssetsRequest request) { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("parent", String.valueOf(request.getParent())); + return params.build(); + } + }) + .build(); GrpcCallSettings batchGetAssetsHistoryTransportSettings = GrpcCallSettings @@ -403,6 +430,12 @@ public Map extract( settings.exportAssetsOperationSettings(), clientContext, operationsStub); + this.listAssetsCallable = + callableFactory.createUnaryCallable( + listAssetsTransportSettings, settings.listAssetsSettings(), clientContext); + this.listAssetsPagedCallable = + callableFactory.createPagedCallable( + listAssetsTransportSettings, settings.listAssetsSettings(), clientContext); this.batchGetAssetsHistoryCallable = callableFactory.createUnaryCallable( batchGetAssetsHistoryTransportSettings, @@ -477,6 +510,16 @@ public UnaryCallable exportAssetsCallable() { return exportAssetsOperationCallable; } + @Override + public UnaryCallable listAssetsCallable() { + return listAssetsCallable; + } + + @Override + public UnaryCallable listAssetsPagedCallable() { + return listAssetsPagedCallable; + } + @Override public UnaryCallable batchGetAssetsHistoryCallable() { diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java index a1ccb48e46..fd93ba8e5e 100644 --- a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/AddressesStubSettings.java @@ -59,6 +59,7 @@ import java.util.List; import java.util.Map; import javax.annotation.Generated; +import org.threeten.bp.Duration; // AUTO-GENERATED DOCUMENTATION AND CLASS. /** @@ -348,7 +349,13 @@ public static class Builder extends StubSettings.Builder> definitions = ImmutableMap.builder(); - definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_0_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put( + "no_retry_1_codes", ImmutableSet.copyOf(Lists.newArrayList())); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -357,8 +364,25 @@ public static class Builder extends StubSettings.Builder definitions = ImmutableMap.builder(); RetrySettings settings = null; - settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); - definitions.put("no_retry_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(600000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(600000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("retry_policy_0_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(600000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(600000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("no_retry_1_params", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); } @@ -409,23 +433,23 @@ private static Builder createDefault() { private static Builder initDefaults(Builder builder) { builder .aggregatedListSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); builder .deleteSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); builder .insertSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); builder .listSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); return builder; } diff --git a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java index 25be522d20..6e6eb4a892 100644 --- a/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java +++ b/test/integration/goldens/compute/com/google/cloud/compute/v1/stub/RegionOperationsStubSettings.java @@ -40,6 +40,7 @@ import java.io.IOException; import java.util.List; import javax.annotation.Generated; +import org.threeten.bp.Duration; // AUTO-GENERATED DOCUMENTATION AND CLASS. /** @@ -178,7 +179,11 @@ public static class Builder extends StubSettings.Builder> definitions = ImmutableMap.builder(); - definitions.put("no_retry_codes", ImmutableSet.copyOf(Lists.newArrayList())); + definitions.put( + "retry_policy_0_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); RETRYABLE_CODE_DEFINITIONS = definitions.build(); } @@ -187,8 +192,17 @@ public static class Builder extends StubSettings.Builder definitions = ImmutableMap.builder(); RetrySettings settings = null; - settings = RetrySettings.newBuilder().setRpcTimeoutMultiplier(1.0).build(); - definitions.put("no_retry_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(600000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(600000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("retry_policy_0_params", settings); RETRY_PARAM_DEFINITIONS = definitions.build(); } @@ -229,8 +243,8 @@ private static Builder createDefault() { private static Builder initDefaults(Builder builder) { builder .getSettings() - .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes")) - .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params")); + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); return builder; }