Skip to content

Commit

Permalink
Merge pull request #157 from Sakuten/feature/150-check-ids-hash-in-dr…
Browse files Browse the repository at this point in the history
…aw-script

scripts/draw.pyで`ids.json`のハッシュ確認をした
  • Loading branch information
Cj-bc authored Sep 14, 2018
2 parents 145ab10 + 7cf019b commit 0248a7e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import argparse
from urllib.request import Request, urlopen
from urllib.error import HTTPError
import hashlib

parser = argparse.ArgumentParser(
description='Draw currently available lotteries')
Expand Down Expand Up @@ -50,6 +51,14 @@ def post_json(path, data=None, token=None):
return json.loads(response_body)


with open(args.list, 'r') as f:
local_checksum = hashlib.sha256(f.read().encode()).hexdigest()
server_checksum = post_json('ids_hash')['sha256']
if local_checksum != server_checksum:
print('local ids.json is different from servers', file=sys.stderr)
sys.exit(70) # we should decide error code


# Login as admin
admin_cred = {
'id': admin_ids['secret_id'],
Expand Down

0 comments on commit 0248a7e

Please sign in to comment.