internal/rpmmd: add missing fields to RepoConfig

Further align the RepoConfig object to the dnf
spec and add missing fields.
This commit is contained in:
Gianluca Zuccarelli 2023-01-23 17:59:34 +00:00 committed by Tomáš Hozza
parent d44703cdc8
commit 3b6fddb14a
4 changed files with 41 additions and 15 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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"`
}

View file

@ -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"},
},