Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
93e79fb
chore: pre-commit and spelling fixes
dimaqq Nov 12, 2024
9d9c6a8
chore: ruff autofix
dimaqq Nov 12, 2024
fb8897e
chore: manual fixes
dimaqq Nov 12, 2024
7006d61
chore: docformatter over tests
dimaqq Nov 12, 2024
6422645
chore: docformatter + ruff
dimaqq Nov 12, 2024
61f346b
chore: manual ruff fixes
dimaqq Nov 12, 2024
e21d3c1
chore: manual ruff fixes
dimaqq Nov 12, 2024
70e3a74
chore: pre-commit and its settings
dimaqq Nov 12, 2024
ac99474
chore: verbatim copies of json files from juju
dimaqq Nov 13, 2024
83a3cd4
chore: exempt json files copied from juju from specific checks
dimaqq Nov 13, 2024
04e6446
chore: ruff format after codegen
dimaqq Nov 13, 2024
7ae3858
chore: fix up arg that's not optional
dimaqq Nov 13, 2024
05dfde5
chore: fix up utils, secrets, provisioner
dimaqq Nov 13, 2024
d79029d
chore: fix model; restore jasyncio re-export
dimaqq Nov 13, 2024
a864024
chore: fix k8s proxy; re-export in jasyncio
dimaqq Nov 13, 2024
f546538
chore: fix up the codegen
dimaqq Nov 13, 2024
9b45d8a
chore: fix up the codegen
dimaqq Nov 13, 2024
50199e2
chore: fix client and connection, disable warnings for the generated …
dimaqq Nov 13, 2024
5492c30
chore: clean pre-commit
dimaqq Nov 13, 2024
5f119ec
chore: remove old linter
dimaqq Nov 13, 2024
a8399b4
chore: don't let pre-commit autofix pull requests, it doesn't pass CLA
dimaqq Nov 14, 2024
1217ef1
chore: exclude known large file patterns
dimaqq Nov 14, 2024
a3b241d
chore: document pre-commit
dimaqq Nov 14, 2024
4ccd82d
chore: remove lint from GHA job deps
dimaqq Nov 14, 2024
6de9a5b
chore: fix package build
dimaqq Nov 14, 2024
cb4a962
chore: publish wheels in addition to sdist
dimaqq Nov 14, 2024
3ea32bf
chore: add tooling to the contributor guide
dimaqq Nov 14, 2024
7cd3743
chore: uvx in gha
dimaqq Nov 14, 2024
45c5b99
chore: weirdly my local build both sdist and wheel, while GHA build a…
dimaqq Nov 14, 2024
e3cecc3
chore: main is still on .0, not .1
dimaqq Nov 14, 2024
d8c4688
chore: sensible stacklevel on deprecation warnings
dimaqq Nov 14, 2024
3cba1b6
chore: sensible stacklevel on deprecation warnings
dimaqq Nov 14, 2024
62585d2
chore: pre-commit via github action
dimaqq Nov 15, 2024
f5b93e7
chore: simpler build
dimaqq Nov 15, 2024
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
Prev Previous commit
Next Next commit
chore: fix k8s proxy; re-export in jasyncio
  • Loading branch information
dimaqq committed Nov 13, 2024
commit a8640247ae8dbc1aef4546da20c35c0e1d1f51e7
17 changes: 9 additions & 8 deletions juju/client/proxy/kubernetes/proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache V2, see LICENCE file for details.
import logging
import os
import tempfile

