Skip to content

Commit

Permalink
Update endpoints only if controller model can be accessed
Browse files Browse the repository at this point in the history
Fixes #998

ControllerAPIInfoForModels call requires the uuid of the controller
model, and if the user doesn't have at least read access, they won't
be able to have that, and the update_endpoint call at the end of a
regular connection fails.
  • Loading branch information
cderici committed Feb 7, 2024
1 parent e203dd7 commit 8e6dab7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions juju/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ async def connect(self, *args, **kwargs):
await self.update_endpoints()

async def update_endpoints(self):
info = await self.info()
self._connector._connection.endpoints = [
(e, info.results[0].cacert)
for e in info.results[0].addresses
]
try:
info = await self.info()
self._connector._connection.endpoints = [
(e, info.results[0].cacert)
for e in info.results[0].addresses
]
except errors.JujuPermissionError:
pass

async def connect_current(self):
"""
Expand Down Expand Up @@ -288,6 +291,8 @@ async def info(self):
"""
log.debug('Getting information')
uuids = await self.model_uuids()
if 'controller' not in uuids:
raise errors.JujuPermissionError('Requires access to controller model.')
controller_facade = client.ControllerFacade.from_connection(self.connection())
params = [client.Entity(tag.model(uuids["controller"]))]
return await controller_facade.ControllerAPIInfoForModels(entities=params)
Expand Down

0 comments on commit 8e6dab7

Please sign in to comment.