1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.orgpolicy.v2; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.gax.core.BackgroundResource; 22 import com.google.api.gax.paging.AbstractFixedSizeCollection; 23 import com.google.api.gax.paging.AbstractPage; 24 import com.google.api.gax.paging.AbstractPagedListResponse; 25 import com.google.api.gax.rpc.PageContext; 26 import com.google.api.gax.rpc.UnaryCallable; 27 import com.google.cloud.orgpolicy.v2.stub.OrgPolicyStub; 28 import com.google.cloud.orgpolicy.v2.stub.OrgPolicyStubSettings; 29 import com.google.common.util.concurrent.MoreExecutors; 30 import com.google.protobuf.Empty; 31 import java.io.IOException; 32 import java.util.List; 33 import java.util.concurrent.TimeUnit; 34 import javax.annotation.Generated; 35 36 // AUTO-GENERATED DOCUMENTATION AND CLASS. 37 /** 38 * Service Description: An interface for managing organization policies. 39 * 40 * <p>The Cloud Org Policy service provides a simple mechanism for organizations to restrict the 41 * allowed configurations across their entire Cloud Resource hierarchy. 42 * 43 * <p>You can use a `policy` to configure restrictions in Cloud resources. For example, you can 44 * enforce a `policy` that restricts which Google Cloud Platform APIs can be activated in a certain 45 * part of your resource hierarchy, or prevents serial port access to VM instances in a particular 46 * folder. 47 * 48 * <p>`Policies` are inherited down through the resource hierarchy. A `policy` applied to a parent 49 * resource automatically applies to all its child resources unless overridden with a `policy` lower 50 * in the hierarchy. 51 * 52 * <p>A `constraint` defines an aspect of a resource's configuration that can be controlled by an 53 * organization's policy administrator. `Policies` are a collection of `constraints` that defines 54 * their allowable configuration on a particular resource and its child resources. 55 * 56 * <p>This class provides the ability to make remote calls to the backing service through method 57 * calls that map to API methods. Sample code to get started: 58 * 59 * <pre>{@code 60 * // This snippet has been automatically generated and should be regarded as a code template only. 61 * // It will require modifications to work: 62 * // - It may require correct/in-range values for request initialization. 63 * // - It may require specifying regional endpoints when creating the service client as shown in 64 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 65 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 66 * PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); 67 * Policy response = orgPolicyClient.getPolicy(name); 68 * } 69 * }</pre> 70 * 71 * <p>Note: close() needs to be called on the OrgPolicyClient object to clean up resources such as 72 * threads. In the example above, try-with-resources is used, which automatically calls close(). 73 * 74 * <p>The surface of this class includes several types of Java methods for each of the API's 75 * methods: 76 * 77 * <ol> 78 * <li>A "flattened" method. With this type of method, the fields of the request type have been 79 * converted into function parameters. It may be the case that not all fields are available as 80 * parameters, and not every API method will have a flattened method entry point. 81 * <li>A "request object" method. This type of method only takes one parameter, a request object, 82 * which must be constructed before the call. Not every API method will have a request object 83 * method. 84 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 85 * callable object, which can be used to initiate calls to the service. 86 * </ol> 87 * 88 * <p>See the individual methods for example code. 89 * 90 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 91 * these names, this class includes a format method for each type of name, and additionally a parse 92 * method to extract the individual identifiers contained within names that are returned. 93 * 94 * <p>This class can be customized by passing in a custom instance of OrgPolicySettings to create(). 95 * For example: 96 * 97 * <p>To customize credentials: 98 * 99 * <pre>{@code 100 * // This snippet has been automatically generated and should be regarded as a code template only. 101 * // It will require modifications to work: 102 * // - It may require correct/in-range values for request initialization. 103 * // - It may require specifying regional endpoints when creating the service client as shown in 104 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 105 * OrgPolicySettings orgPolicySettings = 106 * OrgPolicySettings.newBuilder() 107 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 108 * .build(); 109 * OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); 110 * }</pre> 111 * 112 * <p>To customize the endpoint: 113 * 114 * <pre>{@code 115 * // This snippet has been automatically generated and should be regarded as a code template only. 116 * // It will require modifications to work: 117 * // - It may require correct/in-range values for request initialization. 118 * // - It may require specifying regional endpoints when creating the service client as shown in 119 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 120 * OrgPolicySettings orgPolicySettings = 121 * OrgPolicySettings.newBuilder().setEndpoint(myEndpoint).build(); 122 * OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); 123 * }</pre> 124 * 125 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 126 * the wire: 127 * 128 * <pre>{@code 129 * // This snippet has been automatically generated and should be regarded as a code template only. 130 * // It will require modifications to work: 131 * // - It may require correct/in-range values for request initialization. 132 * // - It may require specifying regional endpoints when creating the service client as shown in 133 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 134 * OrgPolicySettings orgPolicySettings = OrgPolicySettings.newHttpJsonBuilder().build(); 135 * OrgPolicyClient orgPolicyClient = OrgPolicyClient.create(orgPolicySettings); 136 * }</pre> 137 * 138 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 139 */ 140 @Generated("by gapic-generator-java") 141 public class OrgPolicyClient implements BackgroundResource { 142 private final OrgPolicySettings settings; 143 private final OrgPolicyStub stub; 144 145 /** Constructs an instance of OrgPolicyClient with default settings. */ create()146 public static final OrgPolicyClient create() throws IOException { 147 return create(OrgPolicySettings.newBuilder().build()); 148 } 149 150 /** 151 * Constructs an instance of OrgPolicyClient, using the given settings. The channels are created 152 * based on the settings passed in, or defaults for any settings that are not set. 153 */ create(OrgPolicySettings settings)154 public static final OrgPolicyClient create(OrgPolicySettings settings) throws IOException { 155 return new OrgPolicyClient(settings); 156 } 157 158 /** 159 * Constructs an instance of OrgPolicyClient, using the given stub for making calls. This is for 160 * advanced usage - prefer using create(OrgPolicySettings). 161 */ create(OrgPolicyStub stub)162 public static final OrgPolicyClient create(OrgPolicyStub stub) { 163 return new OrgPolicyClient(stub); 164 } 165 166 /** 167 * Constructs an instance of OrgPolicyClient, using the given settings. This is protected so that 168 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 169 */ OrgPolicyClient(OrgPolicySettings settings)170 protected OrgPolicyClient(OrgPolicySettings settings) throws IOException { 171 this.settings = settings; 172 this.stub = ((OrgPolicyStubSettings) settings.getStubSettings()).createStub(); 173 } 174 OrgPolicyClient(OrgPolicyStub stub)175 protected OrgPolicyClient(OrgPolicyStub stub) { 176 this.settings = null; 177 this.stub = stub; 178 } 179 getSettings()180 public final OrgPolicySettings getSettings() { 181 return settings; 182 } 183 getStub()184 public OrgPolicyStub getStub() { 185 return stub; 186 } 187 188 // AUTO-GENERATED DOCUMENTATION AND METHOD. 189 /** 190 * Lists `Constraints` that could be applied on the specified resource. 191 * 192 * <p>Sample code: 193 * 194 * <pre>{@code 195 * // This snippet has been automatically generated and should be regarded as a code template only. 196 * // It will require modifications to work: 197 * // - It may require correct/in-range values for request initialization. 198 * // - It may require specifying regional endpoints when creating the service client as shown in 199 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 200 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 201 * FolderName parent = FolderName.of("[FOLDER]"); 202 * for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { 203 * // doThingsWith(element); 204 * } 205 * } 206 * }</pre> 207 * 208 * @param parent Required. The Cloud resource that parents the constraint. Must be in one of the 209 * following forms: 210 * <ul> 211 * <li>`projects/{project_number}` 212 * <li>`projects/{project_id}` 213 * <li>`folders/{folder_id}` 214 * <li>`organizations/{organization_id}` 215 * </ul> 216 * 217 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 218 */ listConstraints(FolderName parent)219 public final ListConstraintsPagedResponse listConstraints(FolderName parent) { 220 ListConstraintsRequest request = 221 ListConstraintsRequest.newBuilder() 222 .setParent(parent == null ? null : parent.toString()) 223 .build(); 224 return listConstraints(request); 225 } 226 227 // AUTO-GENERATED DOCUMENTATION AND METHOD. 228 /** 229 * Lists `Constraints` that could be applied on the specified resource. 230 * 231 * <p>Sample code: 232 * 233 * <pre>{@code 234 * // This snippet has been automatically generated and should be regarded as a code template only. 235 * // It will require modifications to work: 236 * // - It may require correct/in-range values for request initialization. 237 * // - It may require specifying regional endpoints when creating the service client as shown in 238 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 239 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 240 * OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 241 * for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { 242 * // doThingsWith(element); 243 * } 244 * } 245 * }</pre> 246 * 247 * @param parent Required. The Cloud resource that parents the constraint. Must be in one of the 248 * following forms: 249 * <ul> 250 * <li>`projects/{project_number}` 251 * <li>`projects/{project_id}` 252 * <li>`folders/{folder_id}` 253 * <li>`organizations/{organization_id}` 254 * </ul> 255 * 256 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 257 */ listConstraints(OrganizationName parent)258 public final ListConstraintsPagedResponse listConstraints(OrganizationName parent) { 259 ListConstraintsRequest request = 260 ListConstraintsRequest.newBuilder() 261 .setParent(parent == null ? null : parent.toString()) 262 .build(); 263 return listConstraints(request); 264 } 265 266 // AUTO-GENERATED DOCUMENTATION AND METHOD. 267 /** 268 * Lists `Constraints` that could be applied on the specified resource. 269 * 270 * <p>Sample code: 271 * 272 * <pre>{@code 273 * // This snippet has been automatically generated and should be regarded as a code template only. 274 * // It will require modifications to work: 275 * // - It may require correct/in-range values for request initialization. 276 * // - It may require specifying regional endpoints when creating the service client as shown in 277 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 278 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 279 * ProjectName parent = ProjectName.of("[PROJECT]"); 280 * for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { 281 * // doThingsWith(element); 282 * } 283 * } 284 * }</pre> 285 * 286 * @param parent Required. The Cloud resource that parents the constraint. Must be in one of the 287 * following forms: 288 * <ul> 289 * <li>`projects/{project_number}` 290 * <li>`projects/{project_id}` 291 * <li>`folders/{folder_id}` 292 * <li>`organizations/{organization_id}` 293 * </ul> 294 * 295 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 296 */ listConstraints(ProjectName parent)297 public final ListConstraintsPagedResponse listConstraints(ProjectName parent) { 298 ListConstraintsRequest request = 299 ListConstraintsRequest.newBuilder() 300 .setParent(parent == null ? null : parent.toString()) 301 .build(); 302 return listConstraints(request); 303 } 304 305 // AUTO-GENERATED DOCUMENTATION AND METHOD. 306 /** 307 * Lists `Constraints` that could be applied on the specified resource. 308 * 309 * <p>Sample code: 310 * 311 * <pre>{@code 312 * // This snippet has been automatically generated and should be regarded as a code template only. 313 * // It will require modifications to work: 314 * // - It may require correct/in-range values for request initialization. 315 * // - It may require specifying regional endpoints when creating the service client as shown in 316 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 317 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 318 * String parent = ProjectName.of("[PROJECT]").toString(); 319 * for (Constraint element : orgPolicyClient.listConstraints(parent).iterateAll()) { 320 * // doThingsWith(element); 321 * } 322 * } 323 * }</pre> 324 * 325 * @param parent Required. The Cloud resource that parents the constraint. Must be in one of the 326 * following forms: 327 * <ul> 328 * <li>`projects/{project_number}` 329 * <li>`projects/{project_id}` 330 * <li>`folders/{folder_id}` 331 * <li>`organizations/{organization_id}` 332 * </ul> 333 * 334 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 335 */ listConstraints(String parent)336 public final ListConstraintsPagedResponse listConstraints(String parent) { 337 ListConstraintsRequest request = ListConstraintsRequest.newBuilder().setParent(parent).build(); 338 return listConstraints(request); 339 } 340 341 // AUTO-GENERATED DOCUMENTATION AND METHOD. 342 /** 343 * Lists `Constraints` that could be applied on the specified resource. 344 * 345 * <p>Sample code: 346 * 347 * <pre>{@code 348 * // This snippet has been automatically generated and should be regarded as a code template only. 349 * // It will require modifications to work: 350 * // - It may require correct/in-range values for request initialization. 351 * // - It may require specifying regional endpoints when creating the service client as shown in 352 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 353 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 354 * ListConstraintsRequest request = 355 * ListConstraintsRequest.newBuilder() 356 * .setParent(ProjectName.of("[PROJECT]").toString()) 357 * .setPageSize(883849137) 358 * .setPageToken("pageToken873572522") 359 * .build(); 360 * for (Constraint element : orgPolicyClient.listConstraints(request).iterateAll()) { 361 * // doThingsWith(element); 362 * } 363 * } 364 * }</pre> 365 * 366 * @param request The request object containing all of the parameters for the API call. 367 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 368 */ listConstraints(ListConstraintsRequest request)369 public final ListConstraintsPagedResponse listConstraints(ListConstraintsRequest request) { 370 return listConstraintsPagedCallable().call(request); 371 } 372 373 // AUTO-GENERATED DOCUMENTATION AND METHOD. 374 /** 375 * Lists `Constraints` that could be applied on the specified resource. 376 * 377 * <p>Sample code: 378 * 379 * <pre>{@code 380 * // This snippet has been automatically generated and should be regarded as a code template only. 381 * // It will require modifications to work: 382 * // - It may require correct/in-range values for request initialization. 383 * // - It may require specifying regional endpoints when creating the service client as shown in 384 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 385 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 386 * ListConstraintsRequest request = 387 * ListConstraintsRequest.newBuilder() 388 * .setParent(ProjectName.of("[PROJECT]").toString()) 389 * .setPageSize(883849137) 390 * .setPageToken("pageToken873572522") 391 * .build(); 392 * ApiFuture<Constraint> future = 393 * orgPolicyClient.listConstraintsPagedCallable().futureCall(request); 394 * // Do something. 395 * for (Constraint element : future.get().iterateAll()) { 396 * // doThingsWith(element); 397 * } 398 * } 399 * }</pre> 400 */ 401 public final UnaryCallable<ListConstraintsRequest, ListConstraintsPagedResponse> listConstraintsPagedCallable()402 listConstraintsPagedCallable() { 403 return stub.listConstraintsPagedCallable(); 404 } 405 406 // AUTO-GENERATED DOCUMENTATION AND METHOD. 407 /** 408 * Lists `Constraints` that could be applied on the specified resource. 409 * 410 * <p>Sample code: 411 * 412 * <pre>{@code 413 * // This snippet has been automatically generated and should be regarded as a code template only. 414 * // It will require modifications to work: 415 * // - It may require correct/in-range values for request initialization. 416 * // - It may require specifying regional endpoints when creating the service client as shown in 417 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 418 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 419 * ListConstraintsRequest request = 420 * ListConstraintsRequest.newBuilder() 421 * .setParent(ProjectName.of("[PROJECT]").toString()) 422 * .setPageSize(883849137) 423 * .setPageToken("pageToken873572522") 424 * .build(); 425 * while (true) { 426 * ListConstraintsResponse response = orgPolicyClient.listConstraintsCallable().call(request); 427 * for (Constraint element : response.getConstraintsList()) { 428 * // doThingsWith(element); 429 * } 430 * String nextPageToken = response.getNextPageToken(); 431 * if (!Strings.isNullOrEmpty(nextPageToken)) { 432 * request = request.toBuilder().setPageToken(nextPageToken).build(); 433 * } else { 434 * break; 435 * } 436 * } 437 * } 438 * }</pre> 439 */ 440 public final UnaryCallable<ListConstraintsRequest, ListConstraintsResponse> listConstraintsCallable()441 listConstraintsCallable() { 442 return stub.listConstraintsCallable(); 443 } 444 445 // AUTO-GENERATED DOCUMENTATION AND METHOD. 446 /** 447 * Retrieves all of the `Policies` that exist on a particular resource. 448 * 449 * <p>Sample code: 450 * 451 * <pre>{@code 452 * // This snippet has been automatically generated and should be regarded as a code template only. 453 * // It will require modifications to work: 454 * // - It may require correct/in-range values for request initialization. 455 * // - It may require specifying regional endpoints when creating the service client as shown in 456 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 457 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 458 * FolderName parent = FolderName.of("[FOLDER]"); 459 * for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { 460 * // doThingsWith(element); 461 * } 462 * } 463 * }</pre> 464 * 465 * @param parent Required. The target Cloud resource that parents the set of constraints and 466 * policies that will be returned from this call. Must be in one of the following forms: 467 * <ul> 468 * <li>`projects/{project_number}` 469 * <li>`projects/{project_id}` 470 * <li>`folders/{folder_id}` 471 * <li>`organizations/{organization_id}` 472 * </ul> 473 * 474 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 475 */ listPolicies(FolderName parent)476 public final ListPoliciesPagedResponse listPolicies(FolderName parent) { 477 ListPoliciesRequest request = 478 ListPoliciesRequest.newBuilder() 479 .setParent(parent == null ? null : parent.toString()) 480 .build(); 481 return listPolicies(request); 482 } 483 484 // AUTO-GENERATED DOCUMENTATION AND METHOD. 485 /** 486 * Retrieves all of the `Policies` that exist on a particular resource. 487 * 488 * <p>Sample code: 489 * 490 * <pre>{@code 491 * // This snippet has been automatically generated and should be regarded as a code template only. 492 * // It will require modifications to work: 493 * // - It may require correct/in-range values for request initialization. 494 * // - It may require specifying regional endpoints when creating the service client as shown in 495 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 496 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 497 * OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 498 * for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { 499 * // doThingsWith(element); 500 * } 501 * } 502 * }</pre> 503 * 504 * @param parent Required. The target Cloud resource that parents the set of constraints and 505 * policies that will be returned from this call. Must be in one of the following forms: 506 * <ul> 507 * <li>`projects/{project_number}` 508 * <li>`projects/{project_id}` 509 * <li>`folders/{folder_id}` 510 * <li>`organizations/{organization_id}` 511 * </ul> 512 * 513 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 514 */ listPolicies(OrganizationName parent)515 public final ListPoliciesPagedResponse listPolicies(OrganizationName parent) { 516 ListPoliciesRequest request = 517 ListPoliciesRequest.newBuilder() 518 .setParent(parent == null ? null : parent.toString()) 519 .build(); 520 return listPolicies(request); 521 } 522 523 // AUTO-GENERATED DOCUMENTATION AND METHOD. 524 /** 525 * Retrieves all of the `Policies` that exist on a particular resource. 526 * 527 * <p>Sample code: 528 * 529 * <pre>{@code 530 * // This snippet has been automatically generated and should be regarded as a code template only. 531 * // It will require modifications to work: 532 * // - It may require correct/in-range values for request initialization. 533 * // - It may require specifying regional endpoints when creating the service client as shown in 534 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 535 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 536 * ProjectName parent = ProjectName.of("[PROJECT]"); 537 * for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { 538 * // doThingsWith(element); 539 * } 540 * } 541 * }</pre> 542 * 543 * @param parent Required. The target Cloud resource that parents the set of constraints and 544 * policies that will be returned from this call. Must be in one of the following forms: 545 * <ul> 546 * <li>`projects/{project_number}` 547 * <li>`projects/{project_id}` 548 * <li>`folders/{folder_id}` 549 * <li>`organizations/{organization_id}` 550 * </ul> 551 * 552 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 553 */ listPolicies(ProjectName parent)554 public final ListPoliciesPagedResponse listPolicies(ProjectName parent) { 555 ListPoliciesRequest request = 556 ListPoliciesRequest.newBuilder() 557 .setParent(parent == null ? null : parent.toString()) 558 .build(); 559 return listPolicies(request); 560 } 561 562 // AUTO-GENERATED DOCUMENTATION AND METHOD. 563 /** 564 * Retrieves all of the `Policies` that exist on a particular resource. 565 * 566 * <p>Sample code: 567 * 568 * <pre>{@code 569 * // This snippet has been automatically generated and should be regarded as a code template only. 570 * // It will require modifications to work: 571 * // - It may require correct/in-range values for request initialization. 572 * // - It may require specifying regional endpoints when creating the service client as shown in 573 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 574 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 575 * String parent = ProjectName.of("[PROJECT]").toString(); 576 * for (Policy element : orgPolicyClient.listPolicies(parent).iterateAll()) { 577 * // doThingsWith(element); 578 * } 579 * } 580 * }</pre> 581 * 582 * @param parent Required. The target Cloud resource that parents the set of constraints and 583 * policies that will be returned from this call. Must be in one of the following forms: 584 * <ul> 585 * <li>`projects/{project_number}` 586 * <li>`projects/{project_id}` 587 * <li>`folders/{folder_id}` 588 * <li>`organizations/{organization_id}` 589 * </ul> 590 * 591 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 592 */ listPolicies(String parent)593 public final ListPoliciesPagedResponse listPolicies(String parent) { 594 ListPoliciesRequest request = ListPoliciesRequest.newBuilder().setParent(parent).build(); 595 return listPolicies(request); 596 } 597 598 // AUTO-GENERATED DOCUMENTATION AND METHOD. 599 /** 600 * Retrieves all of the `Policies` that exist on a particular resource. 601 * 602 * <p>Sample code: 603 * 604 * <pre>{@code 605 * // This snippet has been automatically generated and should be regarded as a code template only. 606 * // It will require modifications to work: 607 * // - It may require correct/in-range values for request initialization. 608 * // - It may require specifying regional endpoints when creating the service client as shown in 609 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 610 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 611 * ListPoliciesRequest request = 612 * ListPoliciesRequest.newBuilder() 613 * .setParent(ProjectName.of("[PROJECT]").toString()) 614 * .setPageSize(883849137) 615 * .setPageToken("pageToken873572522") 616 * .build(); 617 * for (Policy element : orgPolicyClient.listPolicies(request).iterateAll()) { 618 * // doThingsWith(element); 619 * } 620 * } 621 * }</pre> 622 * 623 * @param request The request object containing all of the parameters for the API call. 624 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 625 */ listPolicies(ListPoliciesRequest request)626 public final ListPoliciesPagedResponse listPolicies(ListPoliciesRequest request) { 627 return listPoliciesPagedCallable().call(request); 628 } 629 630 // AUTO-GENERATED DOCUMENTATION AND METHOD. 631 /** 632 * Retrieves all of the `Policies` that exist on a particular resource. 633 * 634 * <p>Sample code: 635 * 636 * <pre>{@code 637 * // This snippet has been automatically generated and should be regarded as a code template only. 638 * // It will require modifications to work: 639 * // - It may require correct/in-range values for request initialization. 640 * // - It may require specifying regional endpoints when creating the service client as shown in 641 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 642 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 643 * ListPoliciesRequest request = 644 * ListPoliciesRequest.newBuilder() 645 * .setParent(ProjectName.of("[PROJECT]").toString()) 646 * .setPageSize(883849137) 647 * .setPageToken("pageToken873572522") 648 * .build(); 649 * ApiFuture<Policy> future = orgPolicyClient.listPoliciesPagedCallable().futureCall(request); 650 * // Do something. 651 * for (Policy element : future.get().iterateAll()) { 652 * // doThingsWith(element); 653 * } 654 * } 655 * }</pre> 656 */ 657 public final UnaryCallable<ListPoliciesRequest, ListPoliciesPagedResponse> listPoliciesPagedCallable()658 listPoliciesPagedCallable() { 659 return stub.listPoliciesPagedCallable(); 660 } 661 662 // AUTO-GENERATED DOCUMENTATION AND METHOD. 663 /** 664 * Retrieves all of the `Policies` that exist on a particular resource. 665 * 666 * <p>Sample code: 667 * 668 * <pre>{@code 669 * // This snippet has been automatically generated and should be regarded as a code template only. 670 * // It will require modifications to work: 671 * // - It may require correct/in-range values for request initialization. 672 * // - It may require specifying regional endpoints when creating the service client as shown in 673 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 674 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 675 * ListPoliciesRequest request = 676 * ListPoliciesRequest.newBuilder() 677 * .setParent(ProjectName.of("[PROJECT]").toString()) 678 * .setPageSize(883849137) 679 * .setPageToken("pageToken873572522") 680 * .build(); 681 * while (true) { 682 * ListPoliciesResponse response = orgPolicyClient.listPoliciesCallable().call(request); 683 * for (Policy element : response.getPoliciesList()) { 684 * // doThingsWith(element); 685 * } 686 * String nextPageToken = response.getNextPageToken(); 687 * if (!Strings.isNullOrEmpty(nextPageToken)) { 688 * request = request.toBuilder().setPageToken(nextPageToken).build(); 689 * } else { 690 * break; 691 * } 692 * } 693 * } 694 * }</pre> 695 */ listPoliciesCallable()696 public final UnaryCallable<ListPoliciesRequest, ListPoliciesResponse> listPoliciesCallable() { 697 return stub.listPoliciesCallable(); 698 } 699 700 // AUTO-GENERATED DOCUMENTATION AND METHOD. 701 /** 702 * Gets a `Policy` on a resource. 703 * 704 * <p>If no `Policy` is set on the resource, NOT_FOUND is returned. The `etag` value can be used 705 * with `UpdatePolicy()` to update a `Policy` during read-modify-write. 706 * 707 * <p>Sample code: 708 * 709 * <pre>{@code 710 * // This snippet has been automatically generated and should be regarded as a code template only. 711 * // It will require modifications to work: 712 * // - It may require correct/in-range values for request initialization. 713 * // - It may require specifying regional endpoints when creating the service client as shown in 714 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 715 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 716 * PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); 717 * Policy response = orgPolicyClient.getPolicy(name); 718 * } 719 * }</pre> 720 * 721 * @param name Required. Resource name of the policy. See `Policy` for naming requirements. 722 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 723 */ getPolicy(PolicyName name)724 public final Policy getPolicy(PolicyName name) { 725 GetPolicyRequest request = 726 GetPolicyRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 727 return getPolicy(request); 728 } 729 730 // AUTO-GENERATED DOCUMENTATION AND METHOD. 731 /** 732 * Gets a `Policy` on a resource. 733 * 734 * <p>If no `Policy` is set on the resource, NOT_FOUND is returned. The `etag` value can be used 735 * with `UpdatePolicy()` to update a `Policy` during read-modify-write. 736 * 737 * <p>Sample code: 738 * 739 * <pre>{@code 740 * // This snippet has been automatically generated and should be regarded as a code template only. 741 * // It will require modifications to work: 742 * // - It may require correct/in-range values for request initialization. 743 * // - It may require specifying regional endpoints when creating the service client as shown in 744 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 745 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 746 * String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString(); 747 * Policy response = orgPolicyClient.getPolicy(name); 748 * } 749 * }</pre> 750 * 751 * @param name Required. Resource name of the policy. See `Policy` for naming requirements. 752 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 753 */ getPolicy(String name)754 public final Policy getPolicy(String name) { 755 GetPolicyRequest request = GetPolicyRequest.newBuilder().setName(name).build(); 756 return getPolicy(request); 757 } 758 759 // AUTO-GENERATED DOCUMENTATION AND METHOD. 760 /** 761 * Gets a `Policy` on a resource. 762 * 763 * <p>If no `Policy` is set on the resource, NOT_FOUND is returned. The `etag` value can be used 764 * with `UpdatePolicy()` to update a `Policy` during read-modify-write. 765 * 766 * <p>Sample code: 767 * 768 * <pre>{@code 769 * // This snippet has been automatically generated and should be regarded as a code template only. 770 * // It will require modifications to work: 771 * // - It may require correct/in-range values for request initialization. 772 * // - It may require specifying regional endpoints when creating the service client as shown in 773 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 774 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 775 * GetPolicyRequest request = 776 * GetPolicyRequest.newBuilder() 777 * .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) 778 * .build(); 779 * Policy response = orgPolicyClient.getPolicy(request); 780 * } 781 * }</pre> 782 * 783 * @param request The request object containing all of the parameters for the API call. 784 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 785 */ getPolicy(GetPolicyRequest request)786 public final Policy getPolicy(GetPolicyRequest request) { 787 return getPolicyCallable().call(request); 788 } 789 790 // AUTO-GENERATED DOCUMENTATION AND METHOD. 791 /** 792 * Gets a `Policy` on a resource. 793 * 794 * <p>If no `Policy` is set on the resource, NOT_FOUND is returned. The `etag` value can be used 795 * with `UpdatePolicy()` to update a `Policy` during read-modify-write. 796 * 797 * <p>Sample code: 798 * 799 * <pre>{@code 800 * // This snippet has been automatically generated and should be regarded as a code template only. 801 * // It will require modifications to work: 802 * // - It may require correct/in-range values for request initialization. 803 * // - It may require specifying regional endpoints when creating the service client as shown in 804 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 805 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 806 * GetPolicyRequest request = 807 * GetPolicyRequest.newBuilder() 808 * .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) 809 * .build(); 810 * ApiFuture<Policy> future = orgPolicyClient.getPolicyCallable().futureCall(request); 811 * // Do something. 812 * Policy response = future.get(); 813 * } 814 * }</pre> 815 */ getPolicyCallable()816 public final UnaryCallable<GetPolicyRequest, Policy> getPolicyCallable() { 817 return stub.getPolicyCallable(); 818 } 819 820 // AUTO-GENERATED DOCUMENTATION AND METHOD. 821 /** 822 * Gets the effective `Policy` on a resource. This is the result of merging `Policies` in the 823 * resource hierarchy and evaluating conditions. The returned `Policy` will not have an `etag` or 824 * `condition` set because it is a computed `Policy` across multiple resources. Subtrees of 825 * Resource Manager resource hierarchy with 'under:' prefix will not be expanded. 826 * 827 * <p>Sample code: 828 * 829 * <pre>{@code 830 * // This snippet has been automatically generated and should be regarded as a code template only. 831 * // It will require modifications to work: 832 * // - It may require correct/in-range values for request initialization. 833 * // - It may require specifying regional endpoints when creating the service client as shown in 834 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 835 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 836 * PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); 837 * Policy response = orgPolicyClient.getEffectivePolicy(name); 838 * } 839 * }</pre> 840 * 841 * @param name Required. The effective policy to compute. See `Policy` for naming rules. 842 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 843 */ getEffectivePolicy(PolicyName name)844 public final Policy getEffectivePolicy(PolicyName name) { 845 GetEffectivePolicyRequest request = 846 GetEffectivePolicyRequest.newBuilder() 847 .setName(name == null ? null : name.toString()) 848 .build(); 849 return getEffectivePolicy(request); 850 } 851 852 // AUTO-GENERATED DOCUMENTATION AND METHOD. 853 /** 854 * Gets the effective `Policy` on a resource. This is the result of merging `Policies` in the 855 * resource hierarchy and evaluating conditions. The returned `Policy` will not have an `etag` or 856 * `condition` set because it is a computed `Policy` across multiple resources. Subtrees of 857 * Resource Manager resource hierarchy with 'under:' prefix will not be expanded. 858 * 859 * <p>Sample code: 860 * 861 * <pre>{@code 862 * // This snippet has been automatically generated and should be regarded as a code template only. 863 * // It will require modifications to work: 864 * // - It may require correct/in-range values for request initialization. 865 * // - It may require specifying regional endpoints when creating the service client as shown in 866 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 867 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 868 * String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString(); 869 * Policy response = orgPolicyClient.getEffectivePolicy(name); 870 * } 871 * }</pre> 872 * 873 * @param name Required. The effective policy to compute. See `Policy` for naming rules. 874 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 875 */ getEffectivePolicy(String name)876 public final Policy getEffectivePolicy(String name) { 877 GetEffectivePolicyRequest request = 878 GetEffectivePolicyRequest.newBuilder().setName(name).build(); 879 return getEffectivePolicy(request); 880 } 881 882 // AUTO-GENERATED DOCUMENTATION AND METHOD. 883 /** 884 * Gets the effective `Policy` on a resource. This is the result of merging `Policies` in the 885 * resource hierarchy and evaluating conditions. The returned `Policy` will not have an `etag` or 886 * `condition` set because it is a computed `Policy` across multiple resources. Subtrees of 887 * Resource Manager resource hierarchy with 'under:' prefix will not be expanded. 888 * 889 * <p>Sample code: 890 * 891 * <pre>{@code 892 * // This snippet has been automatically generated and should be regarded as a code template only. 893 * // It will require modifications to work: 894 * // - It may require correct/in-range values for request initialization. 895 * // - It may require specifying regional endpoints when creating the service client as shown in 896 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 897 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 898 * GetEffectivePolicyRequest request = 899 * GetEffectivePolicyRequest.newBuilder() 900 * .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) 901 * .build(); 902 * Policy response = orgPolicyClient.getEffectivePolicy(request); 903 * } 904 * }</pre> 905 * 906 * @param request The request object containing all of the parameters for the API call. 907 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 908 */ getEffectivePolicy(GetEffectivePolicyRequest request)909 public final Policy getEffectivePolicy(GetEffectivePolicyRequest request) { 910 return getEffectivePolicyCallable().call(request); 911 } 912 913 // AUTO-GENERATED DOCUMENTATION AND METHOD. 914 /** 915 * Gets the effective `Policy` on a resource. This is the result of merging `Policies` in the 916 * resource hierarchy and evaluating conditions. The returned `Policy` will not have an `etag` or 917 * `condition` set because it is a computed `Policy` across multiple resources. Subtrees of 918 * Resource Manager resource hierarchy with 'under:' prefix will not be expanded. 919 * 920 * <p>Sample code: 921 * 922 * <pre>{@code 923 * // This snippet has been automatically generated and should be regarded as a code template only. 924 * // It will require modifications to work: 925 * // - It may require correct/in-range values for request initialization. 926 * // - It may require specifying regional endpoints when creating the service client as shown in 927 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 928 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 929 * GetEffectivePolicyRequest request = 930 * GetEffectivePolicyRequest.newBuilder() 931 * .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) 932 * .build(); 933 * ApiFuture<Policy> future = orgPolicyClient.getEffectivePolicyCallable().futureCall(request); 934 * // Do something. 935 * Policy response = future.get(); 936 * } 937 * }</pre> 938 */ getEffectivePolicyCallable()939 public final UnaryCallable<GetEffectivePolicyRequest, Policy> getEffectivePolicyCallable() { 940 return stub.getEffectivePolicyCallable(); 941 } 942 943 // AUTO-GENERATED DOCUMENTATION AND METHOD. 944 /** 945 * Creates a Policy. 946 * 947 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not 948 * exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy 949 * already exists on the given Cloud resource. 950 * 951 * <p>Sample code: 952 * 953 * <pre>{@code 954 * // This snippet has been automatically generated and should be regarded as a code template only. 955 * // It will require modifications to work: 956 * // - It may require correct/in-range values for request initialization. 957 * // - It may require specifying regional endpoints when creating the service client as shown in 958 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 959 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 960 * FolderName parent = FolderName.of("[FOLDER]"); 961 * Policy policy = Policy.newBuilder().build(); 962 * Policy response = orgPolicyClient.createPolicy(parent, policy); 963 * } 964 * }</pre> 965 * 966 * @param parent Required. The Cloud resource that will parent the new Policy. Must be in one of 967 * the following forms: 968 * <ul> 969 * <li>`projects/{project_number}` 970 * <li>`projects/{project_id}` 971 * <li>`folders/{folder_id}` 972 * <li>`organizations/{organization_id}` 973 * </ul> 974 * 975 * @param policy Required. `Policy` to create. 976 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 977 */ createPolicy(FolderName parent, Policy policy)978 public final Policy createPolicy(FolderName parent, Policy policy) { 979 CreatePolicyRequest request = 980 CreatePolicyRequest.newBuilder() 981 .setParent(parent == null ? null : parent.toString()) 982 .setPolicy(policy) 983 .build(); 984 return createPolicy(request); 985 } 986 987 // AUTO-GENERATED DOCUMENTATION AND METHOD. 988 /** 989 * Creates a Policy. 990 * 991 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not 992 * exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy 993 * already exists on the given Cloud resource. 994 * 995 * <p>Sample code: 996 * 997 * <pre>{@code 998 * // This snippet has been automatically generated and should be regarded as a code template only. 999 * // It will require modifications to work: 1000 * // - It may require correct/in-range values for request initialization. 1001 * // - It may require specifying regional endpoints when creating the service client as shown in 1002 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1003 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1004 * OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); 1005 * Policy policy = Policy.newBuilder().build(); 1006 * Policy response = orgPolicyClient.createPolicy(parent, policy); 1007 * } 1008 * }</pre> 1009 * 1010 * @param parent Required. The Cloud resource that will parent the new Policy. Must be in one of 1011 * the following forms: 1012 * <ul> 1013 * <li>`projects/{project_number}` 1014 * <li>`projects/{project_id}` 1015 * <li>`folders/{folder_id}` 1016 * <li>`organizations/{organization_id}` 1017 * </ul> 1018 * 1019 * @param policy Required. `Policy` to create. 1020 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1021 */ createPolicy(OrganizationName parent, Policy policy)1022 public final Policy createPolicy(OrganizationName parent, Policy policy) { 1023 CreatePolicyRequest request = 1024 CreatePolicyRequest.newBuilder() 1025 .setParent(parent == null ? null : parent.toString()) 1026 .setPolicy(policy) 1027 .build(); 1028 return createPolicy(request); 1029 } 1030 1031 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1032 /** 1033 * Creates a Policy. 1034 * 1035 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not 1036 * exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy 1037 * already exists on the given Cloud resource. 1038 * 1039 * <p>Sample code: 1040 * 1041 * <pre>{@code 1042 * // This snippet has been automatically generated and should be regarded as a code template only. 1043 * // It will require modifications to work: 1044 * // - It may require correct/in-range values for request initialization. 1045 * // - It may require specifying regional endpoints when creating the service client as shown in 1046 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1047 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1048 * ProjectName parent = ProjectName.of("[PROJECT]"); 1049 * Policy policy = Policy.newBuilder().build(); 1050 * Policy response = orgPolicyClient.createPolicy(parent, policy); 1051 * } 1052 * }</pre> 1053 * 1054 * @param parent Required. The Cloud resource that will parent the new Policy. Must be in one of 1055 * the following forms: 1056 * <ul> 1057 * <li>`projects/{project_number}` 1058 * <li>`projects/{project_id}` 1059 * <li>`folders/{folder_id}` 1060 * <li>`organizations/{organization_id}` 1061 * </ul> 1062 * 1063 * @param policy Required. `Policy` to create. 1064 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1065 */ createPolicy(ProjectName parent, Policy policy)1066 public final Policy createPolicy(ProjectName parent, Policy policy) { 1067 CreatePolicyRequest request = 1068 CreatePolicyRequest.newBuilder() 1069 .setParent(parent == null ? null : parent.toString()) 1070 .setPolicy(policy) 1071 .build(); 1072 return createPolicy(request); 1073 } 1074 1075 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1076 /** 1077 * Creates a Policy. 1078 * 1079 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not 1080 * exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy 1081 * already exists on the given Cloud resource. 1082 * 1083 * <p>Sample code: 1084 * 1085 * <pre>{@code 1086 * // This snippet has been automatically generated and should be regarded as a code template only. 1087 * // It will require modifications to work: 1088 * // - It may require correct/in-range values for request initialization. 1089 * // - It may require specifying regional endpoints when creating the service client as shown in 1090 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1091 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1092 * String parent = ProjectName.of("[PROJECT]").toString(); 1093 * Policy policy = Policy.newBuilder().build(); 1094 * Policy response = orgPolicyClient.createPolicy(parent, policy); 1095 * } 1096 * }</pre> 1097 * 1098 * @param parent Required. The Cloud resource that will parent the new Policy. Must be in one of 1099 * the following forms: 1100 * <ul> 1101 * <li>`projects/{project_number}` 1102 * <li>`projects/{project_id}` 1103 * <li>`folders/{folder_id}` 1104 * <li>`organizations/{organization_id}` 1105 * </ul> 1106 * 1107 * @param policy Required. `Policy` to create. 1108 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1109 */ createPolicy(String parent, Policy policy)1110 public final Policy createPolicy(String parent, Policy policy) { 1111 CreatePolicyRequest request = 1112 CreatePolicyRequest.newBuilder().setParent(parent).setPolicy(policy).build(); 1113 return createPolicy(request); 1114 } 1115 1116 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1117 /** 1118 * Creates a Policy. 1119 * 1120 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not 1121 * exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy 1122 * already exists on the given Cloud resource. 1123 * 1124 * <p>Sample code: 1125 * 1126 * <pre>{@code 1127 * // This snippet has been automatically generated and should be regarded as a code template only. 1128 * // It will require modifications to work: 1129 * // - It may require correct/in-range values for request initialization. 1130 * // - It may require specifying regional endpoints when creating the service client as shown in 1131 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1132 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1133 * CreatePolicyRequest request = 1134 * CreatePolicyRequest.newBuilder() 1135 * .setParent(ProjectName.of("[PROJECT]").toString()) 1136 * .setPolicy(Policy.newBuilder().build()) 1137 * .build(); 1138 * Policy response = orgPolicyClient.createPolicy(request); 1139 * } 1140 * }</pre> 1141 * 1142 * @param request The request object containing all of the parameters for the API call. 1143 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1144 */ createPolicy(CreatePolicyRequest request)1145 public final Policy createPolicy(CreatePolicyRequest request) { 1146 return createPolicyCallable().call(request); 1147 } 1148 1149 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1150 /** 1151 * Creates a Policy. 1152 * 1153 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not 1154 * exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy 1155 * already exists on the given Cloud resource. 1156 * 1157 * <p>Sample code: 1158 * 1159 * <pre>{@code 1160 * // This snippet has been automatically generated and should be regarded as a code template only. 1161 * // It will require modifications to work: 1162 * // - It may require correct/in-range values for request initialization. 1163 * // - It may require specifying regional endpoints when creating the service client as shown in 1164 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1165 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1166 * CreatePolicyRequest request = 1167 * CreatePolicyRequest.newBuilder() 1168 * .setParent(ProjectName.of("[PROJECT]").toString()) 1169 * .setPolicy(Policy.newBuilder().build()) 1170 * .build(); 1171 * ApiFuture<Policy> future = orgPolicyClient.createPolicyCallable().futureCall(request); 1172 * // Do something. 1173 * Policy response = future.get(); 1174 * } 1175 * }</pre> 1176 */ createPolicyCallable()1177 public final UnaryCallable<CreatePolicyRequest, Policy> createPolicyCallable() { 1178 return stub.createPolicyCallable(); 1179 } 1180 1181 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1182 /** 1183 * Updates a Policy. 1184 * 1185 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the 1186 * policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag 1187 * supplied in the request does not match the persisted etag of the policy 1188 * 1189 * <p>Note: the supplied policy will perform a full overwrite of all fields. 1190 * 1191 * <p>Sample code: 1192 * 1193 * <pre>{@code 1194 * // This snippet has been automatically generated and should be regarded as a code template only. 1195 * // It will require modifications to work: 1196 * // - It may require correct/in-range values for request initialization. 1197 * // - It may require specifying regional endpoints when creating the service client as shown in 1198 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1199 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1200 * Policy policy = Policy.newBuilder().build(); 1201 * Policy response = orgPolicyClient.updatePolicy(policy); 1202 * } 1203 * }</pre> 1204 * 1205 * @param policy Required. `Policy` to update. 1206 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1207 */ updatePolicy(Policy policy)1208 public final Policy updatePolicy(Policy policy) { 1209 UpdatePolicyRequest request = UpdatePolicyRequest.newBuilder().setPolicy(policy).build(); 1210 return updatePolicy(request); 1211 } 1212 1213 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1214 /** 1215 * Updates a Policy. 1216 * 1217 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the 1218 * policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag 1219 * supplied in the request does not match the persisted etag of the policy 1220 * 1221 * <p>Note: the supplied policy will perform a full overwrite of all fields. 1222 * 1223 * <p>Sample code: 1224 * 1225 * <pre>{@code 1226 * // This snippet has been automatically generated and should be regarded as a code template only. 1227 * // It will require modifications to work: 1228 * // - It may require correct/in-range values for request initialization. 1229 * // - It may require specifying regional endpoints when creating the service client as shown in 1230 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1231 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1232 * UpdatePolicyRequest request = 1233 * UpdatePolicyRequest.newBuilder() 1234 * .setPolicy(Policy.newBuilder().build()) 1235 * .setUpdateMask(FieldMask.newBuilder().build()) 1236 * .build(); 1237 * Policy response = orgPolicyClient.updatePolicy(request); 1238 * } 1239 * }</pre> 1240 * 1241 * @param request The request object containing all of the parameters for the API call. 1242 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1243 */ updatePolicy(UpdatePolicyRequest request)1244 public final Policy updatePolicy(UpdatePolicyRequest request) { 1245 return updatePolicyCallable().call(request); 1246 } 1247 1248 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1249 /** 1250 * Updates a Policy. 1251 * 1252 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the 1253 * policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag 1254 * supplied in the request does not match the persisted etag of the policy 1255 * 1256 * <p>Note: the supplied policy will perform a full overwrite of all fields. 1257 * 1258 * <p>Sample code: 1259 * 1260 * <pre>{@code 1261 * // This snippet has been automatically generated and should be regarded as a code template only. 1262 * // It will require modifications to work: 1263 * // - It may require correct/in-range values for request initialization. 1264 * // - It may require specifying regional endpoints when creating the service client as shown in 1265 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1266 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1267 * UpdatePolicyRequest request = 1268 * UpdatePolicyRequest.newBuilder() 1269 * .setPolicy(Policy.newBuilder().build()) 1270 * .setUpdateMask(FieldMask.newBuilder().build()) 1271 * .build(); 1272 * ApiFuture<Policy> future = orgPolicyClient.updatePolicyCallable().futureCall(request); 1273 * // Do something. 1274 * Policy response = future.get(); 1275 * } 1276 * }</pre> 1277 */ updatePolicyCallable()1278 public final UnaryCallable<UpdatePolicyRequest, Policy> updatePolicyCallable() { 1279 return stub.updatePolicyCallable(); 1280 } 1281 1282 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1283 /** 1284 * Deletes a Policy. 1285 * 1286 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org 1287 * Policy does not exist. 1288 * 1289 * <p>Sample code: 1290 * 1291 * <pre>{@code 1292 * // This snippet has been automatically generated and should be regarded as a code template only. 1293 * // It will require modifications to work: 1294 * // - It may require correct/in-range values for request initialization. 1295 * // - It may require specifying regional endpoints when creating the service client as shown in 1296 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1297 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1298 * PolicyName name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]"); 1299 * orgPolicyClient.deletePolicy(name); 1300 * } 1301 * }</pre> 1302 * 1303 * @param name Required. Name of the policy to delete. See `Policy` for naming rules. 1304 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1305 */ deletePolicy(PolicyName name)1306 public final void deletePolicy(PolicyName name) { 1307 DeletePolicyRequest request = 1308 DeletePolicyRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 1309 deletePolicy(request); 1310 } 1311 1312 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1313 /** 1314 * Deletes a Policy. 1315 * 1316 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org 1317 * Policy does not exist. 1318 * 1319 * <p>Sample code: 1320 * 1321 * <pre>{@code 1322 * // This snippet has been automatically generated and should be regarded as a code template only. 1323 * // It will require modifications to work: 1324 * // - It may require correct/in-range values for request initialization. 1325 * // - It may require specifying regional endpoints when creating the service client as shown in 1326 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1327 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1328 * String name = PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString(); 1329 * orgPolicyClient.deletePolicy(name); 1330 * } 1331 * }</pre> 1332 * 1333 * @param name Required. Name of the policy to delete. See `Policy` for naming rules. 1334 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1335 */ deletePolicy(String name)1336 public final void deletePolicy(String name) { 1337 DeletePolicyRequest request = DeletePolicyRequest.newBuilder().setName(name).build(); 1338 deletePolicy(request); 1339 } 1340 1341 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1342 /** 1343 * Deletes a Policy. 1344 * 1345 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org 1346 * Policy does not exist. 1347 * 1348 * <p>Sample code: 1349 * 1350 * <pre>{@code 1351 * // This snippet has been automatically generated and should be regarded as a code template only. 1352 * // It will require modifications to work: 1353 * // - It may require correct/in-range values for request initialization. 1354 * // - It may require specifying regional endpoints when creating the service client as shown in 1355 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1356 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1357 * DeletePolicyRequest request = 1358 * DeletePolicyRequest.newBuilder() 1359 * .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) 1360 * .build(); 1361 * orgPolicyClient.deletePolicy(request); 1362 * } 1363 * }</pre> 1364 * 1365 * @param request The request object containing all of the parameters for the API call. 1366 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 1367 */ deletePolicy(DeletePolicyRequest request)1368 public final void deletePolicy(DeletePolicyRequest request) { 1369 deletePolicyCallable().call(request); 1370 } 1371 1372 // AUTO-GENERATED DOCUMENTATION AND METHOD. 1373 /** 1374 * Deletes a Policy. 1375 * 1376 * <p>Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or Org 1377 * Policy does not exist. 1378 * 1379 * <p>Sample code: 1380 * 1381 * <pre>{@code 1382 * // This snippet has been automatically generated and should be regarded as a code template only. 1383 * // It will require modifications to work: 1384 * // - It may require correct/in-range values for request initialization. 1385 * // - It may require specifying regional endpoints when creating the service client as shown in 1386 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 1387 * try (OrgPolicyClient orgPolicyClient = OrgPolicyClient.create()) { 1388 * DeletePolicyRequest request = 1389 * DeletePolicyRequest.newBuilder() 1390 * .setName(PolicyName.ofProjectPolicyName("[PROJECT]", "[POLICY]").toString()) 1391 * .build(); 1392 * ApiFuture<Empty> future = orgPolicyClient.deletePolicyCallable().futureCall(request); 1393 * // Do something. 1394 * future.get(); 1395 * } 1396 * }</pre> 1397 */ deletePolicyCallable()1398 public final UnaryCallable<DeletePolicyRequest, Empty> deletePolicyCallable() { 1399 return stub.deletePolicyCallable(); 1400 } 1401 1402 @Override close()1403 public final void close() { 1404 stub.close(); 1405 } 1406 1407 @Override shutdown()1408 public void shutdown() { 1409 stub.shutdown(); 1410 } 1411 1412 @Override isShutdown()1413 public boolean isShutdown() { 1414 return stub.isShutdown(); 1415 } 1416 1417 @Override isTerminated()1418 public boolean isTerminated() { 1419 return stub.isTerminated(); 1420 } 1421 1422 @Override shutdownNow()1423 public void shutdownNow() { 1424 stub.shutdownNow(); 1425 } 1426 1427 @Override awaitTermination(long duration, TimeUnit unit)1428 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 1429 return stub.awaitTermination(duration, unit); 1430 } 1431 1432 public static class ListConstraintsPagedResponse 1433 extends AbstractPagedListResponse< 1434 ListConstraintsRequest, 1435 ListConstraintsResponse, 1436 Constraint, 1437 ListConstraintsPage, 1438 ListConstraintsFixedSizeCollection> { 1439 createAsync( PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, ApiFuture<ListConstraintsResponse> futureResponse)1440 public static ApiFuture<ListConstraintsPagedResponse> createAsync( 1441 PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, 1442 ApiFuture<ListConstraintsResponse> futureResponse) { 1443 ApiFuture<ListConstraintsPage> futurePage = 1444 ListConstraintsPage.createEmptyPage().createPageAsync(context, futureResponse); 1445 return ApiFutures.transform( 1446 futurePage, 1447 input -> new ListConstraintsPagedResponse(input), 1448 MoreExecutors.directExecutor()); 1449 } 1450 ListConstraintsPagedResponse(ListConstraintsPage page)1451 private ListConstraintsPagedResponse(ListConstraintsPage page) { 1452 super(page, ListConstraintsFixedSizeCollection.createEmptyCollection()); 1453 } 1454 } 1455 1456 public static class ListConstraintsPage 1457 extends AbstractPage< 1458 ListConstraintsRequest, ListConstraintsResponse, Constraint, ListConstraintsPage> { 1459 ListConstraintsPage( PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, ListConstraintsResponse response)1460 private ListConstraintsPage( 1461 PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, 1462 ListConstraintsResponse response) { 1463 super(context, response); 1464 } 1465 createEmptyPage()1466 private static ListConstraintsPage createEmptyPage() { 1467 return new ListConstraintsPage(null, null); 1468 } 1469 1470 @Override createPage( PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, ListConstraintsResponse response)1471 protected ListConstraintsPage createPage( 1472 PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, 1473 ListConstraintsResponse response) { 1474 return new ListConstraintsPage(context, response); 1475 } 1476 1477 @Override createPageAsync( PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, ApiFuture<ListConstraintsResponse> futureResponse)1478 public ApiFuture<ListConstraintsPage> createPageAsync( 1479 PageContext<ListConstraintsRequest, ListConstraintsResponse, Constraint> context, 1480 ApiFuture<ListConstraintsResponse> futureResponse) { 1481 return super.createPageAsync(context, futureResponse); 1482 } 1483 } 1484 1485 public static class ListConstraintsFixedSizeCollection 1486 extends AbstractFixedSizeCollection< 1487 ListConstraintsRequest, 1488 ListConstraintsResponse, 1489 Constraint, 1490 ListConstraintsPage, 1491 ListConstraintsFixedSizeCollection> { 1492 ListConstraintsFixedSizeCollection( List<ListConstraintsPage> pages, int collectionSize)1493 private ListConstraintsFixedSizeCollection( 1494 List<ListConstraintsPage> pages, int collectionSize) { 1495 super(pages, collectionSize); 1496 } 1497 createEmptyCollection()1498 private static ListConstraintsFixedSizeCollection createEmptyCollection() { 1499 return new ListConstraintsFixedSizeCollection(null, 0); 1500 } 1501 1502 @Override createCollection( List<ListConstraintsPage> pages, int collectionSize)1503 protected ListConstraintsFixedSizeCollection createCollection( 1504 List<ListConstraintsPage> pages, int collectionSize) { 1505 return new ListConstraintsFixedSizeCollection(pages, collectionSize); 1506 } 1507 } 1508 1509 public static class ListPoliciesPagedResponse 1510 extends AbstractPagedListResponse< 1511 ListPoliciesRequest, 1512 ListPoliciesResponse, 1513 Policy, 1514 ListPoliciesPage, 1515 ListPoliciesFixedSizeCollection> { 1516 createAsync( PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, ApiFuture<ListPoliciesResponse> futureResponse)1517 public static ApiFuture<ListPoliciesPagedResponse> createAsync( 1518 PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, 1519 ApiFuture<ListPoliciesResponse> futureResponse) { 1520 ApiFuture<ListPoliciesPage> futurePage = 1521 ListPoliciesPage.createEmptyPage().createPageAsync(context, futureResponse); 1522 return ApiFutures.transform( 1523 futurePage, 1524 input -> new ListPoliciesPagedResponse(input), 1525 MoreExecutors.directExecutor()); 1526 } 1527 ListPoliciesPagedResponse(ListPoliciesPage page)1528 private ListPoliciesPagedResponse(ListPoliciesPage page) { 1529 super(page, ListPoliciesFixedSizeCollection.createEmptyCollection()); 1530 } 1531 } 1532 1533 public static class ListPoliciesPage 1534 extends AbstractPage<ListPoliciesRequest, ListPoliciesResponse, Policy, ListPoliciesPage> { 1535 ListPoliciesPage( PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, ListPoliciesResponse response)1536 private ListPoliciesPage( 1537 PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, 1538 ListPoliciesResponse response) { 1539 super(context, response); 1540 } 1541 createEmptyPage()1542 private static ListPoliciesPage createEmptyPage() { 1543 return new ListPoliciesPage(null, null); 1544 } 1545 1546 @Override createPage( PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, ListPoliciesResponse response)1547 protected ListPoliciesPage createPage( 1548 PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, 1549 ListPoliciesResponse response) { 1550 return new ListPoliciesPage(context, response); 1551 } 1552 1553 @Override createPageAsync( PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, ApiFuture<ListPoliciesResponse> futureResponse)1554 public ApiFuture<ListPoliciesPage> createPageAsync( 1555 PageContext<ListPoliciesRequest, ListPoliciesResponse, Policy> context, 1556 ApiFuture<ListPoliciesResponse> futureResponse) { 1557 return super.createPageAsync(context, futureResponse); 1558 } 1559 } 1560 1561 public static class ListPoliciesFixedSizeCollection 1562 extends AbstractFixedSizeCollection< 1563 ListPoliciesRequest, 1564 ListPoliciesResponse, 1565 Policy, 1566 ListPoliciesPage, 1567 ListPoliciesFixedSizeCollection> { 1568 ListPoliciesFixedSizeCollection(List<ListPoliciesPage> pages, int collectionSize)1569 private ListPoliciesFixedSizeCollection(List<ListPoliciesPage> pages, int collectionSize) { 1570 super(pages, collectionSize); 1571 } 1572 createEmptyCollection()1573 private static ListPoliciesFixedSizeCollection createEmptyCollection() { 1574 return new ListPoliciesFixedSizeCollection(null, 0); 1575 } 1576 1577 @Override createCollection( List<ListPoliciesPage> pages, int collectionSize)1578 protected ListPoliciesFixedSizeCollection createCollection( 1579 List<ListPoliciesPage> pages, int collectionSize) { 1580 return new ListPoliciesFixedSizeCollection(pages, collectionSize); 1581 } 1582 } 1583 } 1584