|
23 | 23 | import java.util.Objects;
|
24 | 24 | import java.util.UUID;
|
25 | 25 |
|
26 |
| -import static com.azure.v2.security.keyvault.administration.KeyVaultAdministrationUtil.CANNOT_BE_NULL; |
27 | 26 | import static com.azure.v2.security.keyvault.administration.KeyVaultAdministrationUtil.mapPages;
|
28 | 27 | import static com.azure.v2.security.keyvault.administration.KeyVaultAdministrationUtil.mapResponse;
|
29 | 28 | import static com.azure.v2.security.keyvault.administration.KeyVaultAdministrationUtil.roleAssignmentToKeyVaultRoleAssignment;
|
@@ -279,18 +278,12 @@ public PagedIterable<KeyVaultRoleDefinition> listRoleDefinitions(KeyVaultRoleSco
|
279 | 278 | public PagedIterable<KeyVaultRoleDefinition> listRoleDefinitions(KeyVaultRoleScope roleScope,
|
280 | 279 | RequestContext requestContext) {
|
281 | 280 |
|
282 |
| - try { |
283 |
| - Objects.requireNonNull(roleScope, String.format(CANNOT_BE_NULL, "'roleScope'")); |
284 |
| - |
285 |
| - return mapPages( |
286 |
| - pagingOptions -> clientImpl.getRoleDefinitions() |
287 |
| - .listSinglePage(roleScope.getValue(), null, requestContext), |
288 |
| - (pagingOptions, nextLink) -> clientImpl.getRoleDefinitions() |
289 |
| - .listNextSinglePage(nextLink, requestContext), |
290 |
| - KeyVaultAdministrationUtil::roleDefinitionToKeyVaultRoleDefinition); |
291 |
| - } catch (RuntimeException e) { |
292 |
| - throw LOGGER.logThrowableAsError(e); |
293 |
| - } |
| 281 | + Objects.requireNonNull(roleScope, "'roleScope' cannot be null."); |
| 282 | + |
| 283 | + return mapPages( |
| 284 | + pagingOptions -> clientImpl.getRoleDefinitions().listSinglePage(roleScope.getValue(), null, requestContext), |
| 285 | + (pagingOptions, nextLink) -> clientImpl.getRoleDefinitions().listNextSinglePage(nextLink, requestContext), |
| 286 | + KeyVaultAdministrationUtil::roleDefinitionToKeyVaultRoleDefinition); |
294 | 287 | }
|
295 | 288 |
|
296 | 289 | /**
|
@@ -349,15 +342,11 @@ public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope) {
|
349 | 342 | */
|
350 | 343 | @ServiceMethod(returns = ReturnType.SINGLE)
|
351 | 344 | public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinitionName) {
|
352 |
| - try { |
353 |
| - Objects.requireNonNull(roleScope, String.format(CANNOT_BE_NULL, "'roleScope'")); |
354 |
| - |
355 |
| - return roleDefinitionToKeyVaultRoleDefinition(clientImpl.getRoleDefinitions() |
356 |
| - .createOrUpdate(roleScope.toString(), |
357 |
| - isNullOrEmpty(roleDefinitionName) ? UUID.randomUUID().toString() : roleDefinitionName, null)); |
358 |
| - } catch (RuntimeException e) { |
359 |
| - throw LOGGER.logThrowableAsError(e); |
360 |
| - } |
| 345 | + Objects.requireNonNull(roleScope, "'roleScope' cannot be null."); |
| 346 | + |
| 347 | + return roleDefinitionToKeyVaultRoleDefinition(clientImpl.getRoleDefinitions() |
| 348 | + .createOrUpdate(roleScope.toString(), |
| 349 | + isNullOrEmpty(roleDefinitionName) ? UUID.randomUUID().toString() : roleDefinitionName, null)); |
361 | 350 | }
|
362 | 351 |
|
363 | 352 | /**
|
@@ -423,15 +412,11 @@ public KeyVaultRoleDefinition setRoleDefinition(KeyVaultRoleScope roleScope, Str
|
423 | 412 | public Response<KeyVaultRoleDefinition> setRoleDefinitionWithResponse(SetRoleDefinitionOptions options,
|
424 | 413 | RequestContext requestContext) {
|
425 | 414 |
|
426 |
| - try { |
427 |
| - return mapResponse( |
428 |
| - clientImpl.getRoleDefinitions() |
429 |
| - .createOrUpdateWithResponse(options.getRoleScope().toString(), options.getRoleDefinitionName(), |
430 |
| - validateAndGetRoleDefinitionCreateParameters(options), requestContext), |
431 |
| - KeyVaultAdministrationUtil::roleDefinitionToKeyVaultRoleDefinition); |
432 |
| - } catch (RuntimeException e) { |
433 |
| - throw LOGGER.logThrowableAsError(e); |
434 |
| - } |
| 415 | + return mapResponse( |
| 416 | + clientImpl.getRoleDefinitions() |
| 417 | + .createOrUpdateWithResponse(options.getRoleScope().toString(), options.getRoleDefinitionName(), |
| 418 | + validateAndGetRoleDefinitionCreateParameters(options, LOGGER), requestContext), |
| 419 | + KeyVaultAdministrationUtil::roleDefinitionToKeyVaultRoleDefinition); |
435 | 420 | }
|
436 | 421 |
|
437 | 422 | /**
|
@@ -464,14 +449,10 @@ public Response<KeyVaultRoleDefinition> setRoleDefinitionWithResponse(SetRoleDef
|
464 | 449 | */
|
465 | 450 | @ServiceMethod(returns = ReturnType.SINGLE)
|
466 | 451 | public KeyVaultRoleDefinition getRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinitionName) {
|
467 |
| - try { |
468 |
| - validateRoleDefinitionParameters(roleScope, roleDefinitionName); |
| 452 | + validateRoleDefinitionParameters(roleScope, roleDefinitionName, LOGGER); |
469 | 453 |
|
470 |
| - return roleDefinitionToKeyVaultRoleDefinition( |
471 |
| - clientImpl.getRoleDefinitions().get(roleScope.toString(), roleDefinitionName)); |
472 |
| - } catch (RuntimeException e) { |
473 |
| - throw LOGGER.logThrowableAsError(e); |
474 |
| - } |
| 454 | + return roleDefinitionToKeyVaultRoleDefinition( |
| 455 | + clientImpl.getRoleDefinitions().get(roleScope.toString(), roleDefinitionName)); |
475 | 456 | }
|
476 | 457 |
|
477 | 458 | /**
|
@@ -514,16 +495,11 @@ public KeyVaultRoleDefinition getRoleDefinition(KeyVaultRoleScope roleScope, Str
|
514 | 495 | public Response<KeyVaultRoleDefinition> getRoleDefinitionWithResponse(KeyVaultRoleScope roleScope,
|
515 | 496 | String roleDefinitionName, RequestContext requestContext) {
|
516 | 497 |
|
517 |
| - try { |
518 |
| - validateRoleDefinitionParameters(roleScope, roleDefinitionName); |
| 498 | + validateRoleDefinitionParameters(roleScope, roleDefinitionName, LOGGER); |
519 | 499 |
|
520 |
| - return mapResponse( |
521 |
| - clientImpl.getRoleDefinitions() |
522 |
| - .getWithResponse(roleScope.toString(), roleDefinitionName, requestContext), |
523 |
| - KeyVaultAdministrationUtil::roleDefinitionToKeyVaultRoleDefinition); |
524 |
| - } catch (RuntimeException e) { |
525 |
| - throw LOGGER.logThrowableAsError(e); |
526 |
| - } |
| 500 | + return mapResponse( |
| 501 | + clientImpl.getRoleDefinitions().getWithResponse(roleScope.toString(), roleDefinitionName, requestContext), |
| 502 | + KeyVaultAdministrationUtil::roleDefinitionToKeyVaultRoleDefinition); |
527 | 503 | }
|
528 | 504 |
|
529 | 505 | /**
|
@@ -552,13 +528,9 @@ public Response<KeyVaultRoleDefinition> getRoleDefinitionWithResponse(KeyVaultRo
|
552 | 528 | */
|
553 | 529 | @ServiceMethod(returns = ReturnType.SINGLE)
|
554 | 530 | public void deleteRoleDefinition(KeyVaultRoleScope roleScope, String roleDefinitionName) {
|
555 |
| - try { |
556 |
| - validateRoleDefinitionParameters(roleScope, roleDefinitionName); |
| 531 | + validateRoleDefinitionParameters(roleScope, roleDefinitionName, LOGGER); |
557 | 532 |
|
558 |
| - clientImpl.getRoleDefinitions().delete(roleScope.toString(), roleDefinitionName); |
559 |
| - } catch (RuntimeException e) { |
560 |
| - throw LOGGER.logThrowableAsError(e); |
561 |
| - } |
| 533 | + clientImpl.getRoleDefinitions().delete(roleScope.toString(), roleDefinitionName); |
562 | 534 | }
|
563 | 535 |
|
564 | 536 | /**
|
@@ -600,15 +572,11 @@ public Response<Void> deleteRoleDefinitionWithResponse(KeyVaultRoleScope roleSco
|
600 | 572 | try (Response<RoleDefinition> response = clientImpl.getRoleDefinitions()
|
601 | 573 | .deleteWithResponse(roleScope.toString(), roleDefinitionName, requestContext)) {
|
602 | 574 |
|
603 |
| - validateRoleDefinitionParameters(roleScope, roleDefinitionName); |
| 575 | + validateRoleDefinitionParameters(roleScope, roleDefinitionName, LOGGER); |
604 | 576 |
|
605 | 577 | return new Response<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null);
|
606 |
| - } catch (RuntimeException e) { |
607 |
| - if (e instanceof HttpResponseException) { |
608 |
| - return swallowExceptionForStatusCode(404, (HttpResponseException) e, LOGGER); |
609 |
| - } |
610 |
| - |
611 |
| - throw LOGGER.logThrowableAsError(e); |
| 578 | + } catch (HttpResponseException e) { |
| 579 | + return swallowExceptionForStatusCode(404, e); |
612 | 580 | }
|
613 | 581 | }
|
614 | 582 |
|
@@ -675,18 +643,14 @@ public PagedIterable<KeyVaultRoleAssignment> listRoleAssignments(KeyVaultRoleSco
|
675 | 643 | public PagedIterable<KeyVaultRoleAssignment> listRoleAssignments(KeyVaultRoleScope roleScope,
|
676 | 644 | RequestContext requestContext) {
|
677 | 645 |
|
678 |
| - try { |
679 |
| - Objects.requireNonNull(roleScope, String.format(CANNOT_BE_NULL, "'roleScope'")); |
680 |
| - |
681 |
| - return mapPages( |
682 |
| - pagingOptions -> clientImpl.getRoleAssignments() |
683 |
| - .listForScopeSinglePage(roleScope.toString(), null, requestContext), |
684 |
| - (pagingOptions, nextLink) -> clientImpl.getRoleAssignments() |
685 |
| - .listForScopeNextSinglePage(nextLink, requestContext), |
686 |
| - KeyVaultAdministrationUtil::roleAssignmentToKeyVaultRoleAssignment); |
687 |
| - } catch (RuntimeException e) { |
688 |
| - throw LOGGER.logThrowableAsError(e); |
689 |
| - } |
| 646 | + Objects.requireNonNull(roleScope, "'roleScope' cannot be null."); |
| 647 | + |
| 648 | + return mapPages( |
| 649 | + pagingOptions -> clientImpl.getRoleAssignments() |
| 650 | + .listForScopeSinglePage(roleScope.toString(), null, requestContext), |
| 651 | + (pagingOptions, nextLink) -> clientImpl.getRoleAssignments() |
| 652 | + .listForScopeNextSinglePage(nextLink, requestContext), |
| 653 | + KeyVaultAdministrationUtil::roleAssignmentToKeyVaultRoleAssignment); |
690 | 654 | }
|
691 | 655 |
|
692 | 656 | /**
|
@@ -769,16 +733,12 @@ public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleScope roleScope,
|
769 | 733 | public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleScope roleScope, String roleDefinitionId,
|
770 | 734 | String principalId, String roleAssignmentName) {
|
771 | 735 |
|
772 |
| - try { |
773 |
| - RoleAssignmentCreateParameters parameters |
774 |
| - = validateAndGetRoleAssignmentCreateParameters(roleScope, roleDefinitionId, principalId, |
775 |
| - isNullOrEmpty(roleAssignmentName) ? UUID.randomUUID().toString() : roleAssignmentName); |
| 736 | + RoleAssignmentCreateParameters parameters |
| 737 | + = validateAndGetRoleAssignmentCreateParameters(roleScope, roleDefinitionId, principalId, |
| 738 | + isNullOrEmpty(roleAssignmentName) ? UUID.randomUUID().toString() : roleAssignmentName, LOGGER); |
776 | 739 |
|
777 |
| - return roleAssignmentToKeyVaultRoleAssignment( |
778 |
| - clientImpl.getRoleAssignments().create(roleScope.toString(), roleAssignmentName, parameters)); |
779 |
| - } catch (RuntimeException e) { |
780 |
| - throw LOGGER.logThrowableAsError(e); |
781 |
| - } |
| 740 | + return roleAssignmentToKeyVaultRoleAssignment( |
| 741 | + clientImpl.getRoleAssignments().create(roleScope.toString(), roleAssignmentName, parameters)); |
782 | 742 | }
|
783 | 743 |
|
784 | 744 | /**
|
@@ -828,17 +788,13 @@ public KeyVaultRoleAssignment createRoleAssignment(KeyVaultRoleScope roleScope,
|
828 | 788 | public Response<KeyVaultRoleAssignment> createRoleAssignmentWithResponse(KeyVaultRoleScope roleScope,
|
829 | 789 | String roleDefinitionId, String principalId, String roleAssignmentName, RequestContext requestContext) {
|
830 | 790 |
|
831 |
| - try { |
832 |
| - RoleAssignmentCreateParameters parameters = validateAndGetRoleAssignmentCreateParameters(roleScope, |
833 |
| - roleDefinitionId, principalId, roleAssignmentName); |
| 791 | + RoleAssignmentCreateParameters parameters = validateAndGetRoleAssignmentCreateParameters(roleScope, |
| 792 | + roleDefinitionId, principalId, roleAssignmentName, LOGGER); |
834 | 793 |
|
835 |
| - return mapResponse( |
836 |
| - clientImpl.getRoleAssignments() |
837 |
| - .createWithResponse(roleScope.toString(), roleAssignmentName, parameters, requestContext), |
838 |
| - KeyVaultAdministrationUtil::roleAssignmentToKeyVaultRoleAssignment); |
839 |
| - } catch (RuntimeException e) { |
840 |
| - throw LOGGER.logThrowableAsError(e); |
841 |
| - } |
| 794 | + return mapResponse( |
| 795 | + clientImpl.getRoleAssignments() |
| 796 | + .createWithResponse(roleScope.toString(), roleAssignmentName, parameters, requestContext), |
| 797 | + KeyVaultAdministrationUtil::roleAssignmentToKeyVaultRoleAssignment); |
842 | 798 | }
|
843 | 799 |
|
844 | 800 | /**
|
@@ -869,14 +825,10 @@ public Response<KeyVaultRoleAssignment> createRoleAssignmentWithResponse(KeyVaul
|
869 | 825 | */
|
870 | 826 | @ServiceMethod(returns = ReturnType.SINGLE)
|
871 | 827 | public KeyVaultRoleAssignment getRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) {
|
872 |
| - try { |
873 |
| - validateRoleAssignmentParameters(roleScope, roleAssignmentName); |
| 828 | + validateRoleAssignmentParameters(roleScope, roleAssignmentName, LOGGER); |
874 | 829 |
|
875 |
| - return roleAssignmentToKeyVaultRoleAssignment( |
876 |
| - clientImpl.getRoleAssignments().get(roleScope.toString(), roleAssignmentName)); |
877 |
| - } catch (RuntimeException e) { |
878 |
| - throw LOGGER.logThrowableAsError(e); |
879 |
| - } |
| 830 | + return roleAssignmentToKeyVaultRoleAssignment( |
| 831 | + clientImpl.getRoleAssignments().get(roleScope.toString(), roleAssignmentName)); |
880 | 832 | }
|
881 | 833 |
|
882 | 834 | /**
|
@@ -917,16 +869,11 @@ public KeyVaultRoleAssignment getRoleAssignment(KeyVaultRoleScope roleScope, Str
|
917 | 869 | public Response<KeyVaultRoleAssignment> getRoleAssignmentWithResponse(KeyVaultRoleScope roleScope,
|
918 | 870 | String roleAssignmentName, RequestContext requestContext) {
|
919 | 871 |
|
920 |
| - try { |
921 |
| - validateRoleAssignmentParameters(roleScope, roleAssignmentName); |
| 872 | + validateRoleAssignmentParameters(roleScope, roleAssignmentName, LOGGER); |
922 | 873 |
|
923 |
| - return mapResponse( |
924 |
| - clientImpl.getRoleAssignments() |
925 |
| - .getWithResponse(roleScope.toString(), roleAssignmentName, requestContext), |
926 |
| - KeyVaultAdministrationUtil::roleAssignmentToKeyVaultRoleAssignment); |
927 |
| - } catch (RuntimeException e) { |
928 |
| - throw LOGGER.logThrowableAsError(e); |
929 |
| - } |
| 874 | + return mapResponse( |
| 875 | + clientImpl.getRoleAssignments().getWithResponse(roleScope.toString(), roleAssignmentName, requestContext), |
| 876 | + KeyVaultAdministrationUtil::roleAssignmentToKeyVaultRoleAssignment); |
930 | 877 | }
|
931 | 878 |
|
932 | 879 | /**
|
@@ -954,13 +901,9 @@ public Response<KeyVaultRoleAssignment> getRoleAssignmentWithResponse(KeyVaultRo
|
954 | 901 | */
|
955 | 902 | @ServiceMethod(returns = ReturnType.SINGLE)
|
956 | 903 | public void deleteRoleAssignment(KeyVaultRoleScope roleScope, String roleAssignmentName) {
|
957 |
| - try { |
958 |
| - validateRoleAssignmentParameters(roleScope, roleAssignmentName); |
| 904 | + validateRoleAssignmentParameters(roleScope, roleAssignmentName, LOGGER); |
959 | 905 |
|
960 |
| - clientImpl.getRoleAssignments().delete(roleScope.toString(), roleAssignmentName); |
961 |
| - } catch (RuntimeException e) { |
962 |
| - throw LOGGER.logThrowableAsError(e); |
963 |
| - } |
| 906 | + clientImpl.getRoleAssignments().delete(roleScope.toString(), roleAssignmentName); |
964 | 907 | }
|
965 | 908 |
|
966 | 909 | /**
|
@@ -1001,15 +944,11 @@ public Response<Void> deleteRoleAssignmentWithResponse(KeyVaultRoleScope roleSco
|
1001 | 944 | try (Response<RoleAssignment> response = clientImpl.getRoleAssignments()
|
1002 | 945 | .deleteWithResponse(roleScope.toString(), roleAssignmentName, requestContext)) {
|
1003 | 946 |
|
1004 |
| - validateRoleAssignmentParameters(roleScope, roleAssignmentName); |
| 947 | + validateRoleAssignmentParameters(roleScope, roleAssignmentName, LOGGER); |
1005 | 948 |
|
1006 | 949 | return new Response<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null);
|
1007 |
| - } catch (RuntimeException e) { |
1008 |
| - if (e instanceof HttpResponseException) { |
1009 |
| - return swallowExceptionForStatusCode(404, (HttpResponseException) e, LOGGER); |
1010 |
| - } |
1011 |
| - |
1012 |
| - throw LOGGER.logThrowableAsError(e); |
| 950 | + } catch (HttpResponseException e) { |
| 951 | + return swallowExceptionForStatusCode(404, e); |
1013 | 952 | }
|
1014 | 953 | }
|
1015 | 954 | }
|
0 commit comments