forked from scaleway/scaleway-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
45 lines (28 loc) · 1.19 KB
/
utils.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
import random
import uuid
from datetime import datetime
from typing import Union
from scaleway_core.profile import ProfileDefaults
system_random = random.SystemRandom()
def random_name() -> str:
return "test-{}".format(uuid.uuid4().hex)
def random_access_key() -> str:
return "SCW" + "".join(
system_random.choices("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", k=16)
)
def string_to_datetime(date: str) -> datetime:
return datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
def random_date(min: Union[str, datetime], max: Union[str, datetime]) -> datetime:
min_time = min if isinstance(min, datetime) else string_to_datetime(min)
max_time = max if isinstance(max, datetime) else string_to_datetime(max)
random_time = min_time + system_random.random() * (max_time - min_time)
return random_time
def datetime_to_string(date: datetime) -> str:
return date.strftime("%Y-%m-%dT%H:%M:%SZ")
def random_date_string(min: str, max: str) -> str:
return datetime_to_string(random_date(min, max))
def random_profile_defaults() -> ProfileDefaults:
return ProfileDefaults(
default_organization_id=uuid.uuid4().hex,
default_project_id=uuid.uuid4().hex,
)