-
Notifications
You must be signed in to change notification settings - Fork 3
/
notary.py
106 lines (87 loc) · 3.17 KB
/
notary.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import argparse
from notary_client import NotaryClient
import json
notary = None
def login_if_needed(notary, command):
pass
def main_method(cmd_str=None):
'''
main method of notary.
Parameters
----------
cmd_str takes the command line input.
Returns
-------
'''
global notary
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=[ 'register', 'confirm', 'notarize', 'login', 'notarystatus',
'uploadfile', 'downloadfile'],
help="Name of the command.")
parser.add_argument("-password", type=str, help="the password used to access the wallet.")
parser.add_argument("-email", type=str, help="the email address of the registered user.")
parser.add_argument("-file", type=str, help="Fully qualified name of the file.")
parser.add_argument("-metadata", type=str, help="File containing metadata of the file to notarize.")
parser.add_argument("-confirm_url", type=str, help="Confirmation URL to confirm an account.")
parser.add_argument("-document_hash", type=str, help="Document hash of a document")
if cmd_str is None:
args = parser.parse_args()
else:
args = parser.parse_args(cmd_str)
if not args.password:
print("Password is required!")
return
if notary is None:
notary = NotaryClient("./notaryconfig.ini", args.password)
command = args.command
print "Running " + command + " command"
if command == "register":
if not args.email:
print "register command needs email address"
else:
print args.email
result = notary.register_user(args.email)
print result
return result
elif command == "notarize":
if not args.metadata:
print "notarize command needs metadata file"
return
if not args.file:
print "notarize command needs file"
return
# print args.file
# print args.metadata
metadata = json.loads(args.metadata)
return notary.notarize_file(args.file,
metadata)
elif command == "uploadfile":
if not args.file:
print "upload command needs file"
return
# print args.file
return notary.upload_file(args.file)
elif command == "downloadfile":
if not args.document_hash:
print "download command needs document hash value"
return
if not args.file:
print "download command needs file"
return
# print args.file
return notary.download_file(args.document_hash,args.file)
elif command == "login":
return notary.authenticate()
elif command == "notarystatus":
if not args.document_hash:
print "confirm command needs document_hash"
else:
print args.document_hash
status = notary.get_notarization_status(args.document_hash)
print "The Document status is"
print status
return status
else:
print "no command"
if __name__ == "__main__":
main_method()