diff --git a/cmd/gen-manifests/main.go b/cmd/gen-manifests/main.go index 70eb5d9f1..1651fb72a 100644 --- a/cmd/gen-manifests/main.go +++ b/cmd/gen-manifests/main.go @@ -17,6 +17,7 @@ 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" @@ -203,8 +204,8 @@ func convertRepo(r repository) rpmmd.RepoConfig { Metalink: r.Metalink, MirrorList: r.MirrorList, GPGKeys: keys, - CheckGPG: r.CheckGPG, - CheckRepoGPG: false, + CheckGPG: &r.CheckGPG, + CheckRepoGPG: common.ToPtr(false), IgnoreSSL: false, MetadataExpire: r.MetadataExpire, RHSM: r.RHSM, diff --git a/cmd/osbuild-pipeline/main.go b/cmd/osbuild-pipeline/main.go index 89ceb7bda..25f50031a 100644 --- a/cmd/osbuild-pipeline/main.go +++ b/cmd/osbuild-pipeline/main.go @@ -8,6 +8,7 @@ import ( "os" "path" + "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" @@ -149,14 +150,16 @@ func main() { keys = []string{repo.GPGKey} } repos[i] = rpmmd.RepoConfig{ - Name: repoName, - BaseURLs: urls, - Metalink: repo.Metalink, - MirrorList: repo.MirrorList, - GPGKeys: keys, - CheckGPG: repo.CheckGPG, - PackageSets: repo.PackageSets, - RHSM: repo.RHSM, + Name: repoName, + BaseURLs: urls, + Metalink: repo.Metalink, + MirrorList: repo.MirrorList, + GPGKeys: keys, + CheckGPG: &repo.CheckGPG, + CheckRepoGPG: common.ToPtr(false), + IgnoreSSL: false, + PackageSets: repo.PackageSets, + RHSM: repo.RHSM, } } diff --git a/internal/blueprint/repository_customizations_test.go b/internal/blueprint/repository_customizations_test.go index eb9918d09..fd5b57648 100644 --- a/internal/blueprint/repository_customizations_test.go +++ b/internal/blueprint/repository_customizations_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/osbuild/osbuild-composer/internal/common" "github.com/stretchr/testify/assert" ) diff --git a/internal/cloudapi/v2/handler.go b/internal/cloudapi/v2/handler.go index 5c9fd3b06..de5be01e2 100644 --- a/internal/cloudapi/v2/handler.go +++ b/internal/cloudapi/v2/handler.go @@ -1363,7 +1363,7 @@ func genRepoConfig(repo Repository) (*rpmmd.RepoConfig, error) { } if repo.CheckGpg != nil { - repoConfig.CheckGPG = *repo.CheckGpg + repoConfig.CheckGPG = repo.CheckGpg } if repo.Gpgkey != nil && *repo.Gpgkey != "" { repoConfig.GPGKeys = []string{*repo.Gpgkey} @@ -1372,10 +1372,10 @@ func genRepoConfig(repo Repository) (*rpmmd.RepoConfig, error) { repoConfig.IgnoreSSL = *repo.IgnoreSsl } if repo.CheckRepoGpg != nil { - repoConfig.CheckRepoGPG = *repo.CheckRepoGpg + repoConfig.CheckRepoGPG = repo.CheckRepoGpg } - if repoConfig.CheckGPG && len(repoConfig.GPGKeys) == 0 { + if repoConfig.CheckGPG != nil && *repoConfig.CheckGPG && len(repoConfig.GPGKeys) == 0 { return nil, HTTPError(ErrorNoGPGKey) } diff --git a/internal/cloudapi/v2/v2_internal_test.go b/internal/cloudapi/v2/v2_internal_test.go index e2e44ef5f..59e4e925e 100644 --- a/internal/cloudapi/v2/v2_internal_test.go +++ b/internal/cloudapi/v2/v2_internal_test.go @@ -108,7 +108,7 @@ func TestRepoConfigConversion(t *testing.T) { Metalink: "", MirrorList: "", GPGKeys: []string{"some-kind-of-key"}, - CheckGPG: true, + CheckGPG: common.ToPtr(true), IgnoreSSL: false, MetadataExpire: "", RHSM: false, @@ -131,7 +131,7 @@ func TestRepoConfigConversion(t *testing.T) { BaseURLs: []string{"http://base.url"}, Metalink: "", // since BaseURL is specified, MetaLink is not copied MirrorList: "", // since BaseURL is specified, MirrorList is not copied - CheckGPG: false, + CheckGPG: nil, IgnoreSSL: true, MetadataExpire: "", RHSM: false, @@ -153,7 +153,7 @@ func TestRepoConfigConversion(t *testing.T) { Name: "", Metalink: "", // since MirrorList is specified, MetaLink is not copied MirrorList: "http://example.org/mirrorlist", - CheckGPG: false, + CheckGPG: nil, IgnoreSSL: true, MetadataExpire: "", RHSM: false, @@ -175,7 +175,7 @@ func TestRepoConfigConversion(t *testing.T) { Name: "", Metalink: "http://example.org/metalink", MirrorList: "", - CheckGPG: false, + CheckGPG: nil, IgnoreSSL: true, MetadataExpire: "", RHSM: true, diff --git a/internal/distro/distro_test.go b/internal/distro/distro_test.go index fc86f6c76..7afc2fdc8 100644 --- a/internal/distro/distro_test.go +++ b/internal/distro/distro_test.go @@ -7,6 +7,7 @@ import ( "testing" "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/distro/distro_test_common" @@ -203,7 +204,7 @@ func TestImageTypePipelineNames(t *testing.T) { BaseURLs: []string{"http://payload.example.com"}, PackageSets: imageType.PayloadPackageSets(), GPGKeys: []string{"payload-gpg-key"}, - CheckGPG: true, + CheckGPG: common.ToPtr(true), }, } containers := make([]container.Spec, 0) diff --git a/internal/distro/distro_test_common/distro_test_common.go b/internal/distro/distro_test_common/distro_test_common.go index a64d0b562..759c5d37c 100644 --- a/internal/distro/distro_test_common/distro_test_common.go +++ b/internal/distro/distro_test_common/distro_test_common.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "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" @@ -76,7 +77,7 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis Metalink: repo.Metalink, MirrorList: repo.MirrorList, GPGKeys: keys, - CheckGPG: repo.CheckGPG, + CheckGPG: common.ToPtr(repo.CheckGPG), PackageSets: repo.PackageSets, } } diff --git a/internal/dnfjson/dnfjson.go b/internal/dnfjson/dnfjson.go index 021edb6f2..f9de0e9ac 100644 --- a/internal/dnfjson/dnfjson.go +++ b/internal/dnfjson/dnfjson.go @@ -266,11 +266,18 @@ func (s *Solver) reposFromRPMMD(rpmRepos []rpmmd.RepoConfig) ([]repoConfig, erro Metalink: rr.Metalink, MirrorList: rr.MirrorList, GPGKeys: rr.GPGKeys, - CheckGPG: rr.CheckGPG, - CheckRepoGPG: rr.CheckRepoGPG, IgnoreSSL: rr.IgnoreSSL, MetadataExpire: rr.MetadataExpire, } + + if rr.CheckGPG != nil { + dr.CheckGPG = *rr.CheckGPG + } + + if rr.CheckRepoGPG != nil { + dr.CheckRepoGPG = *rr.CheckRepoGPG + } + if rr.RHSM { if s.subscriptions == nil { return nil, fmt.Errorf("This system does not have any valid subscriptions. Subscribe it before specifying rhsm: true in sources.") @@ -457,7 +464,9 @@ func (pkgs packageSpecs) toRPMMD(repos map[string]rpmmd.RepoConfig) []rpmmd.Pack rpmDependencies[i].Arch = dep.Arch rpmDependencies[i].RemoteLocation = dep.RemoteLocation rpmDependencies[i].Checksum = dep.Checksum - rpmDependencies[i].CheckGPG = repo.CheckGPG + if repo.CheckGPG != nil { + rpmDependencies[i].CheckGPG = *repo.CheckGPG + } rpmDependencies[i].IgnoreSSL = repo.IgnoreSSL if repo.RHSM { rpmDependencies[i].Secrets = "org.osbuild.rhsm" diff --git a/internal/mocks/rpmrepo/rpmrepo.go b/internal/mocks/rpmrepo/rpmrepo.go index 8c98c349d..cfb065aa3 100644 --- a/internal/mocks/rpmrepo/rpmrepo.go +++ b/internal/mocks/rpmrepo/rpmrepo.go @@ -6,6 +6,7 @@ import ( "net/http/httptest" "os" + "github.com/osbuild/osbuild-composer/internal/common" "github.com/osbuild/osbuild-composer/internal/rpmmd" ) @@ -19,7 +20,7 @@ func NewTestServer() *testRepoServer { testrepo := rpmmd.RepoConfig{ Name: "cs9-baseos", BaseURLs: []string{server.URL}, - CheckGPG: false, + CheckGPG: common.ToPtr(false), IgnoreSSL: true, RHSM: false, } diff --git a/internal/rpmmd/repository.go b/internal/rpmmd/repository.go index cc84b0c50..98f0fef74 100644 --- a/internal/rpmmd/repository.go +++ b/internal/rpmmd/repository.go @@ -33,8 +33,8 @@ type RepoConfig struct { Metalink string `json:"metalink,omitempty"` MirrorList string `json:"mirrorlist,omitempty"` GPGKeys []string `json:"gpgkeys,omitempty"` - CheckGPG bool `json:"check_gpg,omitempty"` - CheckRepoGPG bool `json:"check_repo_gpg,omitempty"` + CheckGPG *bool `json:"check_gpg,omitempty"` + CheckRepoGPG *bool `json:"check_repo_gpg,omitempty"` IgnoreSSL bool `json:"ignore_ssl,omitempty"` MetadataExpire string `json:"metadata_expire,omitempty"` RHSM bool `json:"rhsm,omitempty"` @@ -49,6 +49,9 @@ func (r *RepoConfig) Hash() string { bts := func(b bool) string { return fmt.Sprintf("%T", b) } + bpts := func(b *bool) string { + return fmt.Sprintf("%T", b) + } ats := func(s []string) string { return strings.Join(s, "") } @@ -56,8 +59,8 @@ func (r *RepoConfig) Hash() string { r.Metalink+ r.MirrorList+ ats(r.GPGKeys)+ - bts(r.CheckGPG)+ - bts(r.CheckRepoGPG)+ + bpts(r.CheckGPG)+ + bpts(r.CheckRepoGPG)+ bts(r.IgnoreSSL)+ r.MetadataExpire+ bts(r.RHSM)))) @@ -237,7 +240,7 @@ func loadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error) Metalink: repo.Metalink, MirrorList: repo.MirrorList, GPGKeys: keys, - CheckGPG: repo.CheckGPG, + CheckGPG: &repo.CheckGPG, RHSM: repo.RHSM, MetadataExpire: repo.MetadataExpire, ImageTypeTags: repo.ImageTypeTags, diff --git a/internal/rpmmd/test/repository_test.go b/internal/rpmmd/test/repository_test.go index 549e9b4a6..2bb412e0a 100644 --- a/internal/rpmmd/test/repository_test.go +++ b/internal/rpmmd/test/repository_test.go @@ -7,6 +7,7 @@ import ( "reflect" "testing" + "github.com/osbuild/osbuild-composer/internal/common" "github.com/osbuild/osbuild-composer/internal/distro/test_distro" "github.com/osbuild/osbuild-composer/internal/rpmmd" "github.com/stretchr/testify/assert" @@ -218,8 +219,8 @@ func TestOldWorkerRepositoryCompatUnmarshal(t *testing.T) { Metalink: "http://example.com/metalink", MirrorList: "http://example.com/mirrorlist", GPGKeys: []string{"key1", "key2"}, - CheckGPG: true, - CheckRepoGPG: true, + CheckGPG: common.ToPtr(true), + CheckRepoGPG: common.ToPtr(true), IgnoreSSL: true, MetadataExpire: "test", RHSM: true, @@ -266,8 +267,8 @@ func TestOldWorkerRepositoryCompatMarshal(t *testing.T) { Metalink: "http://example.com/metalink", MirrorList: "http://example.com/mirrorlist", GPGKeys: []string{"key1", "key2"}, - CheckGPG: true, - CheckRepoGPG: true, + CheckGPG: common.ToPtr(true), + CheckRepoGPG: common.ToPtr(true), IgnoreSSL: true, MetadataExpire: "test", RHSM: true, diff --git a/internal/store/store.go b/internal/store/store.go index ad43a0ef8..8adc19286 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -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 diff --git a/internal/store/store_test.go b/internal/store/store_test.go index 742b719d7..1eb0594aa 100644 --- a/internal/store/store_test.go +++ b/internal/store/store_test.go @@ -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") diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 58252f6af..66db48e6d 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -63,12 +63,12 @@ func createWeldrAPI(tempdir string, fixtureGenerator rpmmd_mock.FixtureGenerator rr := reporegistry.NewFromDistrosRepoConfigs(rpmmd.DistrosRepoConfigs{ test_distro.TestDistroName: { test_distro.TestArchName: { - {Name: "test-id", BaseURLs: []string{"http://example.com/test/os/x86_64"}, CheckGPG: true}, + {Name: "test-id", BaseURLs: []string{"http://example.com/test/os/x86_64"}, CheckGPG: common.ToPtr(true)}, }, }, test_distro.TestDistro2Name: { test_distro.TestArchName: { - {Name: "test-id-2", BaseURLs: []string{"http://example.com/test-2/os/x86_64"}, CheckGPG: true}, + {Name: "test-id-2", BaseURLs: []string{"http://example.com/test-2/os/x86_64"}, CheckGPG: common.ToPtr(true)}, }, }, }) @@ -112,12 +112,12 @@ func createWeldrAPI2(tempdir string, fixtureGenerator rpmmd_mock.FixtureGenerato rr := reporegistry.NewFromDistrosRepoConfigs(rpmmd.DistrosRepoConfigs{ test_distro.TestDistroName: { test_distro.TestArch2Name: { - {Name: "test-id", BaseURLs: []string{"http://example.com/test/os/x86_64"}, CheckGPG: true}, + {Name: "test-id", BaseURLs: []string{"http://example.com/test/os/x86_64"}, CheckGPG: common.ToPtr(true)}, }, }, test_distro.TestDistro2Name: { test_distro.TestArch2Name: { - {Name: "test-id-2", BaseURLs: []string{"http://example.com/test-2/os/x86_64"}, CheckGPG: true}, + {Name: "test-id-2", BaseURLs: []string{"http://example.com/test-2/os/x86_64"}, CheckGPG: common.ToPtr(true)}, }, }, })