-
Notifications
You must be signed in to change notification settings - Fork 83
osbuild: inspect wrapper (HMS-8973) #1715
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,11 @@ | |
| // OSBuild (schema v2) types. | ||
| package osbuild | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| ) | ||
|
|
||
| const ( | ||
| // should be "^\\/(?!\\.\\.)((?!\\/\\.\\.\\/).)+$" but Go doesn't support lookaheads | ||
| // therefore we have to instead check for the invalid cases, which is much simpler | ||
|
|
@@ -51,3 +56,31 @@ func (p *Pipeline) AddStages(stages ...*Stage) { | |
| p.AddStage(stage) | ||
| } | ||
| } | ||
|
|
||
| // Take some bytes and deserialize them into a Manifest; mostly used to take | ||
| // an inspected manifest | ||
| func NewManifestFromBytes(data []byte) (*Manifest, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this for a real manifest but it did not go very well, it dies with |
||
| manifest := &Manifest{} | ||
|
|
||
| if err := json.Unmarshal(data, &manifest); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return manifest, nil | ||
| } | ||
|
|
||
| // GetID gets the pipeline identifiers for an *inspected* manifest. These are | ||
| // not available for non-inspected manifests and will return an error there. | ||
| func (p *Pipeline) GetID() (string, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a test for this or is it very difficult to do? We might also want to expand the docstring as AIUI this will only return something if the manifest was run through osbuild-inspect before?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take a look.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring expanded, test included; I'm using a fake manifest, we're not currently mocking any |
||
| if len(p.Stages) == 0 { | ||
| return "", fmt.Errorf("no stages in manifest") | ||
| } | ||
|
|
||
| lastStage := p.Stages[len(p.Stages)-1] | ||
|
|
||
| if len(lastStage.ID) == 0 { | ||
| return "", fmt.Errorf("un-inspected manifest, identifiers are not available") | ||
| } | ||
|
|
||
| return lastStage.ID, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.