Delete unused function converting repository BP customization

These functions are leftover from the `osbuild/images` split and are not
used by any code in osbuild composer. Instead, the version in
`osbuild/images` is used by distro definitions.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-10-19 14:07:56 +02:00 committed by Simon de Vlieger
parent d4e3173234
commit 2cc55065b0
2 changed files with 0 additions and 275 deletions

View file

@ -5,10 +5,6 @@ import (
"net/url"
"regexp"
"strings"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/fsnode"
)
type RepositoryCustomization struct {
@ -74,64 +70,3 @@ func (rc *RepositoryCustomization) getFilename() string {
}
return rc.Filename
}
func RepoCustomizationsToRepoConfigAndGPGKeyFiles(repos []RepositoryCustomization) (map[string][]rpmmd.RepoConfig, []*fsnode.File, error) {
if len(repos) == 0 {
return nil, nil, nil
}
repoMap := make(map[string][]rpmmd.RepoConfig, len(repos))
var gpgKeyFiles []*fsnode.File
for _, repo := range repos {
filename := repo.getFilename()
convertedRepo := repo.customRepoToRepoConfig()
// convert any inline gpgkeys to fsnode.File and
// replace the gpgkey with the file path
for idx, gpgkey := range repo.GPGKeys {
if _, ok := url.ParseRequestURI(gpgkey); ok != nil {
// create the file path
path := fmt.Sprintf("/etc/pki/rpm-gpg/RPM-GPG-KEY-%s-%d", repo.Id, idx)
// replace the gpgkey with the file path
convertedRepo.GPGKeys[idx] = fmt.Sprintf("file://%s", path)
// create the fsnode for the gpgkey keyFile
keyFile, err := fsnode.NewFile(path, nil, nil, nil, []byte(gpgkey))
if err != nil {
return nil, nil, err
}
gpgKeyFiles = append(gpgKeyFiles, keyFile)
}
}
repoMap[filename] = append(repoMap[filename], convertedRepo)
}
return repoMap, gpgKeyFiles, nil
}
func (repo RepositoryCustomization) customRepoToRepoConfig() rpmmd.RepoConfig {
urls := make([]string, len(repo.BaseURLs))
copy(urls, repo.BaseURLs)
keys := make([]string, len(repo.GPGKeys))
copy(keys, repo.GPGKeys)
repoConfig := rpmmd.RepoConfig{
Id: repo.Id,
BaseURLs: urls,
GPGKeys: keys,
Name: repo.Name,
Metalink: repo.Metalink,
MirrorList: repo.Mirrorlist,
CheckGPG: repo.GPGCheck,
CheckRepoGPG: repo.RepoGPGCheck,
Priority: repo.Priority,
Enabled: repo.Enabled,
}
if repo.SSLVerify != nil {
repoConfig.IgnoreSSL = common.ToPtr(!*repo.SSLVerify)
}
return repoConfig
}

View file

