From 3b6fddb14a1de82b80cf80e88d5ff9655986e115 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Mon, 23 Jan 2023 17:59:34 +0000 Subject: [PATCH] internal/rpmmd: add missing fields to RepoConfig Further align the RepoConfig object to the dnf spec and add missing fields. --- cmd/gen-manifests/main.go | 9 ++++++--- cmd/osbuild-pipeline/main.go | 25 +++++++++++++++++-------- internal/rpmmd/repository.go | 6 ++++++ internal/rpmmd/test/repository_test.go | 16 ++++++++++++---- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/cmd/gen-manifests/main.go b/cmd/gen-manifests/main.go index 1651fb72a..6cda1c3b3 100644 --- a/cmd/gen-manifests/main.go +++ b/cmd/gen-manifests/main.go @@ -17,7 +17,6 @@ import ( "strings" "github.com/osbuild/osbuild-composer/internal/blueprint" - "github.com/osbuild/osbuild-composer/internal/common" "github.com/osbuild/osbuild-composer/internal/container" "github.com/osbuild/osbuild-composer/internal/distro" "github.com/osbuild/osbuild-composer/internal/distroregistry" @@ -39,11 +38,14 @@ func (mv *multiValue) Set(v string) error { type repository struct { Name string `json:"name"` + Id string `json:"id,omitempty"` BaseURL string `json:"baseurl,omitempty"` Metalink string `json:"metalink,omitempty"` MirrorList string `json:"mirrorlist,omitempty"` GPGKey string `json:"gpgkey,omitempty"` CheckGPG bool `json:"check_gpg,omitempty"` + CheckRepoGPG bool `json:"check_repo_gpg,omitempty"` + IgnoreSSL bool `json:"ignore_ssl,omitempty"` RHSM bool `json:"rhsm,omitempty"` MetadataExpire string `json:"metadata_expire,omitempty"` ImageTypeTags []string `json:"image_type_tags,omitempty"` @@ -199,14 +201,15 @@ func convertRepo(r repository) rpmmd.RepoConfig { } return rpmmd.RepoConfig{ + Id: r.Id, Name: r.Name, BaseURLs: urls, Metalink: r.Metalink, MirrorList: r.MirrorList, GPGKeys: keys, CheckGPG: &r.CheckGPG, - CheckRepoGPG: common.ToPtr(false), - IgnoreSSL: false, + CheckRepoGPG: &r.CheckRepoGPG, + IgnoreSSL: r.IgnoreSSL, MetadataExpire: r.MetadataExpire, RHSM: r.RHSM, ImageTypeTags: r.ImageTypeTags, diff --git a/cmd/osbuild-pipeline/main.go b/cmd/osbuild-pipeline/main.go index 25f50031a..21930ca99 100644 --- a/cmd/osbuild-pipeline/main.go +++ b/cmd/osbuild-pipeline/main.go @@ -19,14 +19,17 @@ import ( ) type repository struct { - Name string `json:"name,omitempty"` - BaseURL string `json:"baseurl,omitempty"` - Metalink string `json:"metalink,omitempty"` - MirrorList string `json:"mirrorlist,omitempty"` - GPGKey string `json:"gpgkey,omitempty"` - CheckGPG bool `json:"check_gpg,omitempty"` - PackageSets []string `json:"package_sets,omitempty"` - RHSM bool `json:"rhsm,omitempty"` + Id string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + BaseURL string `json:"baseurl,omitempty"` + Metalink string `json:"metalink,omitempty"` + MirrorList string `json:"mirrorlist,omitempty"` + GPGKey string `json:"gpgkey,omitempty"` + CheckGPG bool `json:"check_gpg,omitempty"` + CheckRepoGPG bool `json:"repo_check_gpg,omitempty"` + IgnoreSSL bool `json:"ignore_ssl,omitempty"` + PackageSets []string `json:"package_sets,omitempty"` + RHSM bool `json:"rhsm,omitempty"` } type ostreeOptions struct { @@ -141,6 +144,10 @@ func main() { if repoName == "" { repoName = fmt.Sprintf("repo-%d", i) } + repoId := repo.Id + if repoId == "" { + repoId = fmt.Sprintf("repo-%d", i) + } var urls []string if repo.BaseURL != "" { urls = []string{repo.BaseURL} @@ -149,7 +156,9 @@ func main() { if repo.GPGKey != "" { keys = []string{repo.GPGKey} } + repos[i] = rpmmd.RepoConfig{ + Id: repoId, Name: repoName, BaseURLs: urls, Metalink: repo.Metalink, diff --git a/internal/rpmmd/repository.go b/internal/rpmmd/repository.go index 98f0fef74..b68ec5277 100644 --- a/internal/rpmmd/repository.go +++ b/internal/rpmmd/repository.go @@ -28,6 +28,10 @@ type repository struct { } type RepoConfig struct { + // the repo id is not always required and is ignored in some cases. + // For example, it is not required in dnf-json, but it is a required + // field for creating a repo file in `/etc/yum.repos.d/` + Id string `json:"id,omitempty"` Name string `json:"name,omitempty"` BaseURLs []string `json:"baseurls,omitempty"` Metalink string `json:"metalink,omitempty"` @@ -35,9 +39,11 @@ type RepoConfig struct { GPGKeys []string `json:"gpgkeys,omitempty"` CheckGPG *bool `json:"check_gpg,omitempty"` CheckRepoGPG *bool `json:"check_repo_gpg,omitempty"` + Priority *int `json:"priority,omitempty"` IgnoreSSL bool `json:"ignore_ssl,omitempty"` MetadataExpire string `json:"metadata_expire,omitempty"` RHSM bool `json:"rhsm,omitempty"` + Enabled *bool `json:"enabled,omitempty"` ImageTypeTags []string `json:"image_type_tags,omitempty"` PackageSets []string `json:"package_sets,omitempty"` } diff --git a/internal/rpmmd/test/repository_test.go b/internal/rpmmd/test/repository_test.go index 2bb412e0a..83b95965c 100644 --- a/internal/rpmmd/test/repository_test.go +++ b/internal/rpmmd/test/repository_test.go @@ -212,8 +212,9 @@ func TestOldWorkerRepositoryCompatUnmarshal(t *testing.T) { }, }, { - repoJSON: []byte(`{"name":"all","baseurls":["http://example.com/all"],"metalink":"http://example.com/metalink","mirrorlist":"http://example.com/mirrorlist","gpgkeys":["key1","key2"],"check_gpg":true,"check_repo_gpg":true,"ignore_ssl":true,"metadata_expire":"test","rhsm":true,"image_type_tags":["one","two"],"package_sets":["1","2"],"baseurl":"http://example.com/all"}`), + repoJSON: []byte(`{"id":"all","name":"all","baseurls":["http://example.com/all"],"metalink":"http://example.com/metalink","mirrorlist":"http://example.com/mirrorlist","gpgkeys":["key1","key2"],"check_gpg":true,"check_repo_gpg":true,"ignore_ssl":true,"priority":10,"metadata_expire":"test","rhsm":true,"enabled":true,"image_type_tags":["one","two"],"package_sets":["1","2"],"baseurl":"http://example.com/all"}`), repo: rpmmd.RepoConfig{ + Id: "all", Name: "all", BaseURLs: []string{"http://example.com/all"}, Metalink: "http://example.com/metalink", @@ -222,8 +223,10 @@ func TestOldWorkerRepositoryCompatUnmarshal(t *testing.T) { CheckGPG: common.ToPtr(true), CheckRepoGPG: common.ToPtr(true), IgnoreSSL: true, + Priority: common.ToPtr(10), MetadataExpire: "test", RHSM: true, + Enabled: common.ToPtr(true), ImageTypeTags: []string{"one", "two"}, PackageSets: []string{"1", "2"}, }, @@ -246,22 +249,25 @@ func TestOldWorkerRepositoryCompatMarshal(t *testing.T) { repo rpmmd.RepoConfig }{ { - repoJSON: []byte(`{"name":"fedora","baseurls":["http://example.com/fedora"],"baseurl":"http://example.com/fedora"}`), + repoJSON: []byte(`{"id":"fedora","name":"fedora","baseurls":["http://example.com/fedora"],"baseurl":"http://example.com/fedora"}`), repo: rpmmd.RepoConfig{ + Id: "fedora", Name: "fedora", BaseURLs: []string{"http://example.com/fedora"}, }, }, { - repoJSON: []byte(`{"name":"multiple","baseurls":["http://example.com/one","http://example.com/two"],"baseurl":"http://example.com/one,http://example.com/two"}`), + repoJSON: []byte(`{"id":"multiple","name":"multiple","baseurls":["http://example.com/one","http://example.com/two"],"baseurl":"http://example.com/one,http://example.com/two"}`), repo: rpmmd.RepoConfig{ + Id: "multiple", Name: "multiple", BaseURLs: []string{"http://example.com/one", "http://example.com/two"}, }, }, { - repoJSON: []byte(`{"name":"all","baseurls":["http://example.com/all"],"metalink":"http://example.com/metalink","mirrorlist":"http://example.com/mirrorlist","gpgkeys":["key1","key2"],"check_gpg":true,"check_repo_gpg":true,"ignore_ssl":true,"metadata_expire":"test","rhsm":true,"image_type_tags":["one","two"],"package_sets":["1","2"],"baseurl":"http://example.com/all"}`), + repoJSON: []byte(`{"id":"all","name":"all","baseurls":["http://example.com/all"],"metalink":"http://example.com/metalink","mirrorlist":"http://example.com/mirrorlist","gpgkeys":["key1","key2"],"check_gpg":true,"check_repo_gpg":true,"priority":10,"ignore_ssl":true,"metadata_expire":"test","rhsm":true,"enabled":true,"image_type_tags":["one","two"],"package_sets":["1","2"],"baseurl":"http://example.com/all"}`), repo: rpmmd.RepoConfig{ + Id: "all", Name: "all", BaseURLs: []string{"http://example.com/all"}, Metalink: "http://example.com/metalink", @@ -269,9 +275,11 @@ func TestOldWorkerRepositoryCompatMarshal(t *testing.T) { GPGKeys: []string{"key1", "key2"}, CheckGPG: common.ToPtr(true), CheckRepoGPG: common.ToPtr(true), + Priority: common.ToPtr(10), IgnoreSSL: true, MetadataExpire: "test", RHSM: true, + Enabled: common.ToPtr(true), ImageTypeTags: []string{"one", "two"}, PackageSets: []string{"1", "2"}, },