Skip to content
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

rpmmd,dnfjson: add Path, RepoID to PackageSpec for librepo #1140

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/dnfjson/dnfjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ func (result depsolveResult) toRPMMD(rhsm map[string]bool) ([]rpmmd.PackageSpec,
rpmDependencies[i].RemoteLocation = dep.RemoteLocation
rpmDependencies[i].Checksum = dep.Checksum
rpmDependencies[i].CheckGPG = repo.GPGCheck
rpmDependencies[i].RepoID = dep.RepoID
rpmDependencies[i].Path = dep.Path
if verify := repo.SSLVerify; verify != nil {
rpmDependencies[i].IgnoreSSL = !*verify
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/dnfjson/dnfjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ func TestDepsolver(t *testing.T) {
require.NotNil(t, res)
}

assert.Equal(expectedResult(s.RepoConfig), res.Packages)
assert.Equal(len(res.Repos), 1)
assert.Equal(expectedResult(res.Repos[0]), res.Packages)

if tc.sbomType != sbom.StandardTypeNone {
require.NotNil(t, res.SBOM)
Expand Down Expand Up @@ -725,6 +726,8 @@ func expectedResult(repo rpmmd.RepoConfig) []rpmmd.PackageSpec {
for idx := range exp {
urlTemplate := exp[idx].RemoteLocation
exp[idx].RemoteLocation = fmt.Sprintf(urlTemplate, strings.Join(repo.BaseURLs, ","))
exp[idx].Path = strings.TrimPrefix(urlTemplate, "%s/")
exp[idx].RepoID = repo.Id
}
return exp
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ func (m Manifest) GetOSTreeSourceSpecs() map[string][]ostree.SourceSpec {
return ostreeSpecs
}

// TODO: change signature to map[string]Inputs
// TODO: change signature to map[string]Inputs and/or ensure that
// only depsolved PackageSpecs/RepoConfigs are passed so that we
// have a valid mapping of pkg.RepoID<->repo.Id which will be important
// for librepo
func (m Manifest) Serialize(packageSets map[string][]rpmmd.PackageSpec, containerSpecs map[string][]container.Spec, ostreeCommits map[string][]ostree.CommitSpec, rpmRepos map[string][]rpmmd.RepoConfig) (OSBuildManifest, error) {
pipelines := make([]osbuild.Pipeline, 0)
packages := make([]rpmmd.PackageSpec, 0)
Expand Down
3 changes: 3 additions & 0 deletions pkg/rpmmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ type PackageSpec struct {
Secrets string `json:"secrets,omitempty"`
CheckGPG bool `json:"check_gpg,omitempty"`
IgnoreSSL bool `json:"ignore_ssl,omitempty"`

Path string `json:"path,omitempty"`
RepoID string `json:"repo_id,omitempty"`
}

type PackageSource struct {
Expand Down
42 changes: 41 additions & 1 deletion pkg/rpmmd/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,46 @@ func TestPackageSpecGetNEVRA(t *testing.T) {

func TestRepoConfigMarshalEmpty(t *testing.T) {
repoCfg := &RepoConfig{}
js, _ := json.Marshal(repoCfg)
js, err := json.Marshal(repoCfg)
assert.NoError(t, err)
assert.Equal(t, string(js), `{}`)
}

func TestPackageSpecEmptyJson(t *testing.T) {
pkg := &PackageSpec{Name: "pkg1"}
js, err := json.Marshal(pkg)
assert.NoError(t, err)
assert.Equal(t, string(js), `{"name":"pkg1","epoch":0}`)
}

func TestPackageSpecFull(t *testing.T) {
pkg := &PackageSpec{
Name: "acl",
Epoch: 0,
Version: "2.3.1",
Release: "3.el9",
Arch: "x86_64",
RemoteLocation: "http://example.com/repo/Packages/acl-2.3.1-3.el9.x86_64.rpm",
Checksum: "sha256:986044c3837eddbc9231d7be5e5fc517e245296978b988a803bc9f9172fe84ea",
Secrets: "",
CheckGPG: false,
IgnoreSSL: true,
Path: "Packages/acl-2.3.1-3.el9.x86_64.rpm",
RepoID: "813859d10fe28ff54dbde44655a18b071c8adbaa849a551ec23cc415f0f7f1b0",
}

js, err := json.MarshalIndent(pkg, "", " ")
assert.NoError(t, err)
assert.Equal(t, string(js), `{
"name": "acl",
"epoch": 0,
"version": "2.3.1",
"release": "3.el9",
"arch": "x86_64",
"remote_location": "http://example.com/repo/Packages/acl-2.3.1-3.el9.x86_64.rpm",
"checksum": "sha256:986044c3837eddbc9231d7be5e5fc517e245296978b988a803bc9f9172fe84ea",
"ignore_ssl": true,
"path": "Packages/acl-2.3.1-3.el9.x86_64.rpm",
"repo_id": "813859d10fe28ff54dbde44655a18b071c8adbaa849a551ec23cc415f0f7f1b0"
}`)
}
Loading