@ -4,9 +4,7 @@ import (
"fmt"
"testing"
"github.com/osbuild/images/pkg/rpmmd"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/fsnode"
"github.com/stretchr/testify/assert"
)
@ -157,211 +155,3 @@ func TestCustomRepoFilename(t *testing.T) {
})
}
}
func TestCustomRepoToRepoConfigAndGPGKeys(t *testing.T) {
ensureFileCreation := func(file *fsnode.File, err error) *fsnode.File {
t.Helper()
assert.NoError(t, err)
assert.NotNil(t, file)
return file
}
testCases := []struct {
Name string
Repos []RepositoryCustomization
WantRepoConfig map[string][]rpmmd.RepoConfig
WantGPGKeys []*fsnode.File
}{
{
Name: "Test no gpg keys, no filenames",
Repos: []RepositoryCustomization{
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
},
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
},
},
WantRepoConfig: map[string][]rpmmd.RepoConfig{
"example-1.repo": {
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{},
},
},
"example-2.repo": {
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{},
},
},
},
WantGPGKeys: nil,
},
{
Name: "Test no gpg keys, filenames",
Repos: []RepositoryCustomization{
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
Filename: "test-1.repo",
},
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
Filename: "test-2.repo",
},
},
WantRepoConfig: map[string][]rpmmd.RepoConfig{
"test-1.repo": {
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{},
},
},
"test-2.repo": {
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{},
},
},
},
WantGPGKeys: nil,
},
{
Name: "Test remote gpgkeys",
Repos: []RepositoryCustomization{
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{"http://example-1.com/gpgkey"},
GPGCheck: common.ToPtr(true),
},
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{"http://example-2.com/gpgkey"},
GPGCheck: common.ToPtr(true),
},
},
WantRepoConfig: map[string][]rpmmd.RepoConfig{
"example-1.repo": {
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{"http://example-1.com/gpgkey"},
CheckGPG: common.ToPtr(true),
},
},
"example-2.repo": {
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{"http://example-2.com/gpgkey"},
CheckGPG: common.ToPtr(true),
},
},
},
WantGPGKeys: nil,
},
{
Name: "Test inline gpgkeys",
Repos: []RepositoryCustomization{
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{"-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n"},
GPGCheck: common.ToPtr(true),
},
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{"-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-2-----END PGP PUBLIC KEY BLOCK-----\n"},
GPGCheck: common.ToPtr(true),
},
},
WantRepoConfig: map[string][]rpmmd.RepoConfig{
"example-1.repo": {
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example-1-0"},
CheckGPG: common.ToPtr(true),
},
},
"example-2.repo": {
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example-2-0"},
CheckGPG: common.ToPtr(true),
},
},
},
WantGPGKeys: []*fsnode.File{
ensureFileCreation(fsnode.NewFile("/etc/pki/rpm-gpg/RPM-GPG-KEY-example-1-0", nil, nil, nil, []byte("-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n"))),
ensureFileCreation(fsnode.NewFile("/etc/pki/rpm-gpg/RPM-GPG-KEY-example-2-0", nil, nil, nil, []byte("-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n"))),
},
},
{
Name: "Test multiple inline gpgkeys",
Repos: []RepositoryCustomization{
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{
"-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n",
"-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-2-----END PGP PUBLIC KEY BLOCK-----\n",
},
GPGCheck: common.ToPtr(true),
},
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{
"-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n",
"-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-2-----END PGP PUBLIC KEY BLOCK-----\n",
},
GPGCheck: common.ToPtr(true),
},
},
WantRepoConfig: map[string][]rpmmd.RepoConfig{
"example-1.repo": {
{
Id: "example-1",
BaseURLs: []string{"http://example-1.com"},
GPGKeys: []string{"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example-1-0", "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example-1-1"},
CheckGPG: common.ToPtr(true),
},
},
"example-2.repo": {
{
Id: "example-2",
BaseURLs: []string{"http://example-2.com"},
GPGKeys: []string{"file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example-2-0", "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-example-2-1"},
CheckGPG: common.ToPtr(true),
},
},
},
WantGPGKeys: []*fsnode.File{
ensureFileCreation(fsnode.NewFile("/etc/pki/rpm-gpg/RPM-GPG-KEY-example-1-0", nil, nil, nil, []byte("-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n"))),
ensureFileCreation(fsnode.NewFile("/etc/pki/rpm-gpg/RPM-GPG-KEY-example-1-1", nil, nil, nil, []byte("-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-2-----END PGP PUBLIC KEY BLOCK-----\n"))),
ensureFileCreation(fsnode.NewFile("/etc/pki/rpm-gpg/RPM-GPG-KEY-example-2-0", nil, nil, nil, []byte("-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-1-----END PGP PUBLIC KEY BLOCK-----\n"))),
ensureFileCreation(fsnode.NewFile("/etc/pki/rpm-gpg/RPM-GPG-KEY-example-2-1", nil, nil, nil, []byte("-----BEGIN PGP PUBLIC KEY BLOCK-----fake-gpg-key-2-----END PGP PUBLIC KEY BLOCK-----\n"))),
},
},
}
for _, tt := range testCases {
t.Run(tt.Name, func(t *testing.T) {
got, _, err := RepoCustomizationsToRepoConfigAndGPGKeyFiles(tt.Repos)
assert.NoError(t, err)
assert.Equal(t, tt.WantRepoConfig, got)
})
}
}