Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPE-3617 add ca chain support #383

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/charms/mysql/v0/s3_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

"""S3 helper functions for the MySQL charms."""

import base64
import logging
import tempfile
import time
Expand All @@ -31,7 +31,7 @@

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

# botocore/urllib3 clutter the logs when on debug
logging.getLogger("botocore").setLevel(logging.WARNING)
Expand All @@ -52,13 +52,25 @@ def upload_content_to_s3(content: str, content_path: str, s3_parameters: Dict) -
"""
try:
logger.info(f"Uploading content to bucket={s3_parameters['bucket']}, path={content_path}")
ca_file = tempfile.NamedTemporaryFile()
session = boto3.session.Session(
aws_access_key_id=s3_parameters["access-key"],
aws_secret_access_key=s3_parameters["secret-key"],
region_name=s3_parameters["region"] or None,
)

s3 = session.resource("s3", endpoint_url=s3_parameters["endpoint"])
verif = True
ca_chain = s3_parameters["tls-ca-chain"]
if ca_chain:
ca = "\n".join([base64.b64decode(s).decode() for s in ca_chain])
ca_file.write(ca.encode())
ca_file.flush()
verif = ca_file.name

s3 = session.resource(
"s3",
endpoint_url=s3_parameters["endpoint"],
verify=verif,
)

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

Expand All @@ -73,6 +85,8 @@ def upload_content_to_s3(content: str, content_path: str, s3_parameters: Dict) -
exc_info=e,
)
return False
finally:
ca_file.close()

return True

Expand Down
Loading