-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommonUtils.py
71 lines (46 loc) · 1.87 KB
/
CommonUtils.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
import json
import time
from datetime import datetime
from itertools import zip_longest
is_dev = False
def open_config_file():
config_file_name = 'cfg-dev.json' if is_dev else 'cfg.json'
with open(config_file_name) as config_file:
return json.load(config_file)
def write_config_file(cfg):
config_file_name = 'cfg-dev.json' if is_dev else 'cfg.json'
with open(config_file_name, 'r+') as config:
config.seek(0)
config.write(json.dumps(cfg))
config.truncate()
def open_insights_file():
with open('aws-sechub-default-insights.json') as insights_file:
return json.load(insights_file)
def open_insights_arn_file():
with open('default-insights-arn.json') as insights_file:
return json.load(insights_file)
def write_to_insights_arn_file(arns):
with open('default-insights-arn.json', 'r+') as config:
config.seek(0)
config.write(json.dumps(arns))
config.truncate()
def write_to_log(log_item):
f = open('log.txt', 'a+')
f.write(str(datetime.now()) + ': ' + str(log_item) + '\n')
f.close()
def get_current_utc_datetime():
return str(datetime.utcnow().replace(microsecond=0))
def datetime_to_iso8601_format(time):
date_time_obj = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
return str(date_time_obj.strftime('%Y-%m-%dT%H:%M:%SZ'))
def datetime_string_to_object(time):
return datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
def datetime_to_timestamp(dt):
return int(time.mktime(datetime.strptime(dt, "%Y-%m-%d %H:%M:%S").timetuple()))
def format_date_smc_filter(date):
date_time_obj = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
return str(date_time_obj.strftime('%Y%m%d.%H:%M:%S.000'))
# Split a list into chunks of the specified size
def chunker(iterable, n, fill_value=None):
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fill_value)