weldr: make projects/source/new accept text/x-toml
composer-cli sends sources as toml if the original format is toml.
This commit is contained in:
parent
7036c157fb
commit
72e1da47ab
2 changed files with 36 additions and 5 deletions
|
|
@ -313,17 +313,25 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque
|
|||
}
|
||||
|
||||
contentType := request.Header["Content-Type"]
|
||||
if len(contentType) != 1 || contentType[0] != "application/json" {
|
||||
if len(contentType) == 0 {
|
||||
errors := responseError{
|
||||
ID: "HTTPError",
|
||||
Msg: "Internal Server Error",
|
||||
Msg: "malformed Content-Type header",
|
||||
}
|
||||
statusResponseError(writer, http.StatusInternalServerError, errors)
|
||||
statusResponseError(writer, http.StatusBadRequest, errors)
|
||||
return
|
||||
}
|
||||
|
||||
var source store.SourceConfig
|
||||
err := json.NewDecoder(request.Body).Decode(&source)
|
||||
var err error
|
||||
if contentType[0] == "application/json" {
|
||||
err = json.NewDecoder(request.Body).Decode(&source)
|
||||
} else if contentType[0] == "text/x-toml" {
|
||||
_, err = toml.DecodeReader(request.Body, &source)
|
||||
} else {
|
||||
err = errors.New("blueprint must be in json or toml format")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
Code: http.StatusBadRequest,
|
||||
|
|
@ -1052,7 +1060,7 @@ func (api *API) blueprintsNewHandler(writer http.ResponseWriter, request *http.R
|
|||
}
|
||||
|
||||
contentType := request.Header["Content-Type"]
|
||||
if len(contentType) != 1 {
|
||||
if len(contentType) == 0 {
|
||||
errors := responseError{
|
||||
ID: "BlueprintsError",
|
||||
Msg: "missing Content-Type header",
|
||||
|
|
|
|||
|
|
@ -594,6 +594,29 @@ func TestSourcesNew(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSourcesNewToml(t *testing.T) {
|
||||
source := `
|
||||
name = "fish"
|
||||
url = "https://download.opensuse.org/repositories/shells:/fish:/release:/3/Fedora_29/"
|
||||
type = "yum-baseurl"
|
||||
check_ssl = false
|
||||
check_gpg = false
|
||||
`
|
||||
req := httptest.NewRequest("POST", "/api/v0/projects/source/new", bytes.NewReader([]byte(source)))
|
||||
req.Header.Set("Content-Type", "text/x-toml")
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
api, _ := createWeldrAPI(rpmmd_mock.BaseFixture)
|
||||
api.ServeHTTP(recorder, req)
|
||||
|
||||
r := recorder.Result()
|
||||
if r.StatusCode != http.StatusOK {
|
||||
t.Fatalf("unexpected status %v", r.StatusCode)
|
||||
}
|
||||
|
||||
test.SendHTTP(api, true, "DELETE", "/api/v0/projects/source/delete/fish", ``)
|
||||
}
|
||||
|
||||
func TestSourcesDelete(t *testing.T) {
|
||||
var cases = []struct {
|
||||
Method string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue