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

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