-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
137 lines (116 loc) · 2.9 KB
/
util.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import string
from random import randint, random, choice, getrandbits
from ipaddress import IPv4Network, IPv4Address
from datetime import datetime, timedelta
def timestamp():
return datetime.now().strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]
def seconds_until(t=0):
"""
Given an hour in 24-hour time, return the number of seconds until that hour.
:param t: Integer from 0-23
"""
d, t = divmod(t, 24)
now = datetime.now()
target = datetime(year=now.year, month=now.month, day=now.day, hour=t)
if t < now.hour:
target += timedelta(days=1)
return round(target.timestamp() - now.timestamp())
class Mock:
HOSTS = [
'solsyspingfed1',
'solsyspingfed2',
'solsyspingfed3',
'solsyspingfed4',
'solsyspingfed5',
'solsyspingfed6',
'solsyspingfed7',
'solsyspingfed8',
'solsyspingfed9',
'solsyspingfed10'
]
SUBNETS = [
IPv4Network("10.0.0.0/8"),
IPv4Network("172.16.0.0/12"),
IPv4Network("192.168.0.0/16"),
IPv4Network("169.254.0.0/16")
]
FIRST_NAMES = [
'duncan',
'santosh',
'darren',
'jeremy',
'ryoji',
'steve',
'doug',
'alan',
'john',
'jim'
]
LAST_NAMES = [
'sommerville',
'krishna',
'fuller',
'adams',
'betchaku',
'manuel',
'brown',
'burns',
'tobin',
'liu'
]
EMAIL_DOMAINS = [
'gmail.com',
'solsys.ca',
'yahoo.ca',
'hotmail.com',
'mail.com',
'aol.com'
]
OAUTH_CLIENTS = [
'analyzer',
'portal'
'api',
'solsys_connect',
'connect_api',
'plethora',
'solsys_showcase',
'datafy',
'conceptr',
'jira',
'remedy',
'cloudera',
'aws',
'azure',
'gcp',
'fortify',
'bitbucket'
]
ADAPTERS = [
'HTMLFormSimplePCV',
'LDAPAuthenticator',
'KerberosAuthenticator',
'IWAAuth'
]
@staticmethod
def tid():
return ''.join(choice(string.ascii_letters + string.digits + '-_') for _ in range(27))
@staticmethod
def response_time():
return randint(5, 100) if random() < 0.95 else randint(1000, 5000)
@staticmethod
def host():
return choice(Mock.HOSTS)
@staticmethod
def ip_address():
subnet = choice(Mock.SUBNETS)
bits = getrandbits(subnet.max_prefixlen - subnet.prefixlen)
return str(IPv4Address(subnet.network_address + bits))
@staticmethod
def user():
return '%s.%s@%s' % (choice(Mock.FIRST_NAMES), choice(Mock.LAST_NAMES), choice(Mock.EMAIL_DOMAINS))
@staticmethod
def client():
return choice(Mock.OAUTH_CLIENTS)
@staticmethod
def adapter():
return choice(Mock.ADAPTERS)