Function renamed to better fit the argument element type (StageMetadata). Argument is a map to fit the pipeline metadata in the result object. Signature function is made public to be reused in the cloud API conversion. Metadata test raw value updated to v2 result format. Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package rpmmd
|
|
|
|
import (
|
|
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
|
)
|
|
|
|
type RPM struct {
|
|
Type string `json:"type"` // must be 'rpm'
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
Release string `json:"release"`
|
|
Epoch *string `json:"epoch,omitempty"`
|
|
Arch string `json:"arch"`
|
|
Sigmd5 string `json:"sigmd5"`
|
|
Signature *string `json:"signature"`
|
|
}
|
|
|
|
func OSBuildMetadataToRPMs(stagesMetadata map[string]osbuild.StageMetadata) []RPM {
|
|
rpms := make([]RPM, 0)
|
|
for _, md := range stagesMetadata {
|
|
switch metadata := md.(type) {
|
|
case *osbuild.RPMStageMetadata:
|
|
for _, pkg := range metadata.Packages {
|
|
rpms = append(rpms, RPM{
|
|
Type: "rpm",
|
|
Name: pkg.Name,
|
|
Epoch: pkg.Epoch,
|
|
Version: pkg.Version,
|
|
Release: pkg.Release,
|
|
Arch: pkg.Arch,
|
|
Sigmd5: pkg.SigMD5,
|
|
Signature: PackageMetadataToSignature(pkg),
|
|
})
|
|
}
|
|
default:
|
|
continue
|
|
}
|
|
}
|
|
return rpms
|
|
}
|
|
|
|
func PackageMetadataToSignature(pkg osbuild.RPMPackageMetadata) *string {
|
|
if pkg.SigGPG != "" {
|
|
return &pkg.SigGPG
|
|
} else if pkg.SigPGP != "" {
|
|
return &pkg.SigPGP
|
|
}
|
|
return nil
|
|
}
|