private ProgressEvent updateACL()

in aws-memorydb-acl/src/main/java/software/amazon/memorydb/acl/UpdateHandler.java [48:109]


    private ProgressEvent<ResourceModel, CallbackContext> updateACL(
        AmazonWebServicesClientProxy proxy,
        ProgressEvent<ResourceModel, CallbackContext> progress,
        ResourceHandlerRequest<ResourceModel> request,
        ProxyClient<MemoryDbClient> proxyClient
    ) {
        if (hasChangeOnCoreModel(request.getDesiredResourceState(), request.getPreviousResourceState())) {
            return proxy.initiate("AWS-MemoryDB-User::Update", proxyClient, progress.getResourceModel(),
                progress.getCallbackContext())
                .translateToServiceRequest(Translator::translateToUpdateRequest)
                .makeServiceCall((awsRequest, proxyInvocation)  -> handleExceptions(() -> {
                        try {
                            //Get current acl
                            DescribeAcLsRequest describeRequest =
                                DescribeAcLsRequest.builder().aclName(awsRequest.aclName()).build();
                            final DescribeAcLsResponse describeResponse =
                                proxyInvocation.injectCredentialsAndInvokeV2(describeRequest,
                                    proxyInvocation.client()::describeACLs);

                            ACL acl = describeResponse.acLs().get(0);

                            //Create list of resources to add and remove
                            List<String> userIdsToAdd = progress.getResourceModel().getUserNames().stream()
                                .distinct()
                                .filter(((Predicate<String>) acl.userNames()::contains).negate())
                                .collect(Collectors.toList());

                            this.logger.log(acl.toString());

                            List<String> userIdsToRemove = acl.userNames().stream()
                                .distinct()
                                .filter(
                                    ((Predicate<String>) progress.getResourceModel().getUserNames()::contains).negate())
                                .collect(Collectors.toList());

                            Builder builder = UpdateAclRequest.builder();
                            builder.aclName(acl.name());
                            builder.userNamesToAdd(userIdsToAdd.isEmpty() ? null : userIdsToAdd);
                            builder.userNamesToRemove(userIdsToRemove.isEmpty() ? null : userIdsToRemove);
                            UpdateAclRequest updateRequest = builder.build();

                            //Update ACL
                            final UpdateAclResponse response =
                                proxyInvocation.injectCredentialsAndInvokeV2(updateRequest,
                                    proxyInvocation.client()::updateACL);

                            return response;
                        } catch (final AclNotFoundException e) {
                            throw new CfnNotFoundException(e);
                        } catch (final AwsServiceException e) {
                            throw new CfnGeneralServiceException(e);
                        }
                    }
                ))
                .stabilize(
                    (updateUserRequest, updateUserResponse, proxyInvocation, model, context) -> isAclStabilized(
                        proxyInvocation, model, logger))
                .progress();
        } else {
            return progress;
        }
    }