chg: [ail sync] edit ail_servers/sync_queues + fix logs

pull/586/head
Terrtia 2021-11-29 10:19:33 +01:00
parent 054df7c495
commit 1412e1afef
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
12 changed files with 634 additions and 67 deletions

View File

@ -120,6 +120,8 @@ function launching_logs {
screen -S "Logging_AIL" -X screen -t "LogQueue" bash -c "cd ${AIL_BIN}; ${AIL_VENV}/bin/log_subscriber -p 6380 -c Queuing -l ../logs/; read x" screen -S "Logging_AIL" -X screen -t "LogQueue" bash -c "cd ${AIL_BIN}; ${AIL_VENV}/bin/log_subscriber -p 6380 -c Queuing -l ../logs/; read x"
sleep 0.1 sleep 0.1
screen -S "Logging_AIL" -X screen -t "LogScript" bash -c "cd ${AIL_BIN}; ${AIL_VENV}/bin/log_subscriber -p 6380 -c Script -l ../logs/; read x" screen -S "Logging_AIL" -X screen -t "LogScript" bash -c "cd ${AIL_BIN}; ${AIL_VENV}/bin/log_subscriber -p 6380 -c Script -l ../logs/; read x"
sleep 0.1
screen -S "Logging_AIL" -X screen -t "LogScript" bash -c "cd ${AIL_BIN}; ${AIL_VENV}/bin/log_subscriber -p 6380 -c Sync -l ../logs/; read x"
} }
function launching_queues { function launching_queues {

View File

@ -33,7 +33,7 @@ config_loader = None
#### LOGS #### #### LOGS ####
# redis_logger = publisher # redis_logger = publisher
# redis_logger.port = 6380 # redis_logger.port = 6380
# redis_logger.channel = 'AIL_SYNC' # redis_logger.channel = 'Sync'
##-- LOGS --## ##-- LOGS --##
def is_valid_uuid_v4(UUID): def is_valid_uuid_v4(UUID):
@ -298,14 +298,14 @@ def get_ail_instance_by_key(key):
# def check_acl_sync_queue_ail(ail_uuid, queue_uuid, key): # def check_acl_sync_queue_ail(ail_uuid, queue_uuid, key):
# return is_ail_instance_queue(ail_uuid, queue_uuid) # return is_ail_instance_queue(ail_uuid, queue_uuid)
def update_ail_instance_key(ail_uuid, new_key): # def update_ail_instance_key(ail_uuid, new_key):
old_key = get_ail_instance_key(ail_uuid) # old_key = get_ail_instance_key(ail_uuid)
r_serv_sync.srem(f'ail:instance:key:all', old_key) # r_serv_sync.srem(f'ail:instance:key:all', old_key)
r_serv_sync.delete(f'ail:instance:key:{old_key}') # r_serv_sync.delete(f'ail:instance:key:{old_key}')
#
r_serv_sync.sadd(f'ail:instance:key:all', new_key) # r_serv_sync.sadd(f'ail:instance:key:all', new_key)
r_serv_sync.delete(f'ail:instance:key:{new_key}', ail_uuid) # r_serv_sync.delete(f'ail:instance:key:{new_key}', ail_uuid)
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'api_key', new_key) # r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'api_key', new_key)
#- AIL KEYS -# #- AIL KEYS -#
@ -348,20 +348,33 @@ def is_ail_instance_sync_enabled(ail_uuid, sync_mode=None):
else: else:
return False return False
def change_pull_push_state(ail_uuid, pull=False, push=False): def change_pull_push_state(ail_uuid, pull=None, push=None):
# sanityze pull/push edited = False
if pull: curr_pull = is_ail_instance_pull_enabled(ail_uuid)
pull = True curr_push = is_ail_instance_push_enabled(ail_uuid)
else: if pull is not None:
pull = False # sanityze pull
if push: if pull:
push = True pull = True
else: else:
push = False pull = False
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'push', push) if curr_pull != pull:
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'pull', pull) print('pull hset')
set_last_updated_sync_config() r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'pull', pull)
refresh_ail_instance_connection(ail_uuid) edited = True
if push is not None:
# sanityze push
if push:
push = True
else:
push = False
if curr_push != push:
print('push hset')
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'push', push)
edited = True
if edited:
set_last_updated_sync_config()
refresh_ail_instance_connection(ail_uuid)
def get_ail_server_version(ail_uuid): def get_ail_server_version(ail_uuid):
return r_serv_sync.hget(f'ail:instance:{ail_uuid}', 'version') return r_serv_sync.hget(f'ail:instance:{ail_uuid}', 'version')
@ -380,7 +393,7 @@ def get_ail_instance_metadata(ail_uuid, sync_queues=False):
dict_meta['url'] = get_ail_instance_url(ail_uuid) dict_meta['url'] = get_ail_instance_url(ail_uuid)
dict_meta['description'] = get_ail_instance_description(ail_uuid) dict_meta['description'] = get_ail_instance_description(ail_uuid)
dict_meta['pull'] = is_ail_instance_pull_enabled(ail_uuid) dict_meta['pull'] = is_ail_instance_pull_enabled(ail_uuid)
dict_meta['push'] = is_ail_instance_pull_enabled(ail_uuid) dict_meta['push'] = is_ail_instance_push_enabled(ail_uuid)
dict_meta['ping'] = get_ail_server_ping(ail_uuid) dict_meta['ping'] = get_ail_server_ping(ail_uuid)
dict_meta['version'] = get_ail_server_version(ail_uuid) dict_meta['version'] = get_ail_server_version(ail_uuid)
dict_meta['error'] = get_ail_server_error(ail_uuid) dict_meta['error'] = get_ail_server_error(ail_uuid)
@ -408,6 +421,39 @@ def get_ail_instances_metadata(l_ail_servers):
l_servers.append(get_ail_instance_metadata(ail_uuid, sync_queues=True)) l_servers.append(get_ail_instance_metadata(ail_uuid, sync_queues=True))
return l_servers return l_servers
def edit_ail_instance_key(ail_uuid, new_key):
key = get_ail_instance_key(ail_uuid)
if new_key and key != new_key:
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'api_key', new_key)
r_serv_sync.srem('ail:instance:key:all', key)
r_serv_sync.srem('ail:instance:key:all', new_key)
r_serv_sync.delete(f'ail:instance:key:{key}')
r_serv_sync.set(f'ail:instance:key:{new_key}', ail_uuid)
refresh_ail_instance_connection(ail_uuid)
def edit_ail_instance_url(ail_uuid, new_url):
url = get_ail_instance_url(ail_uuid)
if new_url and new_url != url:
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'url', new_url)
refresh_ail_instance_connection(ail_uuid)
def edit_ail_instance_pull_push(ail_uuid, new_pull, new_push):
pull = is_ail_instance_pull_enabled(ail_uuid)
push = is_ail_instance_push_enabled(ail_uuid)
if new_pull == pull:
new_pull = None
if new_push == push:
new_push = None
change_pull_push_state(ail_uuid, pull=new_pull, push=new_push)
def edit_ail_instance_description(ail_uuid, new_description):
description = get_ail_instance_description(ail_uuid)
if new_description is not None and description != new_description:
if not new_description:
r_serv_sync.hdel(f'ail:instance:{ail_uuid}', 'description')
else:
r_serv_sync.hset(f'ail:instance:{ail_uuid}', 'description', new_description)
# # TODO: VALIDATE URL # # TODO: VALIDATE URL
# API KEY # API KEY
def create_ail_instance(ail_uuid, url, api_key=None, description=None, pull=True, push=True): def create_ail_instance(ail_uuid, url, api_key=None, description=None, pull=True, push=True):
@ -438,6 +484,7 @@ def delete_ail_instance(ail_uuid):
r_serv_sync.srem('ail:instance:all', ail_uuid) r_serv_sync.srem('ail:instance:all', ail_uuid)
set_last_updated_sync_config() set_last_updated_sync_config()
refresh_ail_instance_connection(ail_uuid) refresh_ail_instance_connection(ail_uuid)
clear_save_ail_server_error(ail_uuid)
return ail_uuid return ail_uuid
## WEBSOCKET API - ERRORS ## ## WEBSOCKET API - ERRORS ##
@ -512,8 +559,10 @@ def ping_remote_ail_server(ail_uuid):
if response: if response:
response = response.get('message', False) response = response.get('message', False)
pong = response == 'pong' pong = response == 'pong'
set_ail_server_ping(ail_uuid, pong) else:
return pong pong = False
set_ail_server_ping(ail_uuid, pong)
return pong
## API ## ## API ##
@ -571,6 +620,47 @@ def api_create_ail_instance(json_dict):
pull=pull, push=push) pull=pull, push=push)
return res, 200 return res, 200
def api_edit_ail_instance(json_dict):
ail_uuid = json_dict.get('uuid').replace(' ', '')
if not is_valid_uuid_v4(ail_uuid):
return {"status": "error", "reason": "Invalid ail uuid"}, 400
ail_uuid = sanityze_uuid(ail_uuid)
if not exists_ail_instance(ail_uuid):
return {"status": "error", "reason": "AIL server not found"}, 404
pull = json_dict.get('pull')
push = json_dict.get('push')
if pull is not None:
if pull:
pull = True
else:
pull = False
if push is not None:
if push:
push = True
else:
push = False
edit_ail_instance_pull_push(ail_uuid, pull, push)
description = json_dict.get('description')
edit_ail_instance_description(ail_uuid, description)
ail_url = json_dict.get('url')
if ail_url:
ail_url = ail_url.replace(' ', '')
if not is_valid_websocket_url(ail_url):
return {"status": "error", "reason": "Invalid websocket url"}, 400
edit_ail_instance_url(ail_uuid, ail_url)
ail_key = json_dict.get('key')
if ail_key:
ail_key = ail_key.replace(' ', '')
if not is_valid_websocket_key(ail_key):
return {"status": "error", "reason": "Invalid websocket key"}, 400
edit_ail_instance_key(ail_uuid, ail_key)
return ail_uuid, 200
def api_delete_ail_instance(json_dict): def api_delete_ail_instance(json_dict):
ail_uuid = json_dict.get('uuid', '').replace(' ', '') ail_uuid = json_dict.get('uuid', '').replace(' ', '')
if not is_valid_uuid_v4(ail_uuid): if not is_valid_uuid_v4(ail_uuid):
@ -680,6 +770,31 @@ def unregister_ail_to_sync_queue(ail_uuid, queue_uuid):
def get_all_unregistred_queue_by_ail_instance(ail_uuid): def get_all_unregistred_queue_by_ail_instance(ail_uuid):
return r_serv_sync.sdiff('ail2ail:sync_queue:all', f'ail:instance:sync_queue:{ail_uuid}') return r_serv_sync.sdiff('ail2ail:sync_queue:all', f'ail:instance:sync_queue:{ail_uuid}')
def edit_sync_queue_name(queue_uuid, new_name):
name = get_sync_queue_name(queue_uuid)
if new_name and new_name != name:
r_serv_sync.hset(f'ail2ail:sync_queue:{queue_uuid}', 'name', new_name)
def edit_sync_queue_description(queue_uuid, new_description):
description = get_sync_queue_description(queue_uuid)
if new_description is not None and new_description != description:
r_serv_sync.hset(f'ail2ail:sync_queue:{queue_uuid}', 'description', new_description)
# # TODO: trigger update
def edit_sync_queue_max_size(queue_uuid, new_max_size):
max_size = get_sync_queue_max_size(queue_uuid)
if new_max_size > 0 and new_max_size != max_size:
r_serv_sync.hset(f'ail2ail:sync_queue:{queue_uuid}', 'max_size', new_max_size)
def edit_sync_queue_filter_tags(queue_uuid, new_tags):
tags = set(get_sync_queue_filter(queue_uuid))
new_tags = set(new_tags)
if new_tags and new_tags != tags:
r_serv_sync.delete(f'ail2ail:sync_queue:filter:tags:{queue_uuid}')
for tag in new_tags:
r_serv_sync.sadd(f'ail2ail:sync_queue:filter:tags:{queue_uuid}', tag)
set_last_updated_sync_config()
# # TODO: optionnal name ??? # # TODO: optionnal name ???
# # TODO: SANITYZE TAGS # # TODO: SANITYZE TAGS
def create_sync_queue(name, tags=[], description=None, max_size=100): def create_sync_queue(name, tags=[], description=None, max_size=100):
@ -718,9 +833,9 @@ def api_create_sync_queue(json_dict):
tags = json_dict.get('tags') tags = json_dict.get('tags')
if not tags: if not tags:
{"status": "error", "reason": "no tags provided"}, 400 return {"status": "error", "reason": "no tags provided"}, 400
if not Tag.are_enabled_tags(tags): if not Tag.are_enabled_tags(tags):
{"status": "error", "reason": "Invalid/Disabled tags"}, 400 return {"status": "error", "reason": "Invalid/Disabled tags"}, 400
max_size = json_dict.get('max_size') max_size = json_dict.get('max_size')
if not max_size: if not max_size:
@ -728,7 +843,7 @@ def api_create_sync_queue(json_dict):
try: try:
max_size = int(max_size) max_size = int(max_size)
except ValueError: except ValueError:
{"status": "error", "reason": "Invalid queue size value"}, 400 return {"status": "error", "reason": "Invalid queue size value"}, 400
if not max_size > 0: if not max_size > 0:
return {"status": "error", "reason": "Invalid queue size value"}, 400 return {"status": "error", "reason": "Invalid queue size value"}, 400
@ -736,6 +851,41 @@ def api_create_sync_queue(json_dict):
max_size=max_size) max_size=max_size)
return queue_uuid, 200 return queue_uuid, 200
def api_edit_sync_queue(json_dict):
queue_uuid = json_dict.get('uuid', '').replace(' ', '').replace('-', '')
if not is_valid_uuid_v4(queue_uuid):
return {"status": "error", "reason": "Invalid Queue uuid"}, 400
if not exists_sync_queue(queue_uuid):
return {"status": "error", "reason": "Queue Sync not found"}, 404
description = json_dict.get('description')
description = escape(description)
if description is not None:
edit_sync_queue_description(queue_uuid, description)
queue_name = json_dict.get('name')
if queue_name:
queue_name = escape(queue_name)
edit_sync_queue_name(queue_uuid, queue_name)
tags = json_dict.get('tags')
if tags:
if not Tag.are_enabled_tags(tags):
return {"status": "error", "reason": "Invalid/Disabled tags"}, 400
edit_sync_queue_filter_tags(queue_uuid, tags)
max_size = json_dict.get('max_size')
if max_size:
try:
max_size = int(max_size)
except ValueError:
return {"status": "error", "reason": "Invalid queue size value"}, 400
if not max_size > 0:
return {"status": "error", "reason": "Invalid queue size value"}, 400
edit_sync_queue_max_size(queue_uuid, max_size)
return queue_uuid, 200
def api_delete_sync_queue(json_dict): def api_delete_sync_queue(json_dict):
queue_uuid = json_dict.get('uuid', '').replace(' ', '').replace('-', '') queue_uuid = json_dict.get('uuid', '').replace(' ', '').replace('-', '')
if not is_valid_uuid_v4(queue_uuid): if not is_valid_uuid_v4(queue_uuid):
@ -872,12 +1022,12 @@ if __name__ == '__main__':
# res = get_all_unregistred_queue_by_ail_instance(ail_uuid) # res = get_all_unregistred_queue_by_ail_instance(ail_uuid)
ail_uuid = 'c3c2f3ef-ca53-4ff6-8317-51169b73f731' ail_uuid = 'c3c2f3ef-ca53-4ff6-8317-51169b73f731'
ail_uuid = '03c51929-eeab-4d47-9dc0-c667f94c7d2d' ail_uuid = '2dfeff47-777d-4e70-8c30-07c059307e6a'
# res = ping_remote_ail_server(ail_uuid) # res = ping_remote_ail_server(ail_uuid)
# print(res) # print(res)
# #
res = get_remote_ail_server_version(ail_uuid) res = ping_remote_ail_server(ail_uuid)
#res = _get_remote_ail_server_response(ail_uuid, 'pin') #res = _get_remote_ail_server_response(ail_uuid, 'pin')
print(res) print(res)

