check_policy.py
1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import hashlib
from firebase_admin import db
from firebase_admin import credentials
import firebase_admin
import csv
cred = credentials.Certificate('wello_firebase_SDKKey.json')
firebase_admin.initialize_app(cred, {'databaseURL': 'https://capstone-vip.firebaseio.com/'})
ref = db.reference()
policies = ref.get()
## compare dict
policy_dict = dict()
def policy_hash_writer(policies):
with open('./hash_policy.csv', 'w', encoding='utf-8', newline='') as csvfile:
wr = csv.writer(csvfile)
for policy in policies:
sha = hashlib.sha256()
sha.update(str(policy).encode('utf-8'))
wr.writerow([policy["Value"], sha.hexdigest()])
def policy_db_reader():
for policy in policies:
if policy["Value"] in policy_dict.keys():
sha = hashlib.sha256()
sha.update(str(policy).encode('utf-8'))
if policy_dict[policy["Value"]] != sha.hexdigest():
print("change contents : ", policy["Value"], ".", policy["Policy"])
else:
print("new policy : ", policy["Value"], ". ", policy["Policy"])
def policy_hash_reader():
with open('./hash_policy.csv', 'r', encoding='utf-8') as csvfile:
rdr = csv.reader(csvfile)
for r in rdr:
policy_dict[r[0]] = r[1]
#policy_hash_writer(policies)
policy_hash_reader()
policy_db_reader()