Skip to content

Commit abd1cb8

Browse files
committed
Certificate implementation
Signed-off-by: Anton Kremenetsky <anton.kremenetsky@gmail.com>
1 parent 44ac13c commit abd1cb8

10 files changed

Lines changed: 1073 additions & 124 deletions

File tree

genesis_core/secret/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
DEFAULT_SQL_LIMIT = 100
2020
PASSWORD_KIND = "password"
21+
CERTIFICATE_KIND = "certificate"
2122

2223

2324
class SecretStatus(str, enum.Enum):

genesis_core/secret/dm/models.py

Lines changed: 105 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,48 @@
2727
from genesis_core.secret import constants as sc
2828

2929

30-
class AbstractPasswordConstructor(
30+
class AbstractSecretConstructor(
3131
types_dynamic.AbstractKindModel, ra_models.SimpleViewMixin
3232
):
3333

34-
def build(self, plain_password: str) -> str:
34+
def build(self, plain_secret: str) -> str:
3535
raise NotImplementedError()
3636

3737

38-
class PlainPasswordConstructor(AbstractPasswordConstructor):
38+
class PlainSecretConstructor(AbstractSecretConstructor):
3939
KIND = "plain"
4040

41-
def build(self, plain_password: str) -> str:
42-
return plain_password
41+
def build(self, plain_secret: str) -> str:
42+
return plain_secret
4343

4444

45-
class Password(
45+
class Secret(
4646
cm.ModelWithFullAsset,
47-
orm.SQLStorableMixin,
4847
ua_models.TargetResourceMixin,
49-
ua_models.TargetResourceSQLStorableMixin,
5048
):
51-
__tablename__ = "secret_passwords"
52-
53-
method = properties.property(
54-
types.Enum([s.value for s in sc.SecretMethod]),
55-
default=sc.SecretMethod.AUTO_HEX.value,
56-
)
5749
status = properties.property(
5850
types.Enum([s.value for s in sc.SecretStatus]),
5951
default=sc.SecretStatus.NEW.value,
6052
)
6153
constructor = properties.property(
6254
types_dynamic.KindModelSelectorType(
63-
types_dynamic.KindModelType(PlainPasswordConstructor),
55+
types_dynamic.KindModelType(PlainSecretConstructor),
6456
),
6557
required=True,
66-
default=PlainPasswordConstructor,
58+
default=PlainSecretConstructor,
59+
)
60+
61+
62+
class Password(
63+
Secret,
64+
orm.SQLStorableMixin,
65+
ua_models.TargetResourceSQLStorableMixin,
66+
):
67+
__tablename__ = "secret_passwords"
68+
69+
method = properties.property(
70+
types.Enum([s.value for s in sc.SecretMethod]),
71+
default=sc.SecretMethod.AUTO_HEX.value,
6772
)
6873
value = properties.property(
6974
types.AllowNone(types.String(min_length=1, max_length=512)),
@@ -105,3 +110,87 @@ def get_deleted_passwords(
105110
return cls.get_deleted_target_resources(
106111
cls.__tablename__, sc.PASSWORD_KIND, limit
107112
)
113+
114+
115+
class AbstractCertificateMethod(
116+
types_dynamic.AbstractKindModel, ra_models.SimpleViewMixin
117+
):
118+
pass
119+
120+
121+
class DNSCoreCertificateMethod(AbstractCertificateMethod):
122+
KIND = "dns_core"
123+
124+
125+
class Certificate(
126+
Secret,
127+
orm.SQLStorableWithJSONFieldsMixin,
128+
ua_models.TargetResourceSQLStorableMixin,
129+
):
130+
__tablename__ = "secret_certificates"
131+
__jsonfields__ = ["domains"]
132+
133+
method = properties.property(
134+
types_dynamic.KindModelSelectorType(
135+
types_dynamic.KindModelType(DNSCoreCertificateMethod),
136+
),
137+
required=True,
138+
default=DNSCoreCertificateMethod,
139+
)
140+
valid_until = properties.property(
141+
types.AllowNone(types.UTCDateTimeZ()),
142+
default=None,
143+
)
144+
email = properties.property(types.Email())
145+
domains = properties.property(
146+
types.TypedList(types.String()),
147+
required=True,
148+
)
149+
key = properties.property(
150+
types.AllowNone(types.String(min_length=1, max_length=10240)),
151+
default=None,
152+
)
153+
cert = properties.property(
154+
types.AllowNone(types.String(min_length=1, max_length=10240)),
155+
default=None,
156+
)
157+
158+
def get_resource_target_fields(self) -> set[str]:
159+
"""Return the collection of target fields.
160+
161+
Refer to the Resource model for more details about target fields.
162+
"""
163+
return {
164+
"method",
165+
"email",
166+
"domains",
167+
"constructor",
168+
"name",
169+
"description",
170+
"project_id",
171+
"uuid",
172+
}
173+
174+
@classmethod
175+
def get_new_certificates(
176+
cls, limit: int = sc.DEFAULT_SQL_LIMIT
177+
) -> list["Certificate"]:
178+
return cls.get_new_entities(
179+
cls.__tablename__, sc.CERTIFICATE_KIND, limit
180+
)
181+
182+
@classmethod
183+
def get_updated_certificates(
184+
cls, limit: int = sc.DEFAULT_SQL_LIMIT
185+
) -> list["Certificate"]:
186+
return cls.get_updated_entities(
187+
cls.__tablename__, sc.CERTIFICATE_KIND, limit
188+
)
189+
190+
@classmethod
191+
def get_deleted_certificates(
192+
cls, limit: int = sc.DEFAULT_SQL_LIMIT
193+
) -> list[ua_models.TargetResource]:
194+
return cls.get_deleted_target_resources(
195+
cls.__tablename__, sc.CERTIFICATE_KIND, limit
196+
)

0 commit comments

Comments
 (0)