24
24
import socket
25
25
from typing import List , Optional
26
26
27
- from charms .tls_certificates_interface .v1 .tls_certificates import (
27
+ from charms .tls_certificates_interface .v2 .tls_certificates import (
28
28
CertificateAvailableEvent ,
29
29
CertificateExpiringEvent ,
30
- TLSCertificatesRequiresV1 ,
30
+ TLSCertificatesRequiresV2 ,
31
31
generate_csr ,
32
32
generate_private_key ,
33
33
)
34
- from cryptography import x509
35
- from cryptography .x509 .extensions import ExtensionType
36
34
from ops .charm import ActionEvent , RelationBrokenEvent
37
35
from ops .framework import Object
38
36
from ops .pebble import ConnectionError , PathError , ProtocolError
45
43
46
44
# Increment this PATCH version before using `charmcraft publish-lib` or reset
47
45
# to 0 if you are raising the major API version.
48
- LIBPATCH = 7
46
+ LIBPATCH = 8
49
47
50
48
logger = logging .getLogger (__name__ )
51
49
SCOPE = "unit"
@@ -63,7 +61,7 @@ def __init__(
63
61
self .charm = charm
64
62
self .peer_relation = peer_relation
65
63
self .additional_dns_names = additional_dns_names or []
66
- self .certs = TLSCertificatesRequiresV1 (self .charm , TLS_RELATION )
64
+ self .certs = TLSCertificatesRequiresV2 (self .charm , TLS_RELATION )
67
65
self .framework .observe (
68
66
self .charm .on .set_tls_private_key_action , self ._on_set_tls_private_key
69
67
)
@@ -90,7 +88,6 @@ def _request_certificate(self, param: Optional[str]):
90
88
csr = generate_csr (
91
89
private_key = key ,
92
90
subject = self .charm .get_hostname_by_unit (self .charm .unit .name ),
93
- additional_critical_extensions = self ._get_tls_extensions (),
94
91
** self ._get_sans (),
95
92
)
96
93
@@ -161,7 +158,6 @@ def _on_certificate_expiring(self, event: CertificateExpiringEvent) -> None:
161
158
new_csr = generate_csr (
162
159
private_key = key ,
163
160
subject = self .charm .get_hostname_by_unit (self .charm .unit .name ),
164
- additional_critical_extensions = self ._get_tls_extensions (),
165
161
** self ._get_sans (),
166
162
)
167
163
self .certs .request_certificate_renewal (
@@ -207,12 +203,6 @@ def is_ip_address(address: str) -> bool:
207
203
"sans_dns" : sans_dns ,
208
204
}
209
205
210
- @staticmethod
211
- def _get_tls_extensions () -> Optional [List [ExtensionType ]]:
212
- """Return a list of TLS extensions for which certificate key can be used."""
213
- basic_constraints = x509 .BasicConstraints (ca = True , path_length = None )
214
- return [basic_constraints ]
215
-
216
206
def get_tls_files (self ) -> (Optional [str ], Optional [str ], Optional [str ]):
217
207
"""Prepare TLS files in special PostgreSQL way.
218
208
0 commit comments