weldr: Add support for the v1 API to /projects/source/new

This commit changes the store.PushSource function to take the key as
well as the SourceConfig so that it can be used for v0 or v1.

It adds helper functions for decoding the toml/json into a new
SourceConfig interface type which lets the core source/new code be
shared between the versions.

It also adds tests for the new API behavior.
This commit is contained in:
Brian C. Lane 2020-04-29 15:29:17 -07:00 committed by Tom Gundersen
parent 55325a8549
commit ddd2010815
6 changed files with 304 additions and 32 deletions

View file

@ -63,6 +63,16 @@ func PostJSONSourceV0(socket *http.Client, source string) (*APIResponse, error)
return NewAPIResponse(body)
}
// PostJSONSourceV1 sends a JSON source string to the API
// and returns an APIResponse
func PostJSONSourceV1(socket *http.Client, source string) (*APIResponse, error) {
body, resp, err := PostJSON(socket, "/api/v1/projects/source/new", source)
if resp != nil || err != nil {
return resp, err
}
return NewAPIResponse(body)
}
// PostTOMLSourceV0 sends a TOML source string to the API
// and returns an APIResponse
func PostTOMLSourceV0(socket *http.Client, source string) (*APIResponse, error) {
@ -73,6 +83,16 @@ func PostTOMLSourceV0(socket *http.Client, source string) (*APIResponse, error)
return NewAPIResponse(body)
}
// PostTOMLSourceV1 sends a TOML source string to the API
// and returns an APIResponse
func PostTOMLSourceV1(socket *http.Client, source string) (*APIResponse, error) {
body, resp, err := PostTOML(socket, "/api/v1/projects/source/new", source)
if resp != nil || err != nil {
return resp, err
}
return NewAPIResponse(body)
}
// DeleteSourceV0 deletes the named source and returns an APIResponse
func DeleteSourceV0(socket *http.Client, sourceName string) (*APIResponse, error) {
body, resp, err := DeleteRaw(socket, "/api/v0/projects/source/delete/"+sourceName)