from kubernetes import client
Expand Down Expand Up @@ -36,11 +35,15 @@ def __init__(
except ValueError:
raise ValueError(f"Invalid port number: {remote_port}")

self.port_forwarder = None

if ca_cert:
self.temp_ca_file = tempfile.NamedTemporaryFile(delete=False)
self.temp_ca_file = tempfile.NamedTemporaryFile() # noqa: SIM115
self.temp_ca_file.write(bytes(ca_cert, "utf-8"))
self.temp_ca_file.flush()
config.ssl_ca_cert = self.temp_ca_file.name
else:
self.temp_ca_file = None

self.api_client = client.ApiClient(config)

Expand All @@ -64,15 +67,13 @@ 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:
self.port_forwarder.close()
self.temp_ca_file.close()
if self.port_forwarder:
self.port_forwarder.close()
if self.temp_ca_file:
self.temp_ca_file.close()
except AttributeError:
pass

Expand Down
10 changes: 5 additions & 5 deletions juju/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async def destroy_models(

"""
uuids = await self.model_uuids()
models = [uuids[model] if model in uuids else model for model in models]
models = [uuids.get(model) or model for model in models]

model_facade = client.ModelManagerFacade.from_connection(self.connection())

Expand Down Expand Up @@ -574,7 +574,7 @@ async def get_models(self, all=False, username=None): # noqa: A002
"""
return await self.list_models(username, all)

async def model_uuids(self, username=None, all=False):
async def model_uuids(self, username=None, all=False): # noqa: A002
"""Return a mapping of model names to UUIDs the given user can access.

:param str username: Optional username argument, defaults to
Expand All @@ -599,7 +599,7 @@ async def model_uuids(self, username=None, all=False):
model_summary.name: model_summary.uuid for model_summary in model_summaries
}

async def list_models(self, username=None, all=False):
async def list_models(self, username=None, all=False): # noqa: A002
"""Return list of names of the available models on this controller.

Equivalent to ``sorted((await self.model_uuids()).keys())``
Expand Down Expand Up @@ -885,7 +885,7 @@ async def _watcher(stop_event):
jasyncio.ensure_future(_watcher(stop_event))
return stop_event

async def add_secret_backends(self, id, name, backend_type, config):
async def add_secret_backends(self, id_, name, backend_type, config):
"""Add a new secret backend.

Parameters
Expand All @@ -907,7 +907,7 @@ async def add_secret_backends(self, id, name, backend_type, config):
facade = client.SecretBackendsFacade.from_connection(self.connection())
return await facade.AddSecretBackends([
{
"id": id,
"id": id_,
"backend-type": backend_type,
"config": config,
"name": name,
Expand Down
76 changes: 57 additions & 19 deletions juju/jasyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,71 @@
import functools
import logging
import signal
from asyncio import (
ALL_COMPLETED as ALL_COMPLETED,
)
from asyncio import (
FIRST_COMPLETED as FIRST_COMPLETED,
)
from asyncio import (
CancelledError,
create_task,
wait,
Event as Event, TimeoutError as TimeoutError, Queue as Queue, ensure_future as ensure_future,
gather as gather,
sleep as sleep,
wait_for as wait_for,
create_subprocess_exec as create_subprocess_exec,
subprocess as subprocess,

FIRST_COMPLETED as FIRST_COMPLETED,
Lock as Lock,
as_completed as as_completed,
new_event_loop as new_event_loop,
)

# FIXME: integration tests don't use these, but some are used in this repo
# Use primitives from asyncio within this repo and remove these re-exports
from asyncio import (
Event as Event,
)
from asyncio import (
Lock as Lock,
)
from asyncio import (
Queue as Queue,
)
from asyncio import (
TimeoutError as TimeoutError, # noqa: A004
)
from asyncio import (
all_tasks as all_tasks,
)
from asyncio import (
as_completed as as_completed,
)
from asyncio import (
create_subprocess_exec as create_subprocess_exec,
)
from asyncio import (
current_task as current_task,
)
from asyncio import (
ensure_future as ensure_future,
)
from asyncio import (
gather as gather,
)
from asyncio import (
get_event_loop_policy as get_event_loop_policy,
get_running_loop as
get_running_loop,
ALL_COMPLETED as
ALL_COMPLETED,
all_tasks as
all_tasks,
current_task as
current_task,
)
from asyncio import (
get_running_loop as get_running_loop,
)
from asyncio import (
new_event_loop as new_event_loop,
)
from asyncio import (
shield as shield,
)
from asyncio import (
sleep as sleep,
)
from asyncio import (
subprocess as subprocess,
)
from asyncio import (
wait_for as wait_for,
)

import websockets

Expand Down