Skip to content
Open
Changes from all commits
Commits
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
48 changes: 27 additions & 21 deletions docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ See [confdb-schema types](https://documentation.ubuntu.com/core/reference/assert

Now let’s create some view rules to access confdb.

In our example, we'll use one snap to configure the network and another to access it, which means we need two views: `wifi-admin` and `wifi-state`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the rebase has undone changes that landed in #378.. llike renaming the views to wifi-admin & wifi-state. And now the storage paths start with v1

In our example, we'll use one snap as custodian of the two views and allowing changes to the configuration of the network, and another snap to access it. This means we will need two views: `configure-wifi` and `access-wifi`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view names here are also the old ones


* `wifi-admin` exposes parameters and allows them to be set.
* `wifi-state` allows the snap to list Wi-Fi connections and read SSID and state information (e.g., up, down).
Expand All @@ -108,27 +108,27 @@ views:
summary: Configure Wi-Fi networks
rules:
-
request: "{name}.ssid"
storage: "v1.wifi.{name}.ssid"
request: "{name}.ssid"
storage: "wifi.{name}.ssid"
-
request: "{name}.password"
storage: "v1.wifi.{name}.psk"
request: "{name}.password"
storage: "wifi.{name}.psk"
-
request: "{name}.state"
storage: "v1.wifi.{name}.state"
request: "{name}.state"
storage: "wifi.{name}.state"
Comment on lines +111 to +118

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is restoring the pre-SD247 paths


wifi-state:
summary: List and read Wi-Fi SSIDs
rules:
-
request: "{name}"
storage: "v1.wifi.{name}"
access: read
content:
request: "{name}"
storage: "wifi.{name}"
access: read
content:
-
storage: ssid
storage: ssid
-
storage: state
storage: state

body-length: 552
sign-key-sha3-384: 74KHeq1foV…
Expand Down Expand Up @@ -225,7 +225,7 @@ Custodian snaps have a special role when accessing ephemeral data. They're respo

The data that snapd stores for ephemeral configuration is only a cached, non-authoritative version of the external data. At least one custodian snap must be installed in the system for a particular confdb-schema.

The first snap will configure the Wi-Fi network to be used, so let’s configure it accordingly:
The first snap will act as the custodian for both views as well as allowing configuration of the Wi-Fi network, so let’s configure it accordingly:

```yaml
plugs:
Expand All @@ -234,6 +234,11 @@ plugs:
account: <account-id>
view: network/wifi-admin
role: custodian
access-wifi:
interface: confdb
account: <account-id>
view: network/access-wifi
role: custodian
```

The other component that must be defined in the snap are the {ref}`hooks <reference-development-supported-snap-hooks>`.
Expand All @@ -260,7 +265,7 @@ That’s it for the custodian snap.

### Reader snap

Now we’ll create a snap that will read the configuration. Its plug will reference the read-only view and it will omit the `role`:
Now we’ll create a snap that will only read the configuration. Its plug will reference the read-only view and it will omit the `role`:

```yaml
plugs:
Expand Down Expand Up @@ -288,8 +293,9 @@ Note that when a snap is published by the same account ID as the assertion, the

```shell
snap install custodian-snap reader-snap
snap connect custodian-snap:network-wifi-admin
snap connect reader-snap:network-wifi-state
snap connect custodian-snap:configure-wifi
snap connect custodian-snap:access-wifi
snap connect reader-snap:access-wifi
Comment on lines +296 to +298

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

```

## Setting data
Expand Down Expand Up @@ -325,10 +331,10 @@ ID Status Spawn Ready Summary
$ snap change 123
Status Spawn Ready Summary
Done ... ... Clears the ongoing confdb transaction from state (on error)
Done ... ... Run hook change-view-network-wifi-admin of snap "custodian-snap"
Done ... ... Run hook observe-view-network-wifi-state of snap "reader-snap"
Done ... ... Commit changes to confdb (<account-id>/network/wifi-admin)
Done ... ... Clears the ongoing confdb transaction from state
Done ... ... Run hook change-view-configure-wifi of snap "custodian-snap"
Done ... ... Run hook observe-view-access-wifi of snap "test-snap"
Done ... ... Commit changes to confdb (NI7Jstuu8gffcoXr02i1kYt898p6Co0A/network/wifi-setup)
Done ... ... Clears the ongoing confdb transaction from state

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same



$ cat /snap/reader-snap/common/ssid
Expand Down
Loading