|
27 | 27 | from genesis_core.secret import constants as sc |
28 | 28 |
|
29 | 29 |
|
30 | | -class AbstractPasswordConstructor( |
| 30 | +class AbstractSecretConstructor( |
31 | 31 | types_dynamic.AbstractKindModel, ra_models.SimpleViewMixin |
32 | 32 | ): |
33 | 33 |
|
34 | | - def build(self, plain_password: str) -> str: |
| 34 | + def build(self, plain_secret: str) -> str: |
35 | 35 | raise NotImplementedError() |
36 | 36 |
|
37 | 37 |
|
38 | | -class PlainPasswordConstructor(AbstractPasswordConstructor): |
| 38 | +class PlainSecretConstructor(AbstractSecretConstructor): |
39 | 39 | KIND = "plain" |
40 | 40 |
|
41 | | - def build(self, plain_password: str) -> str: |
42 | | - return plain_password |
| 41 | + def build(self, plain_secret: str) -> str: |
| 42 | + return plain_secret |
43 | 43 |
|
44 | 44 |
|
45 | | -class Password( |
| 45 | +class Secret( |
46 | 46 | cm.ModelWithFullAsset, |
47 | | - orm.SQLStorableMixin, |
48 | 47 | ua_models.TargetResourceMixin, |
49 | | - ua_models.TargetResourceSQLStorableMixin, |
50 | 48 | ): |
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 | | - ) |
57 | 49 | status = properties.property( |
58 | 50 | types.Enum([s.value for s in sc.SecretStatus]), |
59 | 51 | default=sc.SecretStatus.NEW.value, |
60 | 52 | ) |
61 | 53 | constructor = properties.property( |
62 | 54 | types_dynamic.KindModelSelectorType( |
63 | | - types_dynamic.KindModelType(PlainPasswordConstructor), |
| 55 | + types_dynamic.KindModelType(PlainSecretConstructor), |
64 | 56 | ), |
65 | 57 | 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, |
67 | 72 | ) |
68 | 73 | value = properties.property( |
69 | 74 | types.AllowNone(types.String(min_length=1, max_length=512)), |
@@ -105,3 +110,87 @@ def get_deleted_passwords( |
105 | 110 | return cls.get_deleted_target_resources( |
106 | 111 | cls.__tablename__, sc.PASSWORD_KIND, limit |
107 | 112 | ) |
| 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