From 566bc6feab9b5483d96cb6cbe0e4d396a431825b 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 14:52:11 +0000 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#357) - [ ] 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-orgpolicy/pom.xml | 16 + .../cloud/orgpolicy/v2/OrgPolicyClient.java | 14 + .../cloud/orgpolicy/v2/OrgPolicySettings.java | 23 +- .../HttpJsonOrgPolicyCallableFactory.java | 105 ++ .../v2/stub/HttpJsonOrgPolicyStub.java | 543 ++++++++++ .../v2/stub/OrgPolicyStubSettings.java | 52 +- .../v2/OrgPolicyClientHttpJsonTest.java | 990 ++++++++++++++++++ .../SyncCreateSetCredentialsProvider.java | 41 + .../SyncCreateSetCredentialsProvider1.java | 40 + .../create/SyncCreateSetEndpoint.java | 38 + .../createpolicy/AsyncCreatePolicy.java | 47 + .../createpolicy/SyncCreatePolicy.java | 44 + .../SyncCreatePolicyFoldernamePolicy.java | 40 + ...yncCreatePolicyOrganizationnamePolicy.java | 40 + .../SyncCreatePolicyProjectnamePolicy.java | 40 + .../SyncCreatePolicyStringPolicy.java | 40 + .../deletepolicy/AsyncDeletePolicy.java | 46 + .../deletepolicy/SyncDeletePolicy.java | 42 + .../SyncDeletePolicyPolicyname.java | 38 + .../deletepolicy/SyncDeletePolicyString.java | 38 + .../AsyncGetEffectivePolicy.java | 46 + .../SyncGetEffectivePolicy.java | 43 + .../SyncGetEffectivePolicyPolicyname.java | 39 + .../SyncGetEffectivePolicyString.java | 39 + .../getpolicy/AsyncGetPolicy.java | 46 + .../getpolicy/SyncGetPolicy.java | 43 + .../getpolicy/SyncGetPolicyPolicyname.java | 39 + .../getpolicy/SyncGetPolicyString.java | 39 + .../listconstraints/AsyncListConstraints.java | 51 + .../AsyncListConstraintsPaged.java | 58 + .../listconstraints/SyncListConstraints.java | 47 + .../SyncListConstraintsFoldername.java | 41 + .../SyncListConstraintsOrganizationname.java | 41 + .../SyncListConstraintsProjectname.java | 41 + .../SyncListConstraintsString.java | 41 + .../listpolicies/AsyncListPolicies.java | 50 + .../listpolicies/AsyncListPoliciesPaged.java | 58 + .../listpolicies/SyncListPolicies.java | 47 + .../SyncListPoliciesFoldername.java | 41 + .../SyncListPoliciesOrganizationname.java | 41 + .../SyncListPoliciesProjectname.java | 41 + .../listpolicies/SyncListPoliciesString.java | 41 + .../updatepolicy/AsyncUpdatePolicy.java | 43 + .../updatepolicy/SyncUpdatePolicy.java | 40 + .../updatepolicy/SyncUpdatePolicyPolicy.java | 38 + .../getpolicy/SyncGetPolicy.java | 45 + .../getpolicy/SyncGetPolicy.java | 45 + 47 files changed, 3456 insertions(+), 5 deletions(-) create mode 100644 google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyCallableFactory.java create mode 100644 google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyStub.java create mode 100644 google-cloud-orgpolicy/src/test/java/com/google/cloud/orgpolicy/v2/OrgPolicyClientHttpJsonTest.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetEndpoint.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/AsyncCreatePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyFoldernamePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyOrganizationnamePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyProjectnamePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyStringPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/AsyncDeletePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyPolicyname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyString.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/AsyncGetEffectivePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyPolicyname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyString.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/AsyncGetPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyPolicyname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyString.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraints.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraintsPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraints.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsFoldername.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsOrganizationname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsProjectname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsString.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPoliciesPaged.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPolicies.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesFoldername.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesOrganizationname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesProjectname.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesString.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/AsyncUpdatePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicyPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicysettings/getpolicy/SyncGetPolicy.java create mode 100644 samples/snippets/generated/com/google/cloud/orgpolicy/v2/stub/orgpolicystubsettings/getpolicy/SyncGetPolicy.java diff --git a/google-cloud-orgpolicy/pom.xml b/google-cloud-orgpolicy/pom.xml index 92d01b8..673771a 100644 --- a/google-cloud-orgpolicy/pom.xml +++ b/google-cloud-orgpolicy/pom.xml @@ -61,6 +61,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -79,12 +83,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-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicyClient.java b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicyClient.java index f25877c..48d8382 100644 --- a/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicyClient.java +++ b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicyClient.java @@ -113,6 +113,20 @@ * OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); * } * + *

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.
+ * OrgPolicySettings orgPolicySettings =
+ *     OrgPolicySettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             OrgPolicySettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") diff --git a/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicySettings.java b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicySettings.java index d1e067d..fb0e60c 100644 --- a/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicySettings.java +++ b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/OrgPolicySettings.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; @@ -134,11 +135,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return OrgPolicyStubSettings.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 OrgPolicyStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return OrgPolicyStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return OrgPolicyStubSettings.defaultTransportChannelProvider(); } @@ -148,11 +156,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return OrgPolicyStubSettings.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); @@ -190,6 +204,11 @@ private static Builder createDefault() { return new Builder(OrgPolicyStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(OrgPolicyStubSettings.newHttpJsonBuilder()); + } + public OrgPolicyStubSettings.Builder getStubSettingsBuilder() { return ((OrgPolicyStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyCallableFactory.java b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyCallableFactory.java new file mode 100644 index 0000000..ee892c9 --- /dev/null +++ b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyCallableFactory.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.orgpolicy.v2.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 OrgPolicy service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonOrgPolicyCallableFactory + 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-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyStub.java b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyStub.java new file mode 100644 index 0000000..9e08177 --- /dev/null +++ b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/HttpJsonOrgPolicyStub.java @@ -0,0 +1,543 @@ +/* + * 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.orgpolicy.v2.stub; + +import static com.google.cloud.orgpolicy.v2.OrgPolicyClient.ListConstraintsPagedResponse; +import static com.google.cloud.orgpolicy.v2.OrgPolicyClient.ListPoliciesPagedResponse; + +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.orgpolicy.v2.CreatePolicyRequest; +import com.google.cloud.orgpolicy.v2.DeletePolicyRequest; +import com.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest; +import com.google.cloud.orgpolicy.v2.GetPolicyRequest; +import com.google.cloud.orgpolicy.v2.ListConstraintsRequest; +import com.google.cloud.orgpolicy.v2.ListConstraintsResponse; +import com.google.cloud.orgpolicy.v2.ListPoliciesRequest; +import com.google.cloud.orgpolicy.v2.ListPoliciesResponse; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.UpdatePolicyRequest; +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 OrgPolicy service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonOrgPolicyStub extends OrgPolicyStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + listConstraintsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/ListConstraints") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*}/constraints", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v2/{parent=folders/*}/constraints", + "/v2/{parent=organizations/*}/constraints") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListConstraintsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listPoliciesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/ListPolicies") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*}/policies", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v2/{parent=folders/*}/policies", + "/v2/{parent=organizations/*}/policies") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ListPoliciesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor getPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/GetPolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/policies/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v2/{name=folders/*/policies/*}", "/v2/{name=organizations/*/policies/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getEffectivePolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/GetEffectivePolicy") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/policies/*}:getEffectivePolicy", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v2/{name=folders/*/policies/*}:getEffectivePolicy", + "/v2/{name=organizations/*/policies/*}:getEffectivePolicy") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + createPolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/CreatePolicy") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{parent=projects/*}/policies", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths( + "/v2/{parent=folders/*}/policies", + "/v2/{parent=organizations/*}/policies") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("policy", request.getPolicy())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updatePolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/UpdatePolicy") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{policy.name=projects/*/policies/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam( + fields, "policy.name", request.getPolicy().getName()); + return fields; + }) + .setAdditionalPaths( + "/v2/{policy.name=folders/*/policies/*}", + "/v2/{policy.name=organizations/*/policies/*}") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create().toBody("policy", request.getPolicy())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Policy.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deletePolicyMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/DeletePolicy") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v2/{name=projects/*/policies/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setAdditionalPaths( + "/v2/{name=folders/*/policies/*}", + "/v2/{name=organizations/*/policies/*}") + .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 + listConstraintsCallable; + private final UnaryCallable + listConstraintsPagedCallable; + private final UnaryCallable listPoliciesCallable; + private final UnaryCallable + listPoliciesPagedCallable; + private final UnaryCallable getPolicyCallable; + private final UnaryCallable getEffectivePolicyCallable; + private final UnaryCallable createPolicyCallable; + private final UnaryCallable updatePolicyCallable; + private final UnaryCallable deletePolicyCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonOrgPolicyStub create(OrgPolicyStubSettings settings) + throws IOException { + return new HttpJsonOrgPolicyStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonOrgPolicyStub create(ClientContext clientContext) throws IOException { + return new HttpJsonOrgPolicyStub( + OrgPolicyStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonOrgPolicyStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonOrgPolicyStub( + OrgPolicyStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonOrgPolicyStub, 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 HttpJsonOrgPolicyStub(OrgPolicyStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonOrgPolicyCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonOrgPolicyStub, 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 HttpJsonOrgPolicyStub( + OrgPolicyStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + listConstraintsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listConstraintsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings listPoliciesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listPoliciesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getEffectivePolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getEffectivePolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createPolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createPolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updatePolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updatePolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deletePolicyTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deletePolicyMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.listConstraintsCallable = + callableFactory.createUnaryCallable( + listConstraintsTransportSettings, settings.listConstraintsSettings(), clientContext); + this.listConstraintsPagedCallable = + callableFactory.createPagedCallable( + listConstraintsTransportSettings, settings.listConstraintsSettings(), clientContext); + this.listPoliciesCallable = + callableFactory.createUnaryCallable( + listPoliciesTransportSettings, settings.listPoliciesSettings(), clientContext); + this.listPoliciesPagedCallable = + callableFactory.createPagedCallable( + listPoliciesTransportSettings, settings.listPoliciesSettings(), clientContext); + this.getPolicyCallable = + callableFactory.createUnaryCallable( + getPolicyTransportSettings, settings.getPolicySettings(), clientContext); + this.getEffectivePolicyCallable = + callableFactory.createUnaryCallable( + getEffectivePolicyTransportSettings, + settings.getEffectivePolicySettings(), + clientContext); + this.createPolicyCallable = + callableFactory.createUnaryCallable( + createPolicyTransportSettings, settings.createPolicySettings(), clientContext); + this.updatePolicyCallable = + callableFactory.createUnaryCallable( + updatePolicyTransportSettings, settings.updatePolicySettings(), clientContext); + this.deletePolicyCallable = + callableFactory.createUnaryCallable( + deletePolicyTransportSettings, settings.deletePolicySettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(listConstraintsMethodDescriptor); + methodDescriptors.add(listPoliciesMethodDescriptor); + methodDescriptors.add(getPolicyMethodDescriptor); + methodDescriptors.add(getEffectivePolicyMethodDescriptor); + methodDescriptors.add(createPolicyMethodDescriptor); + methodDescriptors.add(updatePolicyMethodDescriptor); + methodDescriptors.add(deletePolicyMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable listConstraintsCallable() { + return listConstraintsCallable; + } + + @Override + public UnaryCallable + listConstraintsPagedCallable() { + return listConstraintsPagedCallable; + } + + @Override + public UnaryCallable listPoliciesCallable() { + return listPoliciesCallable; + } + + @Override + public UnaryCallable listPoliciesPagedCallable() { + return listPoliciesPagedCallable; + } + + @Override + public UnaryCallable getPolicyCallable() { + return getPolicyCallable; + } + + @Override + public UnaryCallable getEffectivePolicyCallable() { + return getEffectivePolicyCallable; + } + + @Override + public UnaryCallable createPolicyCallable() { + return createPolicyCallable; + } + + @Override + public UnaryCallable updatePolicyCallable() { + return updatePolicyCallable; + } + + @Override + public UnaryCallable deletePolicyCallable() { + return deletePolicyCallable; + } + + @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-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/OrgPolicyStubSettings.java b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/OrgPolicyStubSettings.java index 6109a32..d77efc4 100644 --- a/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/OrgPolicyStubSettings.java +++ b/google-cloud-orgpolicy/src/main/java/com/google/cloud/orgpolicy/v2/stub/OrgPolicyStubSettings.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; @@ -266,6 +269,11 @@ public OrgPolicyStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcOrgPolicyStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonOrgPolicyStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -298,29 +306,54 @@ 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(OrgPolicyStubSettings.class)) .setTransportToken( 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(OrgPolicyStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return OrgPolicyStubSettings.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); @@ -453,6 +486,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 .listConstraintsSettings() diff --git a/google-cloud-orgpolicy/src/test/java/com/google/cloud/orgpolicy/v2/OrgPolicyClientHttpJsonTest.java b/google-cloud-orgpolicy/src/test/java/com/google/cloud/orgpolicy/v2/OrgPolicyClientHttpJsonTest.java new file mode 100644 index 0000000..0f52b46 --- /dev/null +++ b/google-cloud-orgpolicy/src/test/java/com/google/cloud/orgpolicy/v2/OrgPolicyClientHttpJsonTest.java @@ -0,0 +1,990 @@ +/* + * 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.orgpolicy.v2; + +import static com.google.cloud.orgpolicy.v2.OrgPolicyClient.ListConstraintsPagedResponse; +import static com.google.cloud.orgpolicy.v2.OrgPolicyClient.ListPoliciesPagedResponse; + +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.orgpolicy.v2.stub.HttpJsonOrgPolicyStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import java.io.IOException; +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 OrgPolicyClientHttpJsonTest { + private static MockHttpService mockService; + private static OrgPolicyClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonOrgPolicyStub.getMethodDescriptors(), OrgPolicySettings.getDefaultEndpoint()); + OrgPolicySettings settings = + OrgPolicySettings.newHttpJsonBuilder() + .setTransportChannelProvider( + OrgPolicySettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = OrgPolicyClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void listConstraintsTest() throws Exception { + Constraint responsesElement = Constraint.newBuilder().build(); + ListConstraintsResponse expectedResponse = + ListConstraintsResponse.newBuilder() + .setNextPageToken("") + .addAllConstraints(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListConstraintsPagedResponse pagedListResponse = client.listConstraints(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getConstraintsList().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 listConstraintsExceptionTest() 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.listConstraints(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listConstraintsTest2() throws Exception { + Constraint responsesElement = Constraint.newBuilder().build(); + ListConstraintsResponse expectedResponse = + ListConstraintsResponse.newBuilder() + .setNextPageToken("") + .addAllConstraints(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListConstraintsPagedResponse pagedListResponse = client.listConstraints(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getConstraintsList().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 listConstraintsExceptionTest2() 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.listConstraints(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listConstraintsTest3() throws Exception { + Constraint responsesElement = Constraint.newBuilder().build(); + ListConstraintsResponse expectedResponse = + ListConstraintsResponse.newBuilder() + .setNextPageToken("") + .addAllConstraints(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListConstraintsPagedResponse pagedListResponse = client.listConstraints(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getConstraintsList().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 listConstraintsExceptionTest3() 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.listConstraints(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listConstraintsTest4() throws Exception { + Constraint responsesElement = Constraint.newBuilder().build(); + ListConstraintsResponse expectedResponse = + ListConstraintsResponse.newBuilder() + .setNextPageToken("") + .addAllConstraints(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-2353"; + + ListConstraintsPagedResponse pagedListResponse = client.listConstraints(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getConstraintsList().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 listConstraintsExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-2353"; + client.listConstraints(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listPoliciesTest() throws Exception { + Policy responsesElement = Policy.newBuilder().build(); + ListPoliciesResponse expectedResponse = + ListPoliciesResponse.newBuilder() + .setNextPageToken("") + .addAllPolicies(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListPoliciesPagedResponse pagedListResponse = client.listPolicies(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getPoliciesList().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 listPoliciesExceptionTest() 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.listPolicies(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listPoliciesTest2() throws Exception { + Policy responsesElement = Policy.newBuilder().build(); + ListPoliciesResponse expectedResponse = + ListPoliciesResponse.newBuilder() + .setNextPageToken("") + .addAllPolicies(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListPoliciesPagedResponse pagedListResponse = client.listPolicies(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getPoliciesList().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 listPoliciesExceptionTest2() 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.listPolicies(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listPoliciesTest3() throws Exception { + Policy responsesElement = Policy.newBuilder().build(); + ListPoliciesResponse expectedResponse = + ListPoliciesResponse.newBuilder() + .setNextPageToken("") + .addAllPolicies(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListPoliciesPagedResponse pagedListResponse = client.listPolicies(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getPoliciesList().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 listPoliciesExceptionTest3() 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.listPolicies(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listPoliciesTest4() throws Exception { + Policy responsesElement = Policy.newBuilder().build(); + ListPoliciesResponse expectedResponse = + ListPoliciesResponse.newBuilder() + .setNextPageToken("") + .addAllPolicies(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-2353"; + + ListPoliciesPagedResponse pagedListResponse = client.listPolicies(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getPoliciesList().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 listPoliciesExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-2353"; + client.listPolicies(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + + Policy actualResponse = client.getPolicy(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 getPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + client.getPolicy(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3674/policies/policie-3674"; + + Policy actualResponse = client.getPolicy(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 getPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3674/policies/policie-3674"; + client.getPolicy(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEffectivePolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + + Policy actualResponse = client.getEffectivePolicy(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 getEffectivePolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + client.getEffectivePolicy(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getEffectivePolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3674/policies/policie-3674"; + + Policy actualResponse = client.getEffectivePolicy(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 getEffectivePolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3674/policies/policie-3674"; + client.getEffectivePolicy(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createPolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.createPolicy(parent, policy); + 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 createPolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + Policy policy = Policy.newBuilder().build(); + client.createPolicy(parent, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createPolicyTest2() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.createPolicy(parent, policy); + 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 createPolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + Policy policy = Policy.newBuilder().build(); + client.createPolicy(parent, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createPolicyTest3() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.createPolicy(parent, policy); + 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 createPolicyExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + Policy policy = Policy.newBuilder().build(); + client.createPolicy(parent, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createPolicyTest4() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-2353"; + Policy policy = Policy.newBuilder().build(); + + Policy actualResponse = client.createPolicy(parent, policy); + 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 createPolicyExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-2353"; + Policy policy = Policy.newBuilder().build(); + client.createPolicy(parent, policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updatePolicyTest() throws Exception { + Policy expectedResponse = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + Policy policy = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + + Policy actualResponse = client.updatePolicy(policy); + 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 updatePolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + Policy policy = + Policy.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .setSpec(PolicySpec.newBuilder().build()) + .setAlternate(AlternatePolicySpec.newBuilder().build()) + .build(); + client.updatePolicy(policy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deletePolicyTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + + client.deletePolicy(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 deletePolicyExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + client.deletePolicy(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deletePolicyTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-3674/policies/policie-3674"; + + client.deletePolicy(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 deletePolicyExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-3674/policies/policie-3674"; + client.deletePolicy(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 0000000..4a94c74 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.OrgPolicySettings; +import com.google.cloud.orgpolicy.v2.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. + OrgPolicySettings orgPolicySettings = + OrgPolicySettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 0000000..96d43fa --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_create_setcredentialsprovider1_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.OrgPolicySettings; + +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. + OrgPolicySettings orgPolicySettings = + OrgPolicySettings.newBuilder() + .setTransportChannelProvider( + OrgPolicySettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 0000000..1db4dd3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_create_setendpoint_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.OrgPolicySettings; +import com.google.cloud.orgpolicy.v2.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. + OrgPolicySettings orgPolicySettings = + OrgPolicySettings.newBuilder().setEndpoint(myEndpoint).build(); + OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/AsyncCreatePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/AsyncCreatePolicy.java new file mode 100644 index 0000000..ab33e96 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/AsyncCreatePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_createpolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.CreatePolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class AsyncCreatePolicy { + + public static void main(String[] args) throws Exception { + asyncCreatePolicy(); + } + + public static void asyncCreatePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + CreatePolicyRequest request = + CreatePolicyRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPolicy(Policy.newBuilder().build()) + .build(); + ApiFuture future = orgPolicyClient.createPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_createpolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicy.java new file mode 100644 index 0000000..7c06494 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_createpolicy_sync] +import com.google.cloud.orgpolicy.v2.CreatePolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncCreatePolicy { + + public static void main(String[] args) throws Exception { + syncCreatePolicy(); + } + + public static void syncCreatePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + CreatePolicyRequest request = + CreatePolicyRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPolicy(Policy.newBuilder().build()) + .build(); + Policy response = orgPolicyClient.createPolicy(request); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_createpolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyFoldernamePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyFoldernamePolicy.java new file mode 100644 index 0000000..1eb146d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyFoldernamePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_createpolicy_foldernamepolicy_sync] +import com.google.cloud.orgpolicy.v2.FolderName; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; + +public class SyncCreatePolicyFoldernamePolicy { + + public static void main(String[] args) throws Exception { + syncCreatePolicyFoldernamePolicy(); + } + + public static void syncCreatePolicyFoldernamePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + Policy policy = Policy.newBuilder().build(); + Policy response = orgPolicyClient.createPolicy(parent, policy); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_createpolicy_foldernamepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyOrganizationnamePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyOrganizationnamePolicy.java new file mode 100644 index 0000000..064f570 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyOrganizationnamePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_createpolicy_organizationnamepolicy_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.OrganizationName; +import com.google.cloud.orgpolicy.v2.Policy; + +public class SyncCreatePolicyOrganizationnamePolicy { + + public static void main(String[] args) throws Exception { + syncCreatePolicyOrganizationnamePolicy(); + } + + public static void syncCreatePolicyOrganizationnamePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + Policy policy = Policy.newBuilder().build(); + Policy response = orgPolicyClient.createPolicy(parent, policy); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_createpolicy_organizationnamepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyProjectnamePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyProjectnamePolicy.java new file mode 100644 index 0000000..122ee18 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyProjectnamePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_createpolicy_projectnamepolicy_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncCreatePolicyProjectnamePolicy { + + public static void main(String[] args) throws Exception { + syncCreatePolicyProjectnamePolicy(); + } + + public static void syncCreatePolicyProjectnamePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + Policy policy = Policy.newBuilder().build(); + Policy response = orgPolicyClient.createPolicy(parent, policy); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_createpolicy_projectnamepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyStringPolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyStringPolicy.java new file mode 100644 index 0000000..e64546b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/createpolicy/SyncCreatePolicyStringPolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_createpolicy_stringpolicy_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncCreatePolicyStringPolicy { + + public static void main(String[] args) throws Exception { + syncCreatePolicyStringPolicy(); + } + + public static void syncCreatePolicyStringPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + Policy policy = Policy.newBuilder().build(); + Policy response = orgPolicyClient.createPolicy(parent, policy); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_createpolicy_stringpolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/AsyncDeletePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/AsyncDeletePolicy.java new file mode 100644 index 0000000..edc4936 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/AsyncDeletePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_deletepolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.DeletePolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.PolicyName; +import com.google.protobuf.Empty; + +public class AsyncDeletePolicy { + + public static void main(String[] args) throws Exception { + asyncDeletePolicy(); + } + + public static void asyncDeletePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + DeletePolicyRequest request = + DeletePolicyRequest.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .build(); + ApiFuture future = orgPolicyClient.deletePolicyCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_deletepolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicy.java new file mode 100644 index 0000000..66c9770 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_deletepolicy_sync] +import com.google.cloud.orgpolicy.v2.DeletePolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncDeletePolicy { + + public static void main(String[] args) throws Exception { + syncDeletePolicy(); + } + + public static void syncDeletePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + DeletePolicyRequest request = + DeletePolicyRequest.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .build(); + orgPolicyClient.deletePolicy(request); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_deletepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyPolicyname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyPolicyname.java new file mode 100644 index 0000000..a258766 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyPolicyname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_deletepolicy_policyname_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncDeletePolicyPolicyname { + + public static void main(String[] args) throws Exception { + syncDeletePolicyPolicyname(); + } + + public static void syncDeletePolicyPolicyname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + orgPolicyClient.deletePolicy(name); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_deletepolicy_policyname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyString.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyString.java new file mode 100644 index 0000000..9f68d2b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/deletepolicy/SyncDeletePolicyString.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_deletepolicy_string_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncDeletePolicyString { + + public static void main(String[] args) throws Exception { + syncDeletePolicyString(); + } + + public static void syncDeletePolicyString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString(); + orgPolicyClient.deletePolicy(name); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_deletepolicy_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/AsyncGetEffectivePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/AsyncGetEffectivePolicy.java new file mode 100644 index 0000000..c1605d5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/AsyncGetEffectivePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class AsyncGetEffectivePolicy { + + public static void main(String[] args) throws Exception { + asyncGetEffectivePolicy(); + } + + public static void asyncGetEffectivePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + GetEffectivePolicyRequest request = + GetEffectivePolicyRequest.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .build(); + ApiFuture future = orgPolicyClient.getEffectivePolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicy.java new file mode 100644 index 0000000..b987333 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_sync] +import com.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncGetEffectivePolicy { + + public static void main(String[] args) throws Exception { + syncGetEffectivePolicy(); + } + + public static void syncGetEffectivePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + GetEffectivePolicyRequest request = + GetEffectivePolicyRequest.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .build(); + Policy response = orgPolicyClient.getEffectivePolicy(request); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyPolicyname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyPolicyname.java new file mode 100644 index 0000000..5924a52 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyPolicyname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_policyname_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncGetEffectivePolicyPolicyname { + + public static void main(String[] args) throws Exception { + syncGetEffectivePolicyPolicyname(); + } + + public static void syncGetEffectivePolicyPolicyname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + Policy response = orgPolicyClient.getEffectivePolicy(name); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_policyname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyString.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyString.java new file mode 100644 index 0000000..49cec4b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/geteffectivepolicy/SyncGetEffectivePolicyString.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_string_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncGetEffectivePolicyString { + + public static void main(String[] args) throws Exception { + syncGetEffectivePolicyString(); + } + + public static void syncGetEffectivePolicyString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString(); + Policy response = orgPolicyClient.getEffectivePolicy(name); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_geteffectivepolicy_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/AsyncGetPolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/AsyncGetPolicy.java new file mode 100644 index 0000000..54a9015 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/AsyncGetPolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_getpolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.GetPolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class AsyncGetPolicy { + + public static void main(String[] args) throws Exception { + asyncGetPolicy(); + } + + public static void asyncGetPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + GetPolicyRequest request = + GetPolicyRequest.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .build(); + ApiFuture future = orgPolicyClient.getPolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_getpolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicy.java new file mode 100644 index 0000000..a1a0b50 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_getpolicy_sync] +import com.google.cloud.orgpolicy.v2.GetPolicyRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncGetPolicy { + + public static void main(String[] args) throws Exception { + syncGetPolicy(); + } + + public static void syncGetPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + GetPolicyRequest request = + GetPolicyRequest.newBuilder() + .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) + .build(); + Policy response = orgPolicyClient.getPolicy(request); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_getpolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyPolicyname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyPolicyname.java new file mode 100644 index 0000000..86e590a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyPolicyname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_getpolicy_policyname_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncGetPolicyPolicyname { + + public static void main(String[] args) throws Exception { + syncGetPolicyPolicyname(); + } + + public static void syncGetPolicyPolicyname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); + Policy response = orgPolicyClient.getPolicy(name); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_getpolicy_policyname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyString.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyString.java new file mode 100644 index 0000000..80f3242 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/getpolicy/SyncGetPolicyString.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_getpolicy_string_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.PolicyName; + +public class SyncGetPolicyString { + + public static void main(String[] args) throws Exception { + syncGetPolicyString(); + } + + public static void syncGetPolicyString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString(); + Policy response = orgPolicyClient.getPolicy(name); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_getpolicy_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraints.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraints.java new file mode 100644 index 0000000..66e835f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraints.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.ListConstraintsRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class AsyncListConstraints { + + public static void main(String[] args) throws Exception { + asyncListConstraints(); + } + + public static void asyncListConstraints() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ListConstraintsRequest request = + ListConstraintsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + orgPolicyClient.listConstraintsPagedCallable().futureCall(request); + // Do something. + for (Constraint element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraintsPaged.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraintsPaged.java new file mode 100644 index 0000000..d948fd4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/AsyncListConstraintsPaged.java @@ -0,0 +1,58 @@ +/* + * 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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_paged_async] +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.ListConstraintsRequest; +import com.google.cloud.orgpolicy.v2.ListConstraintsResponse; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.ProjectName; +import com.google.common.base.Strings; + +public class AsyncListConstraintsPaged { + + public static void main(String[] args) throws Exception { + asyncListConstraintsPaged(); + } + + public static void asyncListConstraintsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ListConstraintsRequest request = + ListConstraintsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListConstraintsResponse response = orgPolicyClient.listConstraintsCallable().call(request); + for (Constraint element : response.getConstraintsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraints.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraints.java new file mode 100644 index 0000000..c4848c6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraints.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_sync] +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.ListConstraintsRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncListConstraints { + + public static void main(String[] args) throws Exception { + syncListConstraints(); + } + + public static void syncListConstraints() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ListConstraintsRequest request = + ListConstraintsRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Constraint element : orgPolicyClient.listConstraints(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsFoldername.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsFoldername.java new file mode 100644 index 0000000..dc7a778 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsFoldername.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_foldername_sync] +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.FolderName; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; + +public class SyncListConstraintsFoldername { + + public static void main(String[] args) throws Exception { + syncListConstraintsFoldername(); + } + + public static void syncListConstraintsFoldername() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_foldername_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsOrganizationname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsOrganizationname.java new file mode 100644 index 0000000..9152251 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsOrganizationname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_organizationname_sync] +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.OrganizationName; + +public class SyncListConstraintsOrganizationname { + + public static void main(String[] args) throws Exception { + syncListConstraintsOrganizationname(); + } + + public static void syncListConstraintsOrganizationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_organizationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsProjectname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsProjectname.java new file mode 100644 index 0000000..69adf9f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsProjectname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_projectname_sync] +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncListConstraintsProjectname { + + public static void main(String[] args) throws Exception { + syncListConstraintsProjectname(); + } + + public static void syncListConstraintsProjectname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_projectname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsString.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsString.java new file mode 100644 index 0000000..7410d08 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listconstraints/SyncListConstraintsString.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listconstraints_string_sync] +import com.google.cloud.orgpolicy.v2.Constraint; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncListConstraintsString { + + public static void main(String[] args) throws Exception { + syncListConstraintsString(); + } + + public static void syncListConstraintsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listconstraints_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPolicies.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPolicies.java new file mode 100644 index 0000000..c910985 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPolicies.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.ListPoliciesRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class AsyncListPolicies { + + public static void main(String[] args) throws Exception { + asyncListPolicies(); + } + + public static void asyncListPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ListPoliciesRequest request = + ListPoliciesRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = orgPolicyClient.listPoliciesPagedCallable().futureCall(request); + // Do something. + for (Policy element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPoliciesPaged.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPoliciesPaged.java new file mode 100644 index 0000000..610c64e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/AsyncListPoliciesPaged.java @@ -0,0 +1,58 @@ +/* + * 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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_paged_async] +import com.google.cloud.orgpolicy.v2.ListPoliciesRequest; +import com.google.cloud.orgpolicy.v2.ListPoliciesResponse; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; +import com.google.common.base.Strings; + +public class AsyncListPoliciesPaged { + + public static void main(String[] args) throws Exception { + asyncListPoliciesPaged(); + } + + public static void asyncListPoliciesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ListPoliciesRequest request = + ListPoliciesRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListPoliciesResponse response = orgPolicyClient.listPoliciesCallable().call(request); + for (Policy element : response.getPoliciesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPolicies.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPolicies.java new file mode 100644 index 0000000..895a3e7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPolicies.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_sync] +import com.google.cloud.orgpolicy.v2.ListPoliciesRequest; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncListPolicies { + + public static void main(String[] args) throws Exception { + syncListPolicies(); + } + + public static void syncListPolicies() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ListPoliciesRequest request = + ListPoliciesRequest.newBuilder() + .setParent(ProjectName.of("[PROJECT]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (Policy element : orgPolicyClient.listPolicies(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesFoldername.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesFoldername.java new file mode 100644 index 0000000..ea6213b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesFoldername.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_foldername_sync] +import com.google.cloud.orgpolicy.v2.FolderName; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; + +public class SyncListPoliciesFoldername { + + public static void main(String[] args) throws Exception { + syncListPoliciesFoldername(); + } + + public static void syncListPoliciesFoldername() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + FolderName parent = FolderName.of("[FOLDER]"); + for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_foldername_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesOrganizationname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesOrganizationname.java new file mode 100644 index 0000000..0b55b95 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesOrganizationname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_organizationname_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.OrganizationName; +import com.google.cloud.orgpolicy.v2.Policy; + +public class SyncListPoliciesOrganizationname { + + public static void main(String[] args) throws Exception { + syncListPoliciesOrganizationname(); + } + + public static void syncListPoliciesOrganizationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_organizationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesProjectname.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesProjectname.java new file mode 100644 index 0000000..98c490d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesProjectname.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_projectname_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncListPoliciesProjectname { + + public static void main(String[] args) throws Exception { + syncListPoliciesProjectname(); + } + + public static void syncListPoliciesProjectname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + ProjectName parent = ProjectName.of("[PROJECT]"); + for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_projectname_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesString.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesString.java new file mode 100644 index 0000000..355ce72 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/listpolicies/SyncListPoliciesString.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_listpolicies_string_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.ProjectName; + +public class SyncListPoliciesString { + + public static void main(String[] args) throws Exception { + syncListPoliciesString(); + } + + public static void syncListPoliciesString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + String parent = ProjectName.of("[PROJECT]").toString(); + for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_listpolicies_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/AsyncUpdatePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/AsyncUpdatePolicy.java new file mode 100644 index 0000000..8ef22dd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/AsyncUpdatePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_updatepolicy_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.UpdatePolicyRequest; + +public class AsyncUpdatePolicy { + + public static void main(String[] args) throws Exception { + asyncUpdatePolicy(); + } + + public static void asyncUpdatePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + UpdatePolicyRequest request = + UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build(); + ApiFuture future = orgPolicyClient.updatePolicyCallable().futureCall(request); + // Do something. + Policy response = future.get(); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_updatepolicy_async] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicy.java new file mode 100644 index 0000000..bbbb23a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_updatepolicy_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; +import com.google.cloud.orgpolicy.v2.UpdatePolicyRequest; + +public class SyncUpdatePolicy { + + public static void main(String[] args) throws Exception { + syncUpdatePolicy(); + } + + public static void syncUpdatePolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + UpdatePolicyRequest request = + UpdatePolicyRequest.newBuilder().setPolicy(Policy.newBuilder().build()).build(); + Policy response = orgPolicyClient.updatePolicy(request); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_updatepolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicyPolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicyPolicy.java new file mode 100644 index 0000000..184b69d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicyclient/updatepolicy/SyncUpdatePolicyPolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicyclient_updatepolicy_policy_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicyClient; +import com.google.cloud.orgpolicy.v2.Policy; + +public class SyncUpdatePolicyPolicy { + + public static void main(String[] args) throws Exception { + syncUpdatePolicyPolicy(); + } + + public static void syncUpdatePolicyPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { + Policy policy = Policy.newBuilder().build(); + Policy response = orgPolicyClient.updatePolicy(policy); + } + } +} +// [END orgpolicy_v2_generated_orgpolicyclient_updatepolicy_policy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicysettings/getpolicy/SyncGetPolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicysettings/getpolicy/SyncGetPolicy.java new file mode 100644 index 0000000..0c1c51c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/orgpolicysettings/getpolicy/SyncGetPolicy.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.orgpolicy.v2.samples; + +// [START orgpolicy_v2_generated_orgpolicysettings_getpolicy_sync] +import com.google.cloud.orgpolicy.v2.OrgPolicySettings; +import java.time.Duration; + +public class SyncGetPolicy { + + public static void main(String[] args) throws Exception { + syncGetPolicy(); + } + + public static void syncGetPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + OrgPolicySettings.Builder orgPolicySettingsBuilder = OrgPolicySettings.newBuilder(); + orgPolicySettingsBuilder + .getPolicySettings() + .setRetrySettings( + orgPolicySettingsBuilder + .getPolicySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + OrgPolicySettings orgPolicySettings = orgPolicySettingsBuilder.build(); + } +} +// [END orgpolicy_v2_generated_orgpolicysettings_getpolicy_sync] diff --git a/samples/snippets/generated/com/google/cloud/orgpolicy/v2/stub/orgpolicystubsettings/getpolicy/SyncGetPolicy.java b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/stub/orgpolicystubsettings/getpolicy/SyncGetPolicy.java new file mode 100644 index 0000000..618e1c7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/orgpolicy/v2/stub/orgpolicystubsettings/getpolicy/SyncGetPolicy.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.orgpolicy.v2.stub.samples; + +// [START orgpolicy_v2_generated_orgpolicystubsettings_getpolicy_sync] +import com.google.cloud.orgpolicy.v2.stub.OrgPolicyStubSettings; +import java.time.Duration; + +public class SyncGetPolicy { + + public static void main(String[] args) throws Exception { + syncGetPolicy(); + } + + public static void syncGetPolicy() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + OrgPolicyStubSettings.Builder orgPolicySettingsBuilder = OrgPolicyStubSettings.newBuilder(); + orgPolicySettingsBuilder + .getPolicySettings() + .setRetrySettings( + orgPolicySettingsBuilder + .getPolicySettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + OrgPolicyStubSettings orgPolicySettings = orgPolicySettingsBuilder.build(); + } +} +// [END orgpolicy_v2_generated_orgpolicystubsettings_getpolicy_sync]