weldr: accept rhsm parameter in sources

The system sources allow specification of the rhsm parameter, but it
isn't available in the sources configured over the Weldr API. This patch
implements support for it.
This commit is contained in:
Martin Sehnoutka 2021-06-09 10:47:42 +02:00 committed by msehnout
parent 05ffdc70aa
commit b950d6e062
5 changed files with 36 additions and 0 deletions

View file

@ -490,6 +490,7 @@ func TestGetSourceInfoV1(t *testing.T) {
check_ssl = true check_ssl = true
check_gpg = true check_gpg = true
gpgkey_urls = ["https://url/path/to/gpg-key"] gpgkey_urls = ["https://url/path/to/gpg-key"]
rhsm = false
` `
source = strings.Replace(source, "REPO-PATH", testState.repoDir, 1) source = strings.Replace(source, "REPO-PATH", testState.repoDir, 1)
@ -503,6 +504,7 @@ func TestGetSourceInfoV1(t *testing.T) {
require.Contains(t, info, "package-repo-info-v1", "No source info returned") require.Contains(t, info, "package-repo-info-v1", "No source info returned")
require.Equal(t, "repo for info test v1", info["package-repo-info-v1"].Name) require.Equal(t, "repo for info test v1", info["package-repo-info-v1"].Name)
require.Equal(t, "file://"+testState.repoDir, info["package-repo-info-v1"].URL) require.Equal(t, "file://"+testState.repoDir, info["package-repo-info-v1"].URL)
require.Equal(t, false, info["package-repo-info-v1"].RHSM)
resp, err = DeleteSourceV1(testState.socket, "package-repo-info-v1") resp, err = DeleteSourceV1(testState.socket, "package-repo-info-v1")
require.NoError(t, err, "DELETE source failed with a client error") require.NoError(t, err, "DELETE source failed with a client error")

View file

@ -63,6 +63,7 @@ type sourceV0 struct {
CheckSSL bool `json:"check_ssl"` CheckSSL bool `json:"check_ssl"`
System bool `json:"system"` System bool `json:"system"`
Distros []string `json:"distros"` Distros []string `json:"distros"`
RHSM bool `json:"rhsm"`
} }
type sourcesV0 map[string]sourceV0 type sourcesV0 map[string]sourceV0

View file

@ -50,6 +50,7 @@ type SourceConfig struct {
CheckSSL bool `json:"check_ssl" toml:"check_ssl"` CheckSSL bool `json:"check_ssl" toml:"check_ssl"`
System bool `json:"system" toml:"system"` System bool `json:"system" toml:"system"`
Distros []string `json:"distros" toml:"distros"` Distros []string `json:"distros" toml:"distros"`
RHSM bool `json:"rhsm" toml:"rhsm"`
} }
type NotFoundError struct { type NotFoundError struct {
@ -576,6 +577,7 @@ func (s *SourceConfig) RepoConfig(name string) rpmmd.RepoConfig {
repo.Name = name repo.Name = name
repo.IgnoreSSL = !s.CheckSSL repo.IgnoreSSL = !s.CheckSSL
repo.CheckGPG = s.CheckGPG repo.CheckGPG = s.CheckGPG
repo.RHSM = s.RHSM
if s.Type == "yum-baseurl" { if s.Type == "yum-baseurl" {
repo.BaseURL = s.URL repo.BaseURL = s.URL

View file

@ -1179,6 +1179,34 @@ check_gpg = false
} }
} }
func TestSourcesInfoTomlV1(t *testing.T) {
tempdir, err := ioutil.TempDir("", "weldr-tests-")
require.NoError(t, err)
defer os.RemoveAll(tempdir)
source := `
id = "fish"
name = "fish"
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
type = "yum-baseurl"
rhsm = true
`
sourceStr := `{"check_gpg":false,"check_ssl":false,"id":"fish","name":"fish","rhsm":true,"system":false,"type":"yum-baseurl","url":"https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"}`
req := httptest.NewRequest("POST", "/api/v1/projects/source/new", bytes.NewReader([]byte(source)))
req.Header.Set("Content-Type", "text/x-toml")
recorder := httptest.NewRecorder()
api, _ := createWeldrAPI(tempdir, rpmmd_mock.BaseFixture)
api.ServeHTTP(recorder, req)
r := recorder.Result()
require.Equal(t, http.StatusOK, r.StatusCode)
test.TestRoute(t, api, true, "GET", "/api/v1/projects/source/info/fish", ``, 200, `{"sources":{"fish":`+sourceStr+`},"errors":[]}`)
test.TestRoute(t, api, true, "GET", "/api/v1/projects/source/info/fish?format=json", ``, 200, `{"sources":{"fish":`+sourceStr+`},"errors":[]}`)
}
// TestSourcesNewWrongTomlV1 Tests that Empty TOML, and invalid TOML should return an error // TestSourcesNewWrongTomlV1 Tests that Empty TOML, and invalid TOML should return an error
func TestSourcesNewWrongTomlV1(t *testing.T) { func TestSourcesNewWrongTomlV1(t *testing.T) {
tempdir, err := ioutil.TempDir("", "weldr-tests-") tempdir, err := ioutil.TempDir("", "weldr-tests-")

View file

@ -187,6 +187,7 @@ func NewSourceConfigV1(id string, s store.SourceConfig) SourceConfigV1 {
sc.CheckSSL = s.CheckSSL sc.CheckSSL = s.CheckSSL
sc.System = s.System sc.System = s.System
sc.Distros = s.Distros sc.Distros = s.Distros
sc.RHSM = s.RHSM
return sc return sc
} }
@ -203,6 +204,7 @@ type SourceConfigV1 struct {
Proxy string `json:"proxy,omitempty" toml:"proxy,omitempty"` Proxy string `json:"proxy,omitempty" toml:"proxy,omitempty"`
GPGUrls []string `json:"gpgkey_urls,omitempty" toml:"gpgkey_urls,omitempty"` GPGUrls []string `json:"gpgkey_urls,omitempty" toml:"gpgkey_urls,omitempty"`
Distros []string `json:"distros,omitempty" toml:"distros,omitempty"` Distros []string `json:"distros,omitempty" toml:"distros,omitempty"`
RHSM bool `json:"rhsm" toml:"rhsm"`
} }
// Key returns the key, .ID in this case // Key returns the key, .ID in this case
@ -229,6 +231,7 @@ func (s SourceConfigV1) SourceConfig() (ssc store.SourceConfig) {
ssc.CheckGPG = s.CheckGPG ssc.CheckGPG = s.CheckGPG
ssc.CheckSSL = s.CheckSSL ssc.CheckSSL = s.CheckSSL
ssc.Distros = s.Distros ssc.Distros = s.Distros
ssc.RHSM = s.RHSM
return ssc return ssc
} }