mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-22 13:38:26 +00:00
shim-client: add support for DoPut
While at it, make sure we check for nil in DoPost Signed-off-by: Eric Ernst <eric_ernst@apple.com>
This commit is contained in:
parent
640173cfc2
commit
2a09378dd9
@ -163,5 +163,5 @@ func Resize(volumePath string, size uint64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return shimclient.DoPost(sandboxId, defaultTimeout, containerdshim.DirectVolumeResizeUrl, encoded)
|
return shimclient.DoPost(sandboxId, defaultTimeout, containerdshim.DirectVolumeResizeUrl, "application/json", encoded)
|
||||||
}
|
}
|
||||||
|
@ -65,15 +65,40 @@ func DoGet(sandboxID string, timeoutInSeconds time.Duration, urlPath string) ([]
|
|||||||
return body, nil
|
return body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath string, payload []byte) error {
|
// DoPut will make a PUT request to the shim endpoint that handles the given sandbox ID
|
||||||
|
func DoPut(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentType string, payload []byte) error {
|
||||||
client, err := BuildShimClient(sandboxID, timeoutInSeconds)
|
client, err := BuildShimClient(sandboxID, timeoutInSeconds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Post(fmt.Sprintf("http://shim/%s", urlPath), "application/json", bytes.NewBuffer(payload))
|
req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("http://shim/%s", urlPath), bytes.NewBuffer(payload))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", contentType)
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
defer func() {
|
defer func() {
|
||||||
resp.Body.Close()
|
if resp != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoPost will make a POST request to the shim endpoint that handles the given sandbox ID
|
||||||
|
func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentType string, payload []byte) error {
|
||||||
|
client, err := BuildShimClient(sandboxID, timeoutInSeconds)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Post(fmt.Sprintf("http://shim/%s", urlPath), contentType, bytes.NewBuffer(payload))
|
||||||
|
defer func() {
|
||||||
|
if resp != nil {
|
||||||
|
resp.Body.Close()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user