View File

@ -6,6 +6,7 @@ import json
import os import os
import sys import sys
import time import time
import traceback
from pubsublogger import publisher from pubsublogger import publisher
from urllib.parse import urljoin from urllib.parse import urljoin
@ -23,7 +24,7 @@ from core import ail_2_ail
#### LOGS #### #### LOGS ####
redis_logger = publisher redis_logger = publisher
redis_logger.port = 6380 redis_logger.port = 6380
redis_logger.channel = 'AIL_SYNC_client' redis_logger.channel = 'Sync'
##-- LOGS --## ##-- LOGS --##
#################################################################### ####################################################################
@ -69,7 +70,6 @@ async def push(websocket, ail_uuid):
else: else:
await asyncio.sleep(10) await asyncio.sleep(10)
async def ail_to_ail_client(ail_uuid, sync_mode, api, ail_key=None): async def ail_to_ail_client(ail_uuid, sync_mode, api, ail_key=None):
if not ail_2_ail.exists_ail_instance(ail_uuid): if not ail_2_ail.exists_ail_instance(ail_uuid):
print('AIL server not found') print('AIL server not found')
@ -91,9 +91,10 @@ async def ail_to_ail_client(ail_uuid, sync_mode, api, ail_key=None):
ail_2_ail.clear_save_ail_server_error(ail_uuid) ail_2_ail.clear_save_ail_server_error(ail_uuid)
try: try:
async with websockets.connect( async with websockets.client.connect(
uri, uri,
ssl=ssl_context, ssl=ssl_context,
#open_timeout=10, websockers 10.0 /!\ python>=3.7
extra_headers={"Authorization": f"{ail_key}"} extra_headers={"Authorization": f"{ail_key}"}
) as websocket: ) as websocket:
@ -123,24 +124,36 @@ async def ail_to_ail_client(ail_uuid, sync_mode, api, ail_key=None):
error_message = str(e) error_message = str(e)
if error_message: if error_message:
sys.stderr.write(error_message) sys.stderr.write(error_message)
redis_logger.warning(f'{error_message}: {ail_uuid}') redis_logger.warning(f'{ail_uuid}: {error_message}')
ail_2_ail.save_ail_server_error(ail_uuid, error_message) ail_2_ail.save_ail_server_error(ail_uuid, error_message)
except websockets.exceptions.InvalidURI as e: except websockets.exceptions.InvalidURI as e:
error_message = f'Invalid AIL url: {e.uri}' error_message = f'Invalid AIL url: {e.uri}'
sys.stderr.write(error_message) sys.stderr.write(error_message)
redis_logger.warning(f'{error_message}: {ail_uuid}') redis_logger.warning(f'{ail_uuid}: {error_message}')
ail_2_ail.save_ail_server_error(ail_uuid, error_message) ail_2_ail.save_ail_server_error(ail_uuid, error_message)
except ConnectionError as e: except ConnectionError as e:
error_message = str(e) error_message = str(e)
sys.stderr.write(error_message) sys.stderr.write(error_message)
redis_logger.info(f'{error_message}: {ail_uuid}') redis_logger.info(f'{ail_uuid}: {error_message}')
ail_2_ail.save_ail_server_error(ail_uuid, error_message)
# OSError: Multiple exceptions
except OSError as e: # # TODO: check if we need to check if is connection error
error_message = str(e)
sys.stderr.write(error_message)
redis_logger.info(f'{ail_uuid}: {error_message}')
ail_2_ail.save_ail_server_error(ail_uuid, error_message) ail_2_ail.save_ail_server_error(ail_uuid, error_message)
except websockets.exceptions.ConnectionClosedOK as e: except websockets.exceptions.ConnectionClosedOK as e:
print('connection closed') print('connection closed')
# except Exception as e: except Exception as err:
# print(e) trace = traceback.format_tb(err.__traceback__)
if len(trace) == 1:
trace = trace[0]
trace = str(trace)
error_message = f'{trace}\n{str(err)}'
sys.stderr.write(error_message)
redis_logger.critical(f'{ail_uuid}: {error_message}')
ail_2_ail.save_ail_server_error(ail_uuid, error_message)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -22,7 +22,7 @@ from core import ail_2_ail
#### LOGS #### #### LOGS ####
redis_logger = publisher redis_logger = publisher
redis_logger.port = 6380 redis_logger.port = 6380
redis_logger.channel = 'AIL_SYNC_Server' redis_logger.channel = 'Sync'
############################# #############################

