Skip to content

Commit 56086a0

Browse files
authored
DPE-3617 add ca chain support (#383)
* update lib * fix when chain not defined
1 parent 2176eeb commit 56086a0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/charms/mysql/v0/s3_helpers.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
"""S3 helper functions for the MySQL charms."""
16-
16+
import base64
1717
import logging
1818
import tempfile
1919
import time
@@ -31,7 +31,7 @@
3131

3232
# Increment this PATCH version before using `charmcraft publish-lib` or reset
3333
# to 0 if you are raising the major API version
34-
LIBPATCH = 6
34+
LIBPATCH = 7
3535

3636
# botocore/urllib3 clutter the logs when on debug
3737
logging.getLogger("botocore").setLevel(logging.WARNING)
@@ -52,13 +52,25 @@ def upload_content_to_s3(content: str, content_path: str, s3_parameters: Dict) -
5252
"""
5353
try:
5454
logger.info(f"Uploading content to bucket={s3_parameters['bucket']}, path={content_path}")
55+
ca_file = tempfile.NamedTemporaryFile()
5556
session = boto3.session.Session(
5657
aws_access_key_id=s3_parameters["access-key"],
5758
aws_secret_access_key=s3_parameters["secret-key"],
5859
region_name=s3_parameters["region"] or None,
5960
)
60-
61-
s3 = session.resource("s3", endpoint_url=s3_parameters["endpoint"])
61+
verif = True
62+
ca_chain = s3_parameters.get("tls-ca-chain")
63+
if ca_chain:
64+
ca = "\n".join([base64.b64decode(s).decode() for s in ca_chain])
65+
ca_file.write(ca.encode())
66+
ca_file.flush()
67+
verif = ca_file.name
68+
69+
s3 = session.resource(
70+
"s3",
71+
endpoint_url=s3_parameters["endpoint"],
72+
verify=verif,
73+
)
6274

6375
bucket = s3.Bucket(s3_parameters["bucket"])
6476

@@ -73,6 +85,8 @@ def upload_content_to_s3(content: str, content_path: str, s3_parameters: Dict) -
7385
exc_info=e,
7486
)
7587
return False
88+
finally:
89+
ca_file.close()
7690

7791
return True
7892

0 commit comments

Comments
 (0)