-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.py
More file actions
105 lines (85 loc) · 2.98 KB
/
base.py
File metadata and controls
105 lines (85 loc) · 2.98 KB
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
"""
Simvue Storage Base
===================
Contains general definitions for Simvue Storage objects.
"""
import typing
import pydantic
import datetime
from simvue.api.objects.base import SimvueObject, staging_check, write_only
from simvue.models import NAME_REGEX, DATETIME_FORMAT
class StorageBase(SimvueObject):
"""Storage object base class from which all storage types inherit.
This represents a single storage backend used to store uploaded artifacts.
"""
def __init__(
self,
identifier: str | None = None,
_read_only: bool = False,
**kwargs,
) -> None:
"""Retrieve an alert from the Simvue server by identifier"""
self._label = "storage"
self._endpoint = self._label
super().__init__(identifier, _read_only=_read_only, **kwargs)
@classmethod
def new(cls, **_):
"""Create a new instance of a storage type"""
pass
@property
@staging_check
def name(self) -> str:
"""Retrieve the name for this storage"""
return self._get_attribute("name")
@name.setter
@write_only
@pydantic.validate_call
def name(
self, name: typing.Annotated[str, pydantic.Field(pattern=NAME_REGEX)]
) -> None:
"""Set name assigned to this folder"""
self._staging["name"] = name
@property
def backend(self) -> str:
"""Retrieve the backend of storage"""
return self._get_attribute("backend")
@property
@staging_check
def is_default(self) -> bool:
"""Retrieve if this is the default storage for the user"""
return self._get_attribute("is_default")
@is_default.setter
@write_only
@pydantic.validate_call
def is_default(self, is_default: bool) -> None:
"""Set this storage to be the default"""
self._staging["is_default"] = is_default
@property
@staging_check
def is_tenant_useable(self) -> bool:
"""Retrieve if this is usable by the current user tenant"""
return self._get_attribute("is_tenant_useable")
@is_tenant_useable.setter
@write_only
@pydantic.validate_call
def is_tenant_useable(self, is_tenant_useable: bool) -> None:
"""Set this storage to be usable by the current user tenant"""
self._staging["is_tenant_useable"] = is_tenant_useable
@property
@staging_check
def is_enabled(self) -> bool:
"""Retrieve if this is enabled"""
return self._get_attribute("is_enabled")
@is_enabled.setter
@write_only
@pydantic.validate_call
def is_enabled(self, is_enabled: bool) -> None:
"""Set this storage to be usable by the current user tenant"""
self._staging["is_enabled"] = is_enabled
@property
def created(self) -> datetime.datetime | None:
"""Retrieve created datetime for the artifact"""
_created: str | None = self._get_attribute("created")
return (
datetime.datetime.strptime(_created, DATETIME_FORMAT) if _created else None
)