Skip to content

Commit cea1ac5

Browse files
committed
Add revoke_secret for user secrets
1 parent c8c9420 commit cea1ac5

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

juju/model.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,27 @@ async def grant_secret(self, secret_name, application, *applications):
27342734
if result_error.error is not None:
27352735
raise JujuAPIError(result_error.error)
27362736

2737+
async def revoke_secret(self, secret_name, application, *applications):
2738+
"""Revoke access to a secret.
2739+
2740+
Revoke applications' access to view the value of a specified secret.
2741+
2742+
:param secret_name str: ID|name of the secret.
2743+
:param application str: name of an application for which the access to the secret is revoked
2744+
:param applications []str: names of more applications to disassociate the secret with
2745+
"""
2746+
if client.SecretsFacade.best_facade_version(self.connection()) < 2:
2747+
raise JujuNotSupportedError("user secrets")
2748+
secretsFacade = client.SecretsFacade.from_connection(self.connection())
2749+
results = await secretsFacade.RevokeSecret(
2750+
applications=[application] + list(applications),
2751+
label=secret_name)
2752+
if len(results.results) != 1:
2753+
raise JujuAPIError(f"expected 1 result, got {len(results.results)}")
2754+
result_error = results.results[0]
2755+
if result_error.error is not None:
2756+
raise JujuAPIError(result_error.error)
2757+
27372758
async def _get_source_api(self, url, controller_name=None):
27382759
controller = Controller()
27392760
if url.has_empty_source():

tests/integration/test_secrets.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ async def test_grant_secret(event_loop):
7575
await model.deploy('ubuntu')
7676

7777
await model.grant_secret('my-apitoken', 'ubuntu')
78+
79+
80+
@base.bootstrapped
81+
@pytest.mark.bundle
82+
async def test_revoke_secret(event_loop):
83+
async with base.CleanModel() as model:
84+
secret = await model.add_secret(name='my-apitoken', data_args=['token=34ae35facd4'])
85+
assert secret.startswith('secret:')
86+
await model.revoke_secret('my-apitoken', 'ubuntu')

0 commit comments

Comments
 (0)