rpmmd: move RPM metadata tooling to internal pkg
Move the OSBuildStagesToRPMs function, associated test, and RPM type from the worker into the rpmmd subpackge. We will use this function in the cloud API to compile the NEVRAs for the new metadata endpoint.
This commit is contained in:
parent
b1e40b5ce7
commit
6b3920783f
7 changed files with 75 additions and 66 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
)
|
||||
|
||||
|
|
@ -163,7 +164,7 @@ func TestKojiImport(t *testing.T) {
|
|||
Arch: "noarch",
|
||||
},
|
||||
Tools: []koji.Tool{},
|
||||
RPMs: []koji.RPM{},
|
||||
RPMs: []rpmmd.RPM{},
|
||||
},
|
||||
}
|
||||
output := []koji.Image{
|
||||
|
|
@ -175,7 +176,7 @@ func TestKojiImport(t *testing.T) {
|
|||
ChecksumType: "md5",
|
||||
MD5: hash,
|
||||
Type: "image",
|
||||
RPMs: []koji.RPM{},
|
||||
RPMs: []rpmmd.RPM{},
|
||||
Extra: koji.ImageExtra{
|
||||
Info: koji.ImageExtraInfo{
|
||||
Arch: "noarch",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
)
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ func main() {
|
|||
Arch: arch,
|
||||
},
|
||||
Tools: []koji.Tool{},
|
||||
RPMs: []koji.RPM{},
|
||||
RPMs: []rpmmd.RPM{},
|
||||
},
|
||||
}
|
||||
output := []koji.Image{
|
||||
|
|
@ -95,7 +96,7 @@ func main() {
|
|||
ChecksumType: "md5",
|
||||
MD5: hash,
|
||||
Type: "image",
|
||||
RPMs: []koji.RPM{},
|
||||
RPMs: []rpmmd.RPM{},
|
||||
Extra: koji.ImageExtra{
|
||||
Info: koji.ImageExtraInfo{
|
||||
Arch: arch,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
)
|
||||
|
|
@ -146,7 +147,7 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
|
|||
Arch: buildArgs.Arch,
|
||||
},
|
||||
Tools: []koji.Tool{},
|
||||
RPMs: osbuildStagesToRPMs(buildArgs.OSBuildOutput.Build.Stages),
|
||||
RPMs: rpmmd.OSBuildStagesToRPMs(buildArgs.OSBuildOutput.Build.Stages),
|
||||
})
|
||||
images = append(images, koji.Image{
|
||||
BuildRootID: uint64(i),
|
||||
|
|
@ -156,7 +157,7 @@ func (impl *KojiFinalizeJobImpl) Run(job worker.Job) error {
|
|||
ChecksumType: "md5",
|
||||
MD5: buildArgs.ImageHash,
|
||||
Type: "image",
|
||||
RPMs: osbuildStagesToRPMs(buildArgs.OSBuildOutput.Stages),
|
||||
RPMs: rpmmd.OSBuildStagesToRPMs(buildArgs.OSBuildOutput.Stages),
|
||||
Extra: koji.ImageExtra{
|
||||
Info: koji.ImageExtraInfo{
|
||||
Arch: buildArgs.Arch,
|
||||
|
|
|
|||
|
|
@ -30,39 +30,6 @@ type OSBuildJobImpl struct {
|
|||
AzureCreds *azure.Credentials
|
||||
}
|
||||
|
||||
func packageMetadataToSignature(pkg osbuild.RPMPackageMetadata) *string {
|
||||
if pkg.SigGPG != "" {
|
||||
return &pkg.SigGPG
|
||||
} else if pkg.SigPGP != "" {
|
||||
return &pkg.SigPGP
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func osbuildStagesToRPMs(stages []osbuild.StageResult) []koji.RPM {
|
||||
rpms := make([]koji.RPM, 0)
|
||||
for _, stage := range stages {
|
||||
switch metadata := stage.Metadata.(type) {
|
||||
case *osbuild.RPMStageMetadata:
|
||||
for _, pkg := range metadata.Packages {
|
||||
rpms = append(rpms, koji.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 appendTargetError(res *worker.OSBuildJobResult, err error) {
|
||||
errStr := err.Error()
|
||||
log.Printf("target failed: %s", errStr)
|
||||
|
|
|
|||
49
internal/rpmmd/metadata.go
Normal file
49
internal/rpmmd/metadata.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package rpmmd
|
||||
|
||||
import (
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
|
||||
)
|
||||
|
||||
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 OSBuildStagesToRPMs(stages []osbuild.StageResult) []RPM {
|
||||
rpms := make([]RPM, 0)
|
||||
for _, stage := range stages {
|
||||
switch metadata := stage.Metadata.(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
|
||||
}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package main
|
||||
package rpmmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild1"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_osbuildStagesToRPMs(t *testing.T) {
|
||||
|
|
@ -76,12 +76,12 @@ func Test_osbuildStagesToRPMs(t *testing.T) {
|
|||
err := json.Unmarshal([]byte(raw), &stageResults)
|
||||
require.NoError(t, err)
|
||||
|
||||
rpms := osbuildStagesToRPMs(stageResults)
|
||||
rpms := OSBuildStagesToRPMs(stageResults)
|
||||
|
||||
require.Len(t, rpms, 3)
|
||||
|
||||
signature1 := "89023304000108001d162104963a2beb02009608fe67ea4249fd77499570ff3105025f5a272b000a091049fd77499570ff31ccdb0ffe38b95a55ebf3c021526b3cd4f2358c7e23f7767d1f5ce4b7cccef7b33653c6a96a23022313a818fbaf7abeb41837910f0d3ac15664e02838d5939d38ff459aa0076e248728a032d3ae09ddfaec955f941601081a2e3f9bbd49586fd65c1bc1b31685aeb0405687d1791471eab7359ccf00d5584ddef680e99ebc8a4846316391b9baa68ac8ed8ad696ee16fd625d847f8edd92517df3ea6920a46b77b4f119715a0f619f38835d25e0bd0eb5cfad08cd9c796eace6a2b28f4d3dee552e6068255d9748dc2a1906c951e0ba8aed9922ab24e1f659413a06083f8a0bfea56cfff14bddef23bced449f36bcd369da72f90ddf0512e7b0801ba5a0c8eaa8eb0582c630815e992192042cfb0a7c7239f76219197c2fdf18b6553260c105280806d4f037d7b04bdf3da9fd7e9a207db5c71f7e548f4288928f047c989c4cb9cbb8088eec7bd2fa5c252e693f51a3cfc660f666af6a255a5ca0fd2216d5ccd66cbd9c11afa61067d7f615ec8d0dc0c879b5fe633d8c9443f97285da597e4da8a3993af36f0be06acfa9b8058ec70bbc78b876e4c6c5d2108fb05c15a74ba48a3d7ded697cbc1748c228d77d1e0794a41fd5240fa67c3ed745fe47555a47c3d6163d8ce95fd6c2d0d6fa48f8e5b411e571e442109b1cb200d9a8117ee08bfe645f96aca34f7b7559622bbab75143dcad59f126ae0d319e6668ebba417e725638c4febf2e"
|
||||
require.Equal(t, koji.RPM{
|
||||
require.Equal(t, RPM{
|
||||
Type: "rpm",
|
||||
Name: "libgcc",
|
||||
Version: "10.0.1",
|
||||
|
|
@ -14,6 +14,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/kolo/xmlrpc"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/ubccr/kerby/khttp"
|
||||
)
|
||||
|
||||
|
|
@ -63,24 +64,13 @@ type Tool struct {
|
|||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type BuildRoot struct {
|
||||
ID uint64 `json:"id"`
|
||||
Host Host `json:"host"`
|
||||
ContentGenerator ContentGenerator `json:"content_generator"`
|
||||
Container Container `json:"container"`
|
||||
Tools []Tool `json:"tools"`
|
||||
RPMs []RPM `json:"components"`
|
||||
RPMs []rpmmd.RPM `json:"components"`
|
||||
}
|
||||
|
||||
type ImageExtraInfo struct {
|
||||
|
|
@ -93,15 +83,15 @@ type ImageExtra struct {
|
|||
}
|
||||
|
||||
type Image struct {
|
||||
BuildRootID uint64 `json:"buildroot_id"`
|
||||
Filename string `json:"filename"`
|
||||
FileSize uint64 `json:"filesize"`
|
||||
Arch string `json:"arch"`
|
||||
ChecksumType string `json:"checksum_type"` // must be 'md5'
|
||||
MD5 string `json:"checksum"`
|
||||
Type string `json:"type"`
|
||||
RPMs []RPM `json:"components"`
|
||||
Extra ImageExtra `json:"extra"`
|
||||
BuildRootID uint64 `json:"buildroot_id"`
|
||||
Filename string `json:"filename"`
|
||||
FileSize uint64 `json:"filesize"`
|
||||
Arch string `json:"arch"`
|
||||
ChecksumType string `json:"checksum_type"` // must be 'md5'
|
||||
MD5 string `json:"checksum"`
|
||||
Type string `json:"type"`
|
||||
RPMs []rpmmd.RPM `json:"components"`
|
||||
Extra ImageExtra `json:"extra"`
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue