Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getting and setting snap config #203

Merged
merged 5 commits into from
Jan 22, 2024

Conversation

st3v3nmw
Copy link
Collaborator

@st3v3nmw st3v3nmw commented Jan 19, 2024

TL;DR

This PR:

  • Adds functionality to set the snap config (via SnapManager) & periodically syncing the config (via SnapMonitor)
  • Migrates Snap HTTP functionality to use the snap-http package

Deets

This started off #202 (conditionally use snap_http, fall back to local module) but ran into some issues while using both snap-http & the local landscape.client.snap simultaneously:

  • For HTTP responses, landscape.client.snap returns a dict while snap_http returns SnapdResponse
  • snap_http's SnapException is missing the json method in landscape.client.snap's SnapdHttpException

Applied the git submodule suggestion in #202 and created a symbolic link: landscape.client.snap_http -> snap-http/snap_http and deleted landscape.client.snap.

--

Other noteworthy change: Added a new "schema type" Nested that allows nesting of "container types" like List, Dict, & KeyDict. The values of snap configs have arbitrary types and can be deeply nested. Consider values like:

# A
{"bar": "default", "baz": False}

# B
{
            "foo": {"baz": "default", "qux": [1, True, 2.0]},
            "bar": "enabled",
}

# C
{
            "foo": {"bar": "baz", "qux": {"quux": "corge"}},
            "ssids": [{"name": "Airport Wi-Fi"}, {"name": "Totally Legit Wi-Fi"}],
}

Arbitrary values cannot be generally/succinctly represented with the existing "schema types" esp. very very nested values. The only other option is using a type like Unknown that doesn't do any schema validation.

@st3v3nmw st3v3nmw changed the title Add get and set config Add getting and setting snap config Jan 19, 2024
@st3v3nmw st3v3nmw force-pushed the add-get-and-set-config branch 2 times, most recently from 3cfccf4 to 07318b2 Compare January 19, 2024 13:28
@st3v3nmw st3v3nmw force-pushed the add-get-and-set-config branch 5 times, most recently from a65659c to 7d62df9 Compare January 19, 2024 15:37
@st3v3nmw st3v3nmw force-pushed the add-get-and-set-config branch from 7d62df9 to 0a22efc Compare January 19, 2024 15:42
@st3v3nmw st3v3nmw marked this pull request as ready for review January 19, 2024 16:15
@Perfect5th
Copy link
Contributor

Arbitrary values cannot be generally/succinctly represented with the existing "schema types" esp. very very nested values. The only other option is using a type like Unknown that doesn't do any schema validation.

Because the shape of this data is essentially arbitrary, and therefore cannot cleanly map to anything on the Landscape Server side, database-schema-wise, I'm going to suggest that we just use Unicode as the type, and serialize it as JSON. Is it guaranteed to be serializable?

There's some precedence for doing it this way.

@st3v3nmw
Copy link
Collaborator Author

Is it guaranteed to be serializable?

Yes, the GET /v2/snaps/{name}/conf endpoint returns a JSON map of configuration keys and values. Let me switch to Unicode

@st3v3nmw st3v3nmw force-pushed the add-get-and-set-config branch from cb0c166 to 2d16db1 Compare January 22, 2024 07:35
Copy link
Contributor

@Perfect5th Perfect5th left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Perfect5th Perfect5th merged commit 7f1be98 into canonical:master Jan 22, 2024
5 checks passed
@st3v3nmw st3v3nmw deleted the add-get-and-set-config branch January 23, 2024 06:33
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