Skip to content

docs: document default values for confdb#389

Merged
miguelpires merged 3 commits into
canonical:mainfrom
st3v3nmw:confdb-defaults
Jun 25, 2026
Merged

docs: document default values for confdb#389
miguelpires merged 3 commits into
canonical:mainfrom
st3v3nmw:confdb-defaults

Conversation

@st3v3nmw

Copy link
Copy Markdown
Member

Robotics flagged that providing default values for confdb configuration isn't well documented. This PR adds a "Default values" section covering two approaches: supplying a per-request fallback with the --default flag on snap get and snapctl get --view, and populating a default from a custodian's load-view-<plug> hook so callers don't each have to pass one.

CC: @miguelpires

@miguelpires miguelpires left a comment

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.

FWIW, defaults are already documented in https://snapcraft.io/docs/how-to-guides/snap-development/use-snapctl/#confdb, besides the help messages of both snap/snapctl. I'm wary of including every feature here since it's a practical how-to example and should. Maybe we can shorten it a bit

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
```

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 just setting a value in a hook which already has examples above

Comment on lines +344 to +357
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 <account-id>/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

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.

At most, I'd keep this part IMO

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair point, I'll shorten it.

@st3v3nmw st3v3nmw requested a review from miguelpires June 24, 2026 11:11

@miguelpires miguelpires left a comment

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.

small suggestion

Comment thread docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md Outdated
Comment thread docs/how-to-guides/manage-snaps/configure-snaps-with-confdb.md Outdated
Co-authored-by: Miguel Pires <miguelpires94@gmail.com>

@miguelpires miguelpires left a comment

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.

thanks!

@miguelpires miguelpires merged commit 6131e05 into canonical:main Jun 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants