128 lines
2.6 KiB
Python
Executable File
128 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
__author__ = 'RemiZOffAlex'
|
|
__email__ = 'remizoffalex@mail.ru'
|
|
|
|
import logging
|
|
|
|
from router.broker import Broker
|
|
from router.compiler import Compiler
|
|
from router.syntetic.url import rule_comparator
|
|
|
|
log = logging.getLogger(__name__)
|
|
broker = Broker()
|
|
|
|
|
|
def comparator(rule, query):
|
|
print('comparator')
|
|
print(rule)
|
|
print(query['url'])
|
|
if rule['url']['value'] == query['url']:
|
|
return {}
|
|
|
|
|
|
class Comparator:
|
|
def __init__(self, rule):
|
|
self.rule = rule
|
|
|
|
def __call__(self, query):
|
|
log.error('Comparator.__call__')
|
|
log.error(self.rule)
|
|
compiler = Compiler()
|
|
log.error(compiler)
|
|
expression = compiler(self.rule)
|
|
log.error(expression)
|
|
result = expression(query)
|
|
log.error('result')
|
|
log.error(result)
|
|
return result
|
|
# if self.condition == 'AND':
|
|
# return all(map(lambda x: RuleGroup.get_rule_object(x).evaluate(obj), self.rules))
|
|
# else:
|
|
# return any(map(lambda x: RuleGroup.get_rule_object(x).evaluate(obj), self.rules))
|
|
|
|
|
|
rule={
|
|
'operator': 'and',
|
|
'rules': [
|
|
{
|
|
'key': 'domain',
|
|
'operator': 'regex',
|
|
'value': '.*'
|
|
},
|
|
{
|
|
'key': 'url',
|
|
'operator': 'equal',
|
|
'value': '/'
|
|
}
|
|
]
|
|
}
|
|
@broker.route(
|
|
comparator=Comparator(rule=rule)
|
|
)
|
|
def foo(request):
|
|
return 'foo'
|
|
|
|
|
|
def comparator_flask(rule, query):
|
|
print('comparator')
|
|
print(rule['url'])
|
|
print(query['url'])
|
|
if rule['url'] == query['url']:
|
|
result = rule_comparator(rule['url'], query['url'])
|
|
print(result)
|
|
return result
|
|
|
|
|
|
# rule={
|
|
# 'key': 'url',
|
|
# 'operator': 'equal',
|
|
# 'value': '/'
|
|
# }
|
|
# @broker.route(
|
|
# comparator=comparator_flask(rule=rule)
|
|
# )
|
|
# def foo(request):
|
|
# return 'foo'
|
|
|
|
|
|
request = {
|
|
'url': '/',
|
|
'domain': 'example.org'
|
|
}
|
|
broker_response = broker(request)
|
|
print('broker_response', broker_response)
|
|
if broker_response is not None:
|
|
method, response = broker_response
|
|
print(method)
|
|
|
|
if method is None:
|
|
print('Маршрут не найден')
|
|
response = None
|
|
else:
|
|
response = method(request)
|
|
|
|
print(response)
|
|
|
|
print('#'*80)
|
|
print('CICD')
|
|
import os
|
|
request = os.environ
|
|
print(request)
|
|
broker = Broker()
|
|
|
|
rule={
|
|
'key': 'DESKTOP_SESSION',
|
|
'operator': 'equal',
|
|
'value': 'xfce'
|
|
}
|
|
@broker.route(
|
|
comparator=Comparator(rule=rule)
|
|
)
|
|
def foo(request):
|
|
return 'foo'
|
|
|
|
broker_response = broker(request)
|
|
method, response = broker_response
|
|
print(method)
|