-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/otk: New otk external: osbuild-make-ostree-source
A new command for otk that creates the org.osbuild.ostree source object based on the resolved ostree commit data generated from the osbuild-resolve-ostree-commit command.
- Loading branch information
1 parent
ebe5fd3
commit 66f21b1
Showing
1 changed file
with
75 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"github.com/osbuild/images/pkg/osbuild" | ||
"github.com/osbuild/images/pkg/ostree" | ||
) | ||
|
||
// TODO: move structs to common package with resolver external | ||
|
||
type Input struct { | ||
Tree InputTree `json:"tree"` | ||
} | ||
|
||
type InputTree struct { | ||
Const InputConst `json:"const"` | ||
} | ||
|
||
type InputConst struct { | ||
// Ref of the commit (can be empty). | ||
Ref string `json:"ref,omitempty"` | ||
|
||
// URL of the repo where the commit can be fetched. | ||
URL string `json:"url"` | ||
|
||
// Secrets type to use when pulling the ostree commit content | ||
// (e.g. org.osbuild.rhsm.consumer). | ||
Secrets string `json:"secrets,omitempty"` | ||
|
||
// Checksum of the commit. | ||
Checksum string `json:"checksum"` | ||
} | ||
|
||
type Output struct { | ||
OSTreeSource osbuild.OSTreeSource `json:"org.osbuild.ostree"` | ||
} | ||
|
||
func run(r io.Reader, w io.Writer) error { | ||
var inp Input | ||
if err := json.NewDecoder(r).Decode(&inp); err != nil { | ||
return err | ||
} | ||
|
||
ostreeSource := osbuild.NewOSTreeSource() | ||
ostreeSource.AddItem(ostree.CommitSpec{ | ||
Ref: inp.Tree.Const.Ref, | ||
URL: inp.Tree.Const.URL, | ||
Secrets: inp.Tree.Const.Secrets, | ||
Checksum: inp.Tree.Const.Checksum, | ||
}) | ||
|
||
output := Output{ | ||
OSTreeSource: *ostreeSource, | ||
} | ||
out := map[string]interface{}{ | ||
"tree": output, | ||
} | ||
outputJson, err := json.MarshalIndent(out, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("cannot marshal response: %w", err) | ||
} | ||
fmt.Fprintf(w, "%s\n", outputJson) | ||
return nil | ||
} | ||
|
||
func main() { | ||
if err := run(os.Stdin, os.Stdout); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v", err.Error()) | ||
os.Exit(1) | ||
} | ||
} |