Skip to content

Commit

Permalink
Add check for meta.json file (#251)
Browse files Browse the repository at this point in the history
* Add check for meta.json file

* Moved check_meta_file function to snare_helper
  • Loading branch information
afeena authored Mar 4, 2020
1 parent 501c72a commit 54a0750
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 54a0750

Please sign in to comment.