-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
bcff5e5
to
9530f7c
Compare
There was a problem hiding this 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.
landscape/client/snap_utils.py
Outdated
# 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") = [""]
).
9530f7c
to
8557669
Compare
8557669
to
431aa13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
depends on canonical/snap-http#6