osbuild2: add GenSources helper function

This collects all the sources for a pipeline creates the "sources"
section for an osbuild manifest.
This commit is contained in:
Achilleas Koutsou 2022-06-15 13:10:26 +02:00 committed by Tomáš Hozza
parent c74bfe2aaf
commit 5fe3d1f6d1

View file

@ -3,6 +3,9 @@ package osbuild2
import (
"encoding/json"
"errors"
"github.com/osbuild/osbuild-composer/internal/ostree"
"github.com/osbuild/osbuild-composer/internal/rpmmd"
)
// A Sources map contains all the sources made available to an osbuild run
@ -49,3 +52,46 @@ func (sources *Sources) UnmarshalJSON(data []byte) error {
return nil
}
func GenSources(packages []rpmmd.PackageSpec, ostreeCommits []ostree.CommitSource, inlineData []string) Sources {
sources := Sources{}
curl := &CurlSource{
Items: make(map[string]CurlSourceItem),
}
for _, pkg := range packages {
item := new(CurlSourceOptions)
item.URL = pkg.RemoteLocation
if pkg.Secrets == "org.osbuild.rhsm" {
item.Secrets = &URLSecrets{
Name: "org.osbuild.rhsm",
}
}
curl.Items[pkg.Checksum] = item
}
if len(curl.Items) > 0 {
sources["org.osbuild.curl"] = curl
}
ostree := &OSTreeSource{
Items: make(map[string]OSTreeSourceItem),
}
for _, commit := range ostreeCommits {
item := new(OSTreeSourceItem)
item.Remote.URL = commit.URL
ostree.Items[commit.Checksum] = *item
}
if len(ostree.Items) > 0 {
sources["org.osbuild.ostree"] = ostree
}
if len(inlineData) > 0 {
ils := NewInlineSource()
for _, data := range inlineData {
ils.AddItem(data)
}
sources["org.osbuild.inline"] = ils
}
return sources
}