Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for meta.json file #251

Merged
merged 2 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/snare
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import pip
from snare.server import HttpRequestHandler
from snare.utils.logger import Logger
from snare.utils import snare_helpers
from snare.utils.snare_helpers import str_to_bool, print_color
from snare.utils.snare_helpers import str_to_bool, print_color, check_meta_file


def create_initial_config():
Expand Down Expand Up @@ -176,6 +176,11 @@ if __name__ == '__main__':

with open(os.path.join(full_page_path, 'meta.json')) as meta:
meta_info = json.load(meta)

if not check_meta_file(meta_info):
print_color("Error found in meta.json. Please clone the pages again.", "ERROR")
exit()

if not os.path.exists(os.path.join(base_page_path, args.page_dir,
os.path.join(meta_info[args.index_page]['hash']))):
print_color('can\'t create meta tag', 'WARNING')
Expand Down
9 changes: 9 additions & 0 deletions snare/utils/snare_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ def add_meta_tag(page_dir, index_page, config):
file.write(html)


def check_meta_file(meta_info):
for k, v in meta_info.items():
if 'hash' in v and 'content_type' in v:
continue
else:
return False
return True


def parse_timeout(timeout):
timeouts_coeff = {
'M': 60,
Expand Down