rpmmd/repository: repoconfig pointers
Convert some of the fields in the `RepoConfig` struct to pointers. Since `RepoConfig` will be used to convert custom repositories to an array of `osbuild.YumRepository`, we need to ensure that fields that are not set explicitly are not saved to the `/etc/yum.repos.d` repository files.
This commit is contained in:
parent
75e2138878
commit
d44703cdc8
14 changed files with 78 additions and 51 deletions
|
|
@ -582,13 +582,19 @@ func (s *Store) GetAllDistroSources(distro string) map[string]SourceConfig {
|
|||
|
||||
func NewSourceConfig(repo rpmmd.RepoConfig, system bool) SourceConfig {
|
||||
sc := SourceConfig{
|
||||
Name: repo.Name,
|
||||
CheckGPG: repo.CheckGPG,
|
||||
CheckSSL: !repo.IgnoreSSL,
|
||||
System: system,
|
||||
RHSM: repo.RHSM,
|
||||
CheckRepoGPG: repo.CheckRepoGPG,
|
||||
GPGKeys: repo.GPGKeys,
|
||||
Name: repo.Name,
|
||||
System: system,
|
||||
RHSM: repo.RHSM,
|
||||
GPGKeys: repo.GPGKeys,
|
||||
CheckSSL: !repo.IgnoreSSL,
|
||||
}
|
||||
|
||||
if repo.CheckGPG != nil {
|
||||
sc.CheckGPG = *repo.CheckGPG
|
||||
}
|
||||
|
||||
if repo.CheckRepoGPG != nil {
|
||||
sc.CheckRepoGPG = *repo.CheckRepoGPG
|
||||
}
|
||||
|
||||
if len(repo.BaseURLs) != 0 {
|
||||
|
|
@ -610,9 +616,9 @@ func (s *SourceConfig) RepoConfig(name string) rpmmd.RepoConfig {
|
|||
|
||||
repo.Name = name
|
||||
repo.IgnoreSSL = !s.CheckSSL
|
||||
repo.CheckGPG = s.CheckGPG
|
||||
repo.CheckGPG = &s.CheckGPG
|
||||
repo.RHSM = s.RHSM
|
||||
repo.CheckRepoGPG = s.CheckRepoGPG
|
||||
repo.CheckRepoGPG = &s.CheckRepoGPG
|
||||
repo.GPGKeys = s.GPGKeys
|
||||
|
||||
var urls []string
|
||||
|
|
|
|||
|
|
@ -422,7 +422,7 @@ func (suite *storeTest) TestNewSourceConfigWithBaseURL() {
|
|||
myRepoConfig := rpmmd.RepoConfig{
|
||||
Name: "testRepo",
|
||||
BaseURLs: []string{"testURL"},
|
||||
CheckGPG: true,
|
||||
CheckGPG: common.ToPtr(true),
|
||||
}
|
||||
expectedSource := SourceConfig{Name: "testRepo", Type: "yum-baseurl", URL: "testURL", CheckGPG: true, CheckSSL: true, System: true}
|
||||
actualSource := NewSourceConfig(myRepoConfig, true)
|
||||
|
|
@ -433,7 +433,7 @@ func (suite *storeTest) TestNewSourceConfigWithMetaLink() {
|
|||
myRepoConfig := rpmmd.RepoConfig{
|
||||
Name: "testRepo",
|
||||
Metalink: "testURL",
|
||||
CheckGPG: true,
|
||||
CheckGPG: common.ToPtr(true),
|
||||
}
|
||||
expectedSource := SourceConfig{Name: "testRepo", Type: "yum-metalink", URL: "testURL", CheckGPG: true, CheckSSL: true, System: true}
|
||||
actualSource := NewSourceConfig(myRepoConfig, true)
|
||||
|
|
@ -452,7 +452,7 @@ func (suite *storeTest) TestNewSourceConfigWithMirrorList() {
|
|||
|
||||
// Test converting a SourceConfig with GPGkeys to a RepoConfig
|
||||
func (suite *storeTest) TestRepoConfigGPGKeys() {
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", BaseURLs: []string{"testURL"}, Metalink: "", MirrorList: "", IgnoreSSL: true, MetadataExpire: "", CheckRepoGPG: true, GPGKeys: []string{"http://path.to.gpgkeys/key.pub", "-----BEGIN PGP PUBLIC KEY BLOCK-----\nFULL GPG KEY HERE\n-----END PGP PUBLIC KEY BLOCK-----"}}
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", BaseURLs: []string{"testURL"}, Metalink: "", MirrorList: "", IgnoreSSL: true, MetadataExpire: "", CheckGPG: common.ToPtr(false), CheckRepoGPG: common.ToPtr(true), GPGKeys: []string{"http://path.to.gpgkeys/key.pub", "-----BEGIN PGP PUBLIC KEY BLOCK-----\nFULL GPG KEY HERE\n-----END PGP PUBLIC KEY BLOCK-----"}}
|
||||
mySourceConfig := suite.mySourceConfig
|
||||
mySourceConfig.Type = "yum-baseurl"
|
||||
mySourceConfig.URL = "testURL"
|
||||
|
|
@ -463,7 +463,7 @@ func (suite *storeTest) TestRepoConfigGPGKeys() {
|
|||
}
|
||||
|
||||
func (suite *storeTest) TestRepoConfigBaseURL() {
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", BaseURLs: []string{"testURL"}, Metalink: "", MirrorList: "", IgnoreSSL: true, MetadataExpire: ""}
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", BaseURLs: []string{"testURL"}, Metalink: "", MirrorList: "", IgnoreSSL: true, CheckGPG: common.ToPtr(false), CheckRepoGPG: common.ToPtr(false), MetadataExpire: ""}
|
||||
suite.mySourceConfig.Type = "yum-baseurl"
|
||||
suite.mySourceConfig.URL = "testURL"
|
||||
actualRepo := suite.mySourceConfig.RepoConfig("testSourceConfig")
|
||||
|
|
@ -471,7 +471,7 @@ func (suite *storeTest) TestRepoConfigBaseURL() {
|
|||
}
|
||||
|
||||
func (suite *storeTest) TestRepoConfigMetalink() {
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", Metalink: "testURL", MirrorList: "", IgnoreSSL: true, MetadataExpire: ""}
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", Metalink: "testURL", MirrorList: "", IgnoreSSL: true, CheckGPG: common.ToPtr(false), CheckRepoGPG: common.ToPtr(false), MetadataExpire: ""}
|
||||
suite.mySourceConfig.Type = "yum-metalink"
|
||||
suite.mySourceConfig.URL = "testURL"
|
||||
actualRepo := suite.mySourceConfig.RepoConfig("testSourceConfig")
|
||||
|
|
@ -479,7 +479,7 @@ func (suite *storeTest) TestRepoConfigMetalink() {
|
|||
}
|
||||
|
||||
func (suite *storeTest) TestRepoConfigMirrorlist() {
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", Metalink: "", MirrorList: "testURL", IgnoreSSL: true, MetadataExpire: ""}
|
||||
expectedRepo := rpmmd.RepoConfig{Name: "testSourceConfig", Metalink: "", MirrorList: "testURL", IgnoreSSL: true, CheckGPG: common.ToPtr(false), CheckRepoGPG: common.ToPtr(false), MetadataExpire: ""}
|
||||
suite.mySourceConfig.Type = "yum-mirrorlist"
|
||||
suite.mySourceConfig.URL = "testURL"
|
||||
actualRepo := suite.mySourceConfig.RepoConfig("testSourceConfig")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue