-
Notifications
You must be signed in to change notification settings - Fork 0
/
universal_genius.py
executable file
·77 lines (58 loc) · 2.58 KB
/
universal_genius.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
#!python
import logging, argparse, sys, os, time
from DataStore import DataStore
from rpc import rpc
from pprint import pprint
def ParseArgs():
parser = argparse.ArgumentParser(description='Unified user unlocker',
epilog='--\nHave a great day from Universal Genious')
parser.add_argument('--db', help='Database TNS name')
# , required=True
parser.add_argument('--list-map', help='List mapping of DB to Host:Sid', action='store_true')
parser.add_argument('--put', help="Add/Update mapping, format: --put DB:host1,port2;host2:port2")
parser.add_argument('--delete', help="Delete mapping, format: --delete DB")
parser.add_argument('--unlock', help="Unlock account only", action='store_true')
parser.add_argument('--reset', help="Unlock and reset passord for account (new password will be generated.", action='store_true')
# parser.add_argument('--key', help='Partition key')
# parser.add_argument('--remap', help='Partition key')
parsed_args = parser.parse_args()
return parsed_args
def init_logging():
logPath = "logs"
vlogger = logging.getLogger()
vlogger.setLevel(logging.DEBUG)
logFormatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
ch = logging.StreamHandler()
ch.setFormatter(logFormatter)
ch.setLevel(logging.INFO)
vlogger.addHandler(ch)
fileName = "universal_genius_" + time.strftime("%Y%m%d")
fh = logging.FileHandler("{0}/{1}.log".format(logPath, fileName), mode='a')
fh.setLevel(logging.DEBUG)
fh.setFormatter(logFormatter)
vlogger.addHandler(fh)
vlogger.info("Logger initizlized")
return vlogger
def main():
args = ParseArgs()
logger = init_logging()
logger.info("User [{}] running this script.".format(os.getlogin()))
db = DataStore("pickle.pck", logger)
if args.list_map:
db.list()
if args.put:
logger.info("Adding mapping, {}".format(args.put))
db.set(*db.parseCommandLine(args.put))
if args.delete:
logger.info("Deleting mapping for DB: {}".format(args.delete))
db.delete(args.delete.upper())
if args.unlock or args.reset:
# check if we have mapping for DB
if db.get(args.db.upper()):
logger.info("Trying to unlock/resep password for DB: {}.".format(args.db))
rpc_call = rpc(db.get(args.db), logger)
res = rpc_call.proceed_changes(args.unlock, args.reset)
else:
logger.critical("We don't have mapping for DB: {}".format(args.db))
if __name__ == "__main__":
main()