mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-22 14:17:16 +00:00
chg: [flask] use the same cookie name + cache git commits, tags and branch name
This commit is contained in:
parent
7efc26bab9
commit
21686428f0
4 changed files with 69 additions and 9 deletions
|
@ -38,6 +38,11 @@ def _set_ail_uuid():
|
||||||
r_serv_db.set('ail:uuid', ail_uuid)
|
r_serv_db.set('ail:uuid', ail_uuid)
|
||||||
return ail_uuid
|
return ail_uuid
|
||||||
|
|
||||||
|
def get_ail_uuid_int():
|
||||||
|
ail_uuid = get_ail_uuid()
|
||||||
|
header_uuid = ail_uuid.replace('-', '')
|
||||||
|
return uuid.UUID(hex=header_uuid, version=4).int
|
||||||
|
|
||||||
def is_valid_uuid_v4(header_uuid):
|
def is_valid_uuid_v4(header_uuid):
|
||||||
try:
|
try:
|
||||||
header_uuid = header_uuid.replace('-', '')
|
header_uuid = header_uuid.replace('-', '')
|
||||||
|
|
|
@ -1,7 +1,19 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*-coding:UTF-8 -*
|
# -*-coding:UTF-8 -*
|
||||||
|
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append(os.environ['AIL_BIN'])
|
||||||
|
##################################
|
||||||
|
# Import Project packages
|
||||||
|
##################################
|
||||||
|
from lib.ConfigLoader import ConfigLoader
|
||||||
|
|
||||||
|
config_loader = ConfigLoader()
|
||||||
|
r_cache = config_loader.get_redis_conn("Redis_Cache")
|
||||||
|
config_loader = None
|
||||||
|
|
||||||
TERMINAL_RED = '\033[91m'
|
TERMINAL_RED = '\033[91m'
|
||||||
TERMINAL_YELLOW = '\33[93m'
|
TERMINAL_YELLOW = '\33[93m'
|
||||||
|
@ -154,15 +166,50 @@ def get_last_tag_from_remote(verbose=False):
|
||||||
print('{}{}{}'.format(TERMINAL_RED, process.stderr.decode(), TERMINAL_DEFAULT))
|
print('{}{}{}'.format(TERMINAL_RED, process.stderr.decode(), TERMINAL_DEFAULT))
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
def clear_git_meta_cache():
|
||||||
|
r_cache.delete('git:meta')
|
||||||
|
|
||||||
|
def _get_git_meta():
|
||||||
|
if r_cache.exists('git:meta'):
|
||||||
|
dict_git = {'current_branch': r_cache.hget('git:meta', 'branch'),
|
||||||
|
'is_clone': r_cache.hget('git:meta', 'is_clone') == 'True',
|
||||||
|
'is_working_directory_clean': is_working_directory_clean(),
|
||||||
|
'current_commit': r_cache.hget('git:meta', 'commit'),
|
||||||
|
'last_remote_commit': r_cache.hget('git:meta', 'remote_commit'),
|
||||||
|
'last_local_tag': r_cache.hget('git:meta', 'tag'),
|
||||||
|
'last_remote_tag': r_cache.hget('git:meta', 'remote_tag')}
|
||||||
|
for k in dict_git:
|
||||||
|
if not dict_git[k] and dict_git[k] is not False:
|
||||||
|
return {}
|
||||||
|
return dict_git
|
||||||
|
else:
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_git_metadata():
|
def get_git_metadata():
|
||||||
dict_git = {}
|
dict_git = _get_git_meta()
|
||||||
dict_git['current_branch'] = get_current_branch()
|
if not dict_git:
|
||||||
dict_git['is_clone'] = is_not_fork(REPO_ORIGIN)
|
branch = get_current_branch()
|
||||||
dict_git['is_working_directory_clean'] = is_working_directory_clean()
|
commit = get_last_commit_id_from_local()
|
||||||
dict_git['current_commit'] = get_last_commit_id_from_local()
|
remote_commit = get_last_commit_id_from_remote()
|
||||||
dict_git['last_remote_commit'] = get_last_commit_id_from_remote()
|
is_clone = is_not_fork(REPO_ORIGIN)
|
||||||
dict_git['last_local_tag'] = get_last_tag_from_local()
|
tag = get_last_tag_from_local()
|
||||||
dict_git['last_remote_tag'] = get_last_tag_from_remote()
|
remote_tag = get_last_tag_from_remote()
|
||||||
|
|
||||||
|
r_cache.hset('git:meta', 'branch', branch)
|
||||||
|
r_cache.hset('git:meta', 'commit', commit)
|
||||||
|
r_cache.hset('git:meta', 'remote_commit', remote_commit)
|
||||||
|
r_cache.hset('git:meta', 'is_clone', str(is_clone))
|
||||||
|
r_cache.hset('git:meta', 'tag', tag)
|
||||||
|
r_cache.hset('git:meta', 'remote_tag', remote_tag)
|
||||||
|
r_cache.expire('git:meta', 108000)
|
||||||
|
|
||||||
|
dict_git['current_branch'] = branch
|
||||||
|
dict_git['is_clone'] = is_clone
|
||||||
|
dict_git['is_working_directory_clean'] = is_working_directory_clean()
|
||||||
|
dict_git['current_commit'] = commit
|
||||||
|
dict_git['last_remote_commit'] = remote_commit
|
||||||
|
dict_git['last_local_tag'] = tag
|
||||||
|
dict_git['last_remote_tag'] = remote_tag
|
||||||
|
|
||||||
if dict_git['current_commit'] != dict_git['last_remote_commit']:
|
if dict_git['current_commit'] != dict_git['last_remote_commit']:
|
||||||
dict_git['new_git_update_available'] = True
|
dict_git['new_git_update_available'] = True
|
||||||
|
|
|
@ -11,6 +11,7 @@ sys.path.append(os.environ['AIL_BIN'])
|
||||||
##################################
|
##################################
|
||||||
from lib import ail_updates
|
from lib import ail_updates
|
||||||
from lib.ConfigLoader import ConfigLoader
|
from lib.ConfigLoader import ConfigLoader
|
||||||
|
from packages.git_status import clear_git_meta_cache
|
||||||
|
|
||||||
class AIL_Updater(object):
|
class AIL_Updater(object):
|
||||||
"""docstring for AIL_Updater."""
|
"""docstring for AIL_Updater."""
|
||||||
|
@ -24,6 +25,7 @@ class AIL_Updater(object):
|
||||||
|
|
||||||
self.f_version = float(self.version[1:])
|
self.f_version = float(self.version[1:])
|
||||||
self.current_f_version = ail_updates.get_ail_float_version()
|
self.current_f_version = ail_updates.get_ail_float_version()
|
||||||
|
clear_git_meta_cache()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -26,8 +26,11 @@ sys.path.append(os.environ['AIL_BIN'])
|
||||||
from lib.ConfigLoader import ConfigLoader
|
from lib.ConfigLoader import ConfigLoader
|
||||||
from lib.ail_users import AILUser, get_session_user
|
from lib.ail_users import AILUser, get_session_user
|
||||||
from lib import Tag
|
from lib import Tag
|
||||||
|
from lib import ail_core
|
||||||
from lib import ail_logger
|
from lib import ail_logger
|
||||||
|
|
||||||
|
from packages.git_status import clear_git_meta_cache
|
||||||
|
|
||||||
# Import config
|
# Import config
|
||||||
import Flask_config
|
import Flask_config
|
||||||
|
|
||||||
|
@ -143,7 +146,7 @@ app.register_blueprint(api_rest, url_prefix=baseUrl)
|
||||||
# ========= =========#
|
# ========= =========#
|
||||||
|
|
||||||
# ========= Cookie name ========
|
# ========= Cookie name ========
|
||||||
app.config.update(SESSION_COOKIE_NAME='ail_framework_{}'.format(uuid.uuid4().int))
|
app.config.update(SESSION_COOKIE_NAME='ail_framework_{}'.format(ail_core.get_ail_uuid_int()))
|
||||||
|
|
||||||
# ========= session ========
|
# ========= session ========
|
||||||
app.secret_key = str(random.getrandbits(256))
|
app.secret_key = str(random.getrandbits(256))
|
||||||
|
@ -313,6 +316,9 @@ default_taxonomies = ["infoleak", "gdpr", "fpf", "dark-web"]
|
||||||
for taxonomy in default_taxonomies:
|
for taxonomy in default_taxonomies:
|
||||||
Tag.enable_taxonomy_tags(taxonomy)
|
Tag.enable_taxonomy_tags(taxonomy)
|
||||||
|
|
||||||
|
# ========== GIT Cache ============
|
||||||
|
clear_git_meta_cache()
|
||||||
|
|
||||||
# rrrr = [str(p) for p in app.url_map.iter_rules()]
|
# rrrr = [str(p) for p in app.url_map.iter_rules()]
|
||||||
# for p in rrrr:
|
# for p in rrrr:
|
||||||
# print(p)
|
# print(p)
|
||||||
|
|
Loading…
Reference in a new issue