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 snapd device information to ComputerInfo message #205

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

st3v3nmw
Copy link
Collaborator

@st3v3nmw st3v3nmw force-pushed the add-snap-device-info branch 5 times, most recently from bcff5e5 to 9530f7c Compare January 30, 2024 19:22
@st3v3nmw st3v3nmw marked this pull request as ready for review January 30, 2024 19:27
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.

I think it needs a bit of fixing, in terms of code clarify. See inline comment.

# extract the assertion headers + their signatures as separate assertions
sections = response.result.decode().split("\n\n")
raw_assertions = [
"\n\n".join(sections[i : i + 2]) for i in range(0, len(sections), 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

This split/re-join could be restructured to be more immediately understandable.

Let's think of it as I/O: you have a bytestream with alternating header groups and signatures separated by '\n\n'. These are pairs: (headers, signature). Seems like a perfect usecase for itertools.bulk. Too bad that's py3.12 only. Here's an alt:

sections = response.result.decode().split("\n\n")
parsed = []
rest = sections
while rest:
    headers, signature, *rest = rest
    parsed.append(parse_assertion(headers, signature))

return parsed

Let me know what you think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated to use the more readable code with a slight modification to handle cases where there are no assertions retrieved from the API (response.result = b"" -> response.result.decode().split("\n\n") = [""] ).

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 340e8fc into canonical:master Jan 31, 2024
5 checks passed
@st3v3nmw st3v3nmw deleted the add-snap-device-info branch January 31, 2024 18:50
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