View File

@ -228,6 +228,7 @@ def is_enabled_taxonomie_tag(tag, enabled_taxonomies=None):
return False return False
if not is_taxonomie_tag_enabled(taxonomie, tag): if not is_taxonomie_tag_enabled(taxonomie, tag):
return False return False
return True
def is_enabled_galaxy_tag(tag, enabled_galaxies=None): def is_enabled_galaxy_tag(tag, enabled_galaxies=None):
if not enabled_galaxies: if not enabled_galaxies:
@ -241,6 +242,16 @@ def is_enabled_galaxy_tag(tag, enabled_galaxies=None):
return False return False
return True return True
def sort_tags_taxonomies_galaxies(tags):
taxonomies_tags = []
galaxies_tags = []
for tag in tags:
if is_taxonomie_tag(tag):
taxonomies_tags.append(tag)
else:
galaxies_tags.append(tag)
return taxonomies_tags, galaxies_tags
#### #### #### ####
def is_tag_in_all_tag(tag): def is_tag_in_all_tag(tag):

View File

@ -123,13 +123,11 @@ def ail_server_add():
if register_key: if register_key:
input_dict['key'] = request.form.get("ail_key") input_dict['key'] = request.form.get("ail_key")
print(input_dict)
res = ail_2_ail.api_create_ail_instance(input_dict) res = ail_2_ail.api_create_ail_instance(input_dict)
if res[1] != 200: if res[1] != 200:
return create_json_response(res[0], res[1]) return create_json_response(res[0], res[1])
return redirect(url_for('ail_2_ail_sync.ail_server_view', uuid=res)) return redirect(url_for('ail_2_ail_sync.ail_server_view', uuid=res[0]))
else: else:
return render_template("add_ail_server.html") return render_template("add_ail_server.html")
@ -138,7 +136,29 @@ def ail_server_add():
@login_required @login_required
@login_admin @login_admin
def ail_server_edit(): def ail_server_edit():
ail_uuid = request.args.get('ail_uuid') ail_uuid = request.args.get('uuid')
if request.method == 'POST':
ail_uuid = request.form.get("ail_uuid")
ail_key = request.form.get("ail_key")
url = request.form.get("ail_url")
description = request.form.get("ail_description")
pull = request.form.get("ail_pull", False)
push = request.form.get("ail_push", False)
if pull:
pull = True
if push:
push = True
input_dict = {"uuid": ail_uuid, "url": url,
"description": description,
"key": ail_key,
"pull": pull, "push": push}
res = ail_2_ail.api_edit_ail_instance(input_dict)
return redirect(url_for('ail_2_ail_sync.ail_server_view', uuid=res[0]))
else:
server_metadata = ail_2_ail.get_ail_instance_metadata(ail_uuid)
return render_template("edit_ail_server.html", server_metadata=server_metadata)
@ail_2_ail_sync.route('/settings/ail_2_ail/server/delete', methods=['GET']) @ail_2_ail_sync.route('/settings/ail_2_ail/server/delete', methods=['GET'])
@login_required @login_required
@ -193,8 +213,8 @@ def ail_server_sync_queues_unregister():
#### SYNC QUEUE #### #### SYNC QUEUE ####
@ail_2_ail_sync.route('/settings/ail_2_ail/sync_queues', methods=['GET']) @ail_2_ail_sync.route('/settings/ail_2_ail/sync_queues', methods=['GET'])
# @login_required @login_required
# @login_admin @login_admin
def sync_queues(): def sync_queues():
ail_uuid = request.args.get('ail_uuid') ail_uuid = request.args.get('ail_uuid')
l_queues = ail_2_ail.get_all_queues_metadata() l_queues = ail_2_ail.get_all_queues_metadata()
@ -202,8 +222,8 @@ def sync_queues():
ail_uuid=ail_uuid, l_queues=l_queues) ail_uuid=ail_uuid, l_queues=l_queues)
@ail_2_ail_sync.route('/settings/ail_2_ail/sync_queue/view', methods=['GET']) @ail_2_ail_sync.route('/settings/ail_2_ail/sync_queue/view', methods=['GET'])
# @login_required @login_required
# @login_admin @login_admin
def sync_queue_view(): def sync_queue_view():
queue_uuid = request.args.get('uuid') queue_uuid = request.args.get('uuid')
queue_metadata = ail_2_ail.get_sync_queue_metadata(queue_uuid) queue_metadata = ail_2_ail.get_sync_queue_metadata(queue_uuid)
@ -245,19 +265,61 @@ def sync_queue_add():
if res[1] != 200: if res[1] != 200:
return create_json_response(res[0], res[1]) return create_json_response(res[0], res[1])
return redirect(url_for('ail_2_ail_sync.sync_queue_view', uuid=res)) return redirect(url_for('ail_2_ail_sync.sync_queue_view', uuid=res[0]))
else: else:
return render_template("add_sync_queue.html", tags_selector_data=Tag.get_tags_selector_data()) return render_template("add_sync_queue.html", tags_selector_data=Tag.get_tags_selector_data())
@ail_2_ail_sync.route('/settings/ail_2_ail/sync_queue/edit', methods=['GET', 'POST']) @ail_2_ail_sync.route('/settings/ail_2_ail/sync_queue/edit', methods=['GET', 'POST'])
# @login_required @login_required
# @login_admin @login_admin
def sync_queue_edit(): def sync_queue_edit():
return '' if request.method == 'POST':
queue_uuid = request.form.get("queue_uuid")
queue_name = request.form.get("queue_name")
description = request.form.get("queue_description")
max_size = request.form.get("queue_max_size")
taxonomies_tags = request.form.get('taxonomies_tags')
if taxonomies_tags:
try:
taxonomies_tags = json.loads(taxonomies_tags)
except Exception:
taxonomies_tags = []
else:
taxonomies_tags = []
galaxies_tags = request.form.get('galaxies_tags')
if galaxies_tags:
try:
galaxies_tags = json.loads(galaxies_tags)
except Exception:
galaxies_tags = []
tags = taxonomies_tags + galaxies_tags
input_dict = {"uuid": queue_uuid,
"name": queue_name,
"tags": tags,
"description": description,
"max_size": max_size}
res = ail_2_ail.api_edit_sync_queue(input_dict)
if res[1] != 200:
return create_json_response(res[0], res[1])
return redirect(url_for('ail_2_ail_sync.sync_queue_view', uuid=res[0]))
else:
queue_uuid = request.args.get('uuid')
queue_metadata = ail_2_ail.get_sync_queue_metadata(queue_uuid)
taxonomies_tags, galaxies_tags = Tag.sort_tags_taxonomies_galaxies(queue_metadata['tags'])
tags_selector_data = Tag.get_tags_selector_data()
tags_selector_data['taxonomies_tags'] = taxonomies_tags
tags_selector_data['galaxies_tags'] = galaxies_tags
return render_template("edit_sync_queue.html", queue_metadata=queue_metadata,
bootstrap_label=bootstrap_label,
tags_selector_data=tags_selector_data)
@ail_2_ail_sync.route('/settings/ail_2_ail/sync_queue/delete', methods=['GET']) @ail_2_ail_sync.route('/settings/ail_2_ail/sync_queue/delete', methods=['GET'])
# @login_required @login_required
# @login_admin @login_admin
def sync_queue_delete(): def sync_queue_delete():
queue_uuid = request.args.get('uuid') queue_uuid = request.args.get('uuid')
input_dict = {"uuid": queue_uuid} input_dict = {"uuid": queue_uuid}

