def invoke_rule_meta_updater()

in src/lambdas/custodian_configuration_api_handler/handler.py [0:0]


    def invoke_rule_meta_updater(self, event: RuleUpdateMetaPostModel):

        customer = event.customer or SYSTEM_CUSTOMER

        rs_service = self.rule_source_service

        rule_source_id = event.rule_source_id
        if rule_source_id:
            rule_source = rs_service.get_nullable(rule_source_id)
            if not rule_source or customer != SYSTEM_CUSTOMER and rule_source.customer != customer:
                return build_response(
                    code=HTTPStatus.NOT_FOUND,
                    content=f'The requested Rule Source \'{rule_source_id}\' '
                            f'is not found'
                )
            rule_sources = [rule_source]
        else:
            rule_sources = rs_service.query(customer=customer)

        ids_to_sync = []
        responses = []
        for rule_source in rule_sources:
            log_head = f'RuleSource:{rule_source.id!r} of ' \
                       f'{rule_source.customer!r} customer'
            if rs_service.is_allowed_to_sync(rule_source):
                _LOG.debug(f'{log_head} is allowed to update')
                ids_to_sync.append(rule_source.id)
                response = self.build_update_event_response(
                    rule_source=rule_source
                )
            else:
                _LOG.warning(f'{log_head} is not allowed to update')
                response = self.build_update_event_response(
                    rule_source=rule_source, forbidden=True
                )
            responses.append(response)

        if ids_to_sync:
            self.lambda_client.invoke_function_async(
                RULE_META_UPDATER_LAMBDA_NAME,
                event={'rule_source_ids': ids_to_sync}
            )
            _LOG.debug(f'{RULE_META_UPDATER_LAMBDA_NAME} has been triggered')
        else:
            _LOG.warning(
                f'No rule-sources allowed to update. '
                f'{RULE_META_UPDATER_LAMBDA_NAME} has not been triggered')
            return build_response(
                code=HTTPStatus.NOT_FOUND,
                content='No rule sources were found'
            )

        return build_response(
            code=HTTPStatus.ACCEPTED,
            content=responses
        )