Skip to content

Commit 280f76d

Browse files
[JUJU-2426] Secrets support (#791)
* Add support for secret* facades. * Update app facade version to 16.
1 parent b90f16b commit 280f76d

40 files changed

Lines changed: 54850 additions & 8124 deletions

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
integration:
5050
name: Integration
5151
needs: [lint, unit-tests]
52-
timeout-minutes: 120
52+
timeout-minutes: 150
5353
runs-on: ubuntu-latest
5454
strategy:
5555
matrix:
@@ -64,7 +64,7 @@ jobs:
6464
uses: charmed-kubernetes/actions-operator@main
6565
with:
6666
provider: lxd
67-
juju-channel: 3.0/stable
67+
juju-channel: 3.1/beta
6868
# 2023-01-11 Commented until we discover a
6969
# clear approach for this.
7070
# - name: Set proxy in controller

.github/workflows/test_candidate.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
candidate-integration:
99
name: Edge integration
10-
timeout-minutes: 120
10+
timeout-minutes: 150
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
@@ -26,7 +26,7 @@ jobs:
2626
- name: Check if there is a new candidate
2727
shell: bash
2828
run: |
29-
candidate=$(snap info juju | grep 3.0/candidate | awk '{print $2}')
29+
candidate=$(snap info juju | grep 3.1/candidate | awk '{print $2}')
3030
last_tested=NA
3131
if [ -f juju-last-candidate-version ]; then
3232
last_tested=$(cat juju-last-candidate-version)
@@ -54,7 +54,7 @@ jobs:
5454
uses: charmed-kubernetes/actions-operator@main
5555
with:
5656
provider: lxd
57-
juju-channel: 3.0/candidate
57+
juju-channel: 3.1/candidate
5858
- name: Setup Python
5959
if: ${{ env.next-test != 'NA' }}
6060
uses: actions/setup-python@v4

.github/workflows/test_edge.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
candidate-integration:
99
name: Edge integration
10-
timeout-minutes: 120
10+
timeout-minutes: 150
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
@@ -26,7 +26,7 @@ jobs:
2626
- name: Check if there is a new candidate
2727
shell: bash
2828
run: |
29-
edge=$(snap info juju | grep 3.0/edge | awk '{print $2}')
29+
edge=$(snap info juju | grep 3.1/edge | awk '{print $2}')
3030
last_tested=NA
3131
if [ -f juju-last-edge-version ]; then
3232
last_tested=$(cat juju-last-edge-version)
@@ -54,7 +54,7 @@ jobs:
5454
uses: charmed-kubernetes/actions-operator@main
5555
with:
5656
provider: lxd
57-
juju-channel: 3.0/edge
57+
juju-channel: 3.1/edge
5858
- name: Setup Python
5959
if: ${{ env.next-test != 'NA' }}
6060
uses: actions/setup-python@v4

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0-b1
1+
3.1.0b1

examples/add_secrets_backend.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from juju import jasyncio
2+
from juju.model import Model
3+
4+
import hvac
5+
6+
7+
async def main():
8+
"""This is a complete example that deploys vault, uses a
9+
vault client to initialize it, and registers the backend.
10+
"""
11+
12+
m = Model()
13+
await m.connect_current()
14+
15+
# deploy postgresql
16+
await m.deploy('postgresql')
17+
# deploy vault
18+
await m.deploy("vault", series="focal")
19+
# relate/integrate
20+
await m.relate("vault:db", "postgresql:db")
21+
# wait for the
22+
await m.wait_for_idle(["vault"])
23+
# expose vault
24+
vault_app = m.applications["vault"]
25+
await vault_app.expose()
26+
27+
# Get a vault client
28+
# Deploy this entire thing
29+
status = await m.get_status()
30+
target = ""
31+
for unit in status.applications['vault'].units.values():
32+
target = unit.public_address
33+
34+
vault_url = "http://%s:8200" % target
35+
vault_client = hvac.Client(url=vault_url)
36+
37+
# Initialize vault
38+
keys = vault_client.sys.initialize(3, 2)
39+
40+
# Unseal vault
41+
vault_client.sys.submit_unseal_keys(keys["keys"])
42+
43+
# Add the secret backend
44+
c = await m.get_controller()
45+
response = await c.add_secret_backends("1000", "myvault", "vault", {"endpoint": vault_url})
46+
print("Output from add secret backends")
47+
print(response["results"])
48+
49+
# List the secrets backend
50+
list = await c.list_secret_backends()
51+
print("Output from list secret backends")
52+
print(list["results"])
53+
54+
# Remove it
55+
await c.remove_secret_backends("myvault")
56+
57+
# Finally after removing
58+
list = await c.list_secret_backends()
59+
print("Output from list secret backends after removal")
60+
print(list["results"])
61+
62+
await m.disconnect()
63+
64+
65+
if __name__ == '__main__':
66+
jasyncio.run(main())

examples/list_secrets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from juju import jasyncio
2+
from juju.model import Model
3+
4+
5+
async def main():
6+
7+
m = Model()
8+
await m.connect()
9+
10+
secrets = await m.list_secrets()
11+
print(secrets)
12+
await m.disconnect()
13+
14+
15+
if __name__ == '__main__':
16+
jasyncio.run(main())

juju/client/_client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from juju.client._definitions import *
55

66

7-
from juju.client import _client7, _client1, _client3, _client4, _client2, _client15, _client6, _client5, _client11, _client9, _client18
7+
from juju.client import _client7, _client1, _client3, _client4, _client2, _client16, _client6, _client11, _client10, _client5, _client9, _client18
88

99

1010
CLIENTS = {
@@ -13,10 +13,11 @@
1313
"3": _client3,
1414
"4": _client4,
1515
"2": _client2,
16-
"15": _client15,
16+
"16": _client16,
1717
"6": _client6,
18-
"5": _client5,
1918
"11": _client11,
19+
"10": _client10,
20+
"5": _client5,
2021
"9": _client9,
2122
"18": _client18
2223
}
@@ -456,6 +457,10 @@ class SSHClientFacade(TypeFactory):
456457
pass
457458

458459

460+
class SecretBackendsFacade(TypeFactory):
461+
pass
462+
463+
459464
class SecretsFacade(TypeFactory):
460465
pass
461466

0 commit comments

Comments
 (0)