From 6da256ca67483b1789bff6e3bdce8212cf39dbab Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Mon, 22 Jun 2026 18:18:48 +0300 Subject: [PATCH 1/3] docs: document default values for confdb --- .../configure-snaps-with-confdb.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md b/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md index 4dd54bf..e80c9f3 100644 --- a/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md +++ b/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md @@ -339,6 +339,34 @@ Note that concurrent accesses may block if they would result in writes running c For example, if there is a read ongoing and a write is requested, the write will be blocked. A new read would then also be queued and only run after the write, even though reads are normally run concurrently. This ensures that a stream of reads cannot starve a write access. +## Default values + +Confdb has no schema-level mechanism for declaring default values. There are two ways to provide them. + +### Supplying a default per request + +If no value has been set for a requested path, `snap get` returns an error. You can supply a fallback with `--default`: + +```shell +$ snap get --default=acme-default /network/wifi-state acme.ssid +acme-default +``` + +Snaps can use the same `--default` flag through `snapctl get --view`. In both cases, `--default` can only be used when requesting a single path. The value is returned to the caller only and isn't stored, so every reader must supply its own `--default`. + +### Populating defaults with a load-view hook + +To avoid each caller passing a flag, a custodian snap can populate a default with a `load-view-` hook. snapd runs this hook on every read through the custodian's view, so it can set any path that has no value before the read is served: + +```shell +#!/bin/bash -xe + +# set a default ssid if one hasn't been configured +if ! snapctl get --view :network-wifi-admin acme.ssid >/dev/null 2>&1; then + snapctl set --view :network-wifi-admin acme.ssid=acme-default +fi +``` + ## Getting secret data *From snapd version 2.76+* From 38dd221478e44a145bebf05963a8c802e0b6d4c5 Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Wed, 24 Jun 2026 14:01:53 +0300 Subject: [PATCH 2/3] docs: shorten confdb defaults section --- .../configure-snaps-with-confdb.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md b/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md index e80c9f3..96cea2d 100644 --- a/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md +++ b/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md @@ -341,11 +341,7 @@ For example, if there is a read ongoing and a write is requested, the write will ## Default values -Confdb has no schema-level mechanism for declaring default values. There are two ways to provide them. - -### Supplying a default per request - -If no value has been set for a requested path, `snap get` returns an error. You can supply a fallback with `--default`: +Confdb has no schema-level mechanism for declaring default values. If no value has been set for a requested path, `snap get` returns an error. You can supply a fallback with `--default`: ```shell $ snap get --default=acme-default /network/wifi-state acme.ssid @@ -354,19 +350,6 @@ acme-default Snaps can use the same `--default` flag through `snapctl get --view`. In both cases, `--default` can only be used when requesting a single path. The value is returned to the caller only and isn't stored, so every reader must supply its own `--default`. -### Populating defaults with a load-view hook - -To avoid each caller passing a flag, a custodian snap can populate a default with a `load-view-` hook. snapd runs this hook on every read through the custodian's view, so it can set any path that has no value before the read is served: - -```shell -#!/bin/bash -xe - -# set a default ssid if one hasn't been configured -if ! snapctl get --view :network-wifi-admin acme.ssid >/dev/null 2>&1; then - snapctl set --view :network-wifi-admin acme.ssid=acme-default -fi -``` - ## Getting secret data *From snapd version 2.76+* From 56c6fea0f886cb345f05584cee3300f13cbb36dd Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Thu, 25 Jun 2026 14:12:59 +0300 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Miguel Pires --- .../how-to-guides/manage-snaps/configure-snaps-with-confdb.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md b/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md index 96cea2d..e898e65 100644 --- a/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md +++ b/docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md @@ -341,14 +341,14 @@ For example, if there is a read ongoing and a write is requested, the write will ## Default values -Confdb has no schema-level mechanism for declaring default values. If no value has been set for a requested path, `snap get` returns an error. You can supply a fallback with `--default`: +Confdb has no schema-level mechanism for declaring default values, but both `snap` and `snapctl` allow supplying a fallback with `--default`: ```shell $ snap get --default=acme-default /network/wifi-state acme.ssid acme-default ``` -Snaps can use the same `--default` flag through `snapctl get --view`. In both cases, `--default` can only be used when requesting a single path. The value is returned to the caller only and isn't stored, so every reader must supply its own `--default`. +In both cases, `--default` can only be used when requesting a single path. ## Getting secret data *From snapd version 2.76+*