-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: computer title generation for zero-touch deployment
- Loading branch information
Showing
7 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
|
||
import yaml | ||
|
||
from landscape.client import snap_http | ||
from landscape.client.snap_http import SnapdHttpException | ||
|
||
|
||
def is_snap() -> bool: | ||
"""Is the landscape-client a snap?""" | ||
return os.environ.get("SNAP_REVISION") is not None | ||
|
||
|
||
def get_assertions(assertion_type: str): | ||
"""Get and parse assertions.""" | ||
try: | ||
response = snap_http.get_assertions(assertion_type) | ||
except SnapdHttpException: | ||
return | ||
|
||
# the snapd API returns multiple assertions as a stream of | ||
# bytes separated by double newlines, something like this: | ||
# <assertion1-headers>: <value> | ||
# <assertion1-headers>: <value> | ||
# | ||
# signature | ||
# | ||
# <assertion2-headers>: <value> | ||
# <assertion2-headers>: <value> | ||
# | ||
# signature | ||
|
||
# extract the assertion headers + their signatures as separate assertions | ||
assertions = [] | ||
result = response.result.decode() | ||
if result: | ||
sections = result.split("\n\n") | ||
rest = sections | ||
while rest: | ||
headers, signature, *rest = rest | ||
assertion = yaml.safe_load(headers) | ||
assertion["signature"] = signature | ||
assertions.append(assertion) | ||
|
||
return assertions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule snap-http
updated
from a79cdb to b9e280