Skip to content

Commit

Permalink
Merge branch 'master' into add_missing_revision_params_in_bundle_add_…
Browse files Browse the repository at this point in the history
…charms
  • Loading branch information
cderici authored Apr 22, 2024
2 parents c8648b1 + 2c30901 commit 04f0e53
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions juju/client/proxy/kubernetes/proxy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.

import os
import tempfile
import logging

from juju.client.proxy.proxy import Proxy, ProxyNotConnectedError
from kubernetes import client
from kubernetes.stream import portforward

log = logging.getLogger('juju.client.connection')


class KubernetesProxy(Proxy):
def __init__(
Expand All @@ -33,7 +36,7 @@ def __init__(
raise ValueError("Invalid port number: {}".format(remote_port))

if ca_cert:
self.temp_ca_file = tempfile.NamedTemporaryFile()
self.temp_ca_file = tempfile.NamedTemporaryFile(delete=False)
self.temp_ca_file.write(bytes(ca_cert, 'utf-8'))
self.temp_ca_file.flush()
config.ssl_ca_cert = self.temp_ca_file.name
Expand All @@ -60,6 +63,10 @@ def connect(self):

def __del__(self):
self.close()
try:
os.unlink(self.temp_ca_file.name)
except FileNotFoundError:
log.debug(f"file {self.temp_ca_file.name} not found")

def close(self):
try:
Expand Down

0 comments on commit 04f0e53

Please sign in to comment.