View File

@ -103,13 +103,8 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$('#nav_sync').removeClass("text-muted"); $('#nav_sync').removeClass("text-muted");
$("#nav_ail_servers").addClass("active"); $("#navsync_queues").addClass("active");
$("#div_register_key").hide();
$('#register_key').on("change", function () {
register_key_input_controler();
});
}); });
function toggle_sidebar(){ function toggle_sidebar(){
@ -129,8 +124,6 @@ function toggle_sidebar(){
function SubmitCreateQueue() { function SubmitCreateQueue() {
var tags = ltags.getValue(); var tags = ltags.getValue();
var tagsgalaxy = ltagsgalaxies.getValue(); var tagsgalaxy = ltagsgalaxies.getValue();
console.log(tags);
console.log(tagsgalaxy);
$('#ltags').val(tags); $('#ltags').val(tags);
$('#ltagsgalaxies').val(tagsgalaxy); $('#ltagsgalaxies').val(tagsgalaxy);
return true; return true;

View File

@ -0,0 +1,145 @@
<!DOCTYPE html>
<html>
<head>
<title>AIL-Framework</title>
<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png')}}">
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
<!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
</head>
<body>
{% include 'nav_bar.html' %}
<div class="container-fluid">
<div class="row">
{% include 'settings/menu_sidebar.html' %}
<div class="col-12 col-lg-10" id="core_content">
<div class="card my-3">
<div class="card-header bg-dark text-white">
<h5 class="card-title">Edit AIL Server</h5>
</div>
<div class="card-body">
<form action="{{ url_for('ail_2_ail_sync.ail_server_edit') }}" method='post'>
<div class="row">
<div class="col-12 col-xl-9">
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-dark text-white"><i class="fas fa-quote-right"></i></div>
</div>
<div class="form-control">
{{ server_metadata['uuid'] }}
<input id="ail_uuid" name="ail_uuid" type="text" value="{{ server_metadata['uuid'] }}" hidden>
</div>
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-secondary text-white"><i class="fas fa-server"></i></div>
</div>
<input id="ail_url" class="form-control" type="text" name="ail_url" value="{{ server_metadata['url'] }}" placeholder="AIL Server URL">
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-info text-white"><i class="fas fa-pencil-alt"></i></div>
</div>
<textarea id="ail_description" name="ail_description" class="form-control" placeholder="AIL Server Description (optional)" rows="3">{{ server_metadata['description'] }}</textarea>
</div>
<h5 class="mt-2 text-secondary">
SYNC Modes:
</h5>
<div class="row">
<div class="col-12 col-xl-6">
<div class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="True" id="pull" name="ail_pull" {%if server_metadata['pull']%}checked{%endif%}>
<label class="custom-control-label" for="ail_pull"><h5>PULL</h5></label>
</div>
</div>
<div class="col-12 col-xl-6">
<div class="custom-control custom-checkbox">
<input class="custom-control-input" type="checkbox" value="True" id="ail_push" name="ail_push" {%if server_metadata['push']%}checked{%endif%}>
<label class="custom-control-label" for="ail_push"><h5 class="">PUSH</h5></label>
</div>
</div>
</div>
<h5 class="mt-2 text-secondary">
Server Key <i class="fas fa-key"></i>:
</h5>
<div id="div_register_key">
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-danger text-white"><i class="fas fa-key"></i></div>
</div>
<input id="ail_key" class="form-control" type="text" minlength="56" maxlength="56" name="ail_key" value="{{ server_metadata['api_key'] }}" placeholder="AIL key">
</div>
</div>
</div>
<div class="col-12 col-xl-3">
Edit AIL Server
</div>
</div>
<br>
<button class="btn btn-primary mt-2">
<i class="fas fa-plus"></i> Edit AIL Server
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function(){
$('#nav_sync').removeClass("text-muted");
$("#nav_ail_servers").addClass("active");
});
function toggle_sidebar(){
if($('#nav_menu').is(':visible')){
$('#nav_menu').hide();
$('#side_menu').removeClass('border-right')
$('#side_menu').removeClass('col-lg-2')
$('#core_content').removeClass('col-lg-10')
}else{
$('#nav_menu').show();
$('#side_menu').addClass('border-right')
$('#side_menu').addClass('col-lg-2')
$('#core_content').addClass('col-lg-10')
}
}
</script>

View File

@ -0,0 +1,144 @@
<!DOCTYPE html>
<html>
<head>
<title>AIL-Framework</title>
<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png')}}">
<!-- Core CSS -->
<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ url_for('static', filename='css/tags.css') }}" rel="stylesheet" type="text/css" />
<!-- JS -->
<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/tags.js') }}"></script>
</head>
<body>
{% include 'nav_bar.html' %}
<div class="container-fluid">
<div class="row">
{% include 'settings/menu_sidebar.html' %}
<div class="col-12 col-lg-10" id="core_content">
<div class="card my-3">
<div class="card-header bg-dark text-white">
<h5 class="card-title">Edit SYNC Queue</h5>
</div>
<div class="card-body">
<form action="{{ url_for('ail_2_ail_sync.sync_queue_edit') }}" method='post' onsubmit="SubmitCreateQueue();">
<div class="row">
<div class="col-12 col-xl-9">
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-dark text-white"><i class="fas fa-quote-right"></i></div>
</div>
<div class="form-control">
{{ queue_metadata['uuid'] }}
<input id="queue_uuid" name="queue_uuid" type="text" value="{{ queue_metadata['uuid'] }}" hidden>
</div>
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-dark text-white"><i class="fas fa-quote-right"></i></div>
</div>
<input id="queue_name" name="queue_name" class="form-control" value="{{ queue_metadata['name'] }}" placeholder="Queue Name" type="text" required>
</div>
<div class="input-group form-group mb-2">
<div class="input-group-prepend">
<span class="input-group-text bg-success"><i class="fas fa-water"></i></span>
</div>
<input class="form-control" type="number" id="queue_max_size" name="queue_max_size" min="1" value="{{ queue_metadata['max_size'] }}" required>
<div class="input-group-append">
<span class="input-group-text">Queue Max Size</span>
</div>
</div>
<div class="input-group mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text bg-info text-white"><i class="fas fa-pencil-alt"></i></div>
</div>
<textarea id="queue_description" name="queue_description" class="form-control" placeholder="Sync Queue Description (optional)" rows="3">{{ queue_metadata['description'] }}</textarea>
</div>
<div class="card my-4">
<div class="card-header bg-secondary text-white">
<b>Tags Filter</b>
</div>
<div class="card-body">
{% include 'tags/block_tags_selector.html' %}
</div>
</div>
</div>
<div class="col-12 col-xl-3">
SYNC: Edit Sync Queue
</div>
</div>
<br>
<button class="btn btn-primary mt-2">
<i class="fas fa-plus"></i> Edit Sync Queue
</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function(){
$('#nav_sync').removeClass("text-muted");
$("#navsync_queues").addClass("active");
});
function toggle_sidebar(){
if($('#nav_menu').is(':visible')){
$('#nav_menu').hide();
$('#side_menu').removeClass('border-right')
$('#side_menu').removeClass('col-lg-2')
$('#core_content').removeClass('col-lg-10')
}else{
$('#nav_menu').show();
$('#side_menu').addClass('border-right')
$('#side_menu').addClass('col-lg-2')
$('#core_content').addClass('col-lg-10')
}
}
function SubmitCreateQueue() {
var tags = ltags.getValue();
var tagsgalaxy = ltagsgalaxies.getValue();
$('#ltags').val(tags);
$('#ltagsgalaxies').val(tagsgalaxy);
return true;
}
</script>

View File

@ -85,13 +85,29 @@
<tr> <tr>
<td class="text-right"><b>Pull</b></td> <td class="text-right"><b>Pull</b></td>
<td> <td>
{{server_metadata['pull']}} {% if server_metadata['pull'] %}
<span style="color:Green;">
<i class="fas fa-check-circle"></i> Enabled
</span>
{% else %}
<span class="text-secondary">
<i class="fas fa-times-circle"></i> Disabled
</span>
{% endif %}
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="text-right"><b>Push</b></td> <td class="text-right"><b>Push</b></td>
<td> <td>
{{server_metadata['push']}} {% if server_metadata['push'] %}
<span style="color:Green;">
<i class="fas fa-check-circle"></i> Enabled
</span>
{% else %}
<span class="text-secondary">
<i class="fas fa-times-circle"></i> Disabled
</span>
{% endif %}
</td> </td>
</tr> </tr>
<tr> <tr>
@ -121,7 +137,12 @@
<a href="{{ url_for('ail_2_ail_sync.ail_server_delete') }}?uuid={{server_metadata['uuid']}}"> <a href="{{ url_for('ail_2_ail_sync.ail_server_delete') }}?uuid={{server_metadata['uuid']}}">
<button type="button" class="btn btn-danger"> <button type="button" class="btn btn-danger">
<i class="fas fa-trash-alt"></i> <b>Delete AIL Server</b> <i class="fas fa-trash-alt"></i> <b>Delete AIL Server</b>
</button> </button>
</a>
<a href="{{ url_for('ail_2_ail_sync.ail_server_edit') }}?uuid={{server_metadata['uuid']}}">
<button type="button" class="btn btn-info">
<i class="fas fa-pencil-alt"></i> <b>Edit</b>
</button>
</a> </a>
</div> </div>

View File

@ -72,6 +72,11 @@
<i class="fas fa-trash-alt"></i> <b>Delete Sync Queue</b> <i class="fas fa-trash-alt"></i> <b>Delete Sync Queue</b>
</button> </button>
</a> </a>
<a href="{{ url_for('ail_2_ail_sync.sync_queue_edit') }}?uuid={{queue_metadata['uuid']}}">
<button type="button" class="btn btn-info">
<i class="fas fa-pencil-alt"></i> <b>Edit</b>
</button>
</a>
</div> </div>
<div class="card"> <div class="card">

View File

@ -49,9 +49,20 @@ var ltagsgalaxies;
$.getJSON("{{ url_for('tags_ui.tag_taxonomies_tags_enabled_json') }}", $.getJSON("{{ url_for('tags_ui.tag_taxonomies_tags_enabled_json') }}",
function(data) { function(data) {
{% if 'taxonomies_tags' in tags_selector_data %}
var valueData = [
{% for tag in tags_selector_data['taxonomies_tags'] %}
'{{tag|safe}}',
{% endfor %}
];
{% else %}
var valueData = [];
{% endif %}
ltags = $('#ltags').tagSuggest({ ltags = $('#ltags').tagSuggest({
data: data, data: data,
value: valueData,
maxDropHeight: 200, maxDropHeight: 200,
name: 'ltags' name: 'ltags'
}); });
@ -59,9 +70,19 @@ $.getJSON("{{ url_for('tags_ui.tag_taxonomies_tags_enabled_json') }}",
$.getJSON("{{ url_for('tags_ui.tag_galaxies_tags_enabled_json') }}", $.getJSON("{{ url_for('tags_ui.tag_galaxies_tags_enabled_json') }}",
function(data) { function(data) {
{% if 'galaxies_tags' in tags_selector_data %}
var valueData = [
{% for tag in tags_selector_data['galaxies_tags'] %}
'{{tag|safe}}',
{% endfor %}
];
{% else %}
var valueData = [];
{% endif %}
ltagsgalaxies = $('#ltagsgalaxies').tagSuggest({ ltagsgalaxies = $('#ltagsgalaxies').tagSuggest({
data: data, data: data,
value: valueData,
maxDropHeight: 200, maxDropHeight: 200,
name: 'ltagsgalaxies' name: 'ltagsgalaxies'
}); });