mirror of
https://github.com/kubevirt/containerized-data-importer.git
synced 2025-06-03 06:30:22 +00:00

* Updated dependencies Signed-off-by: Tomasz Baranski <tbaransk@redhat.com> * Replace skopeo with containers API. This commit removes dependence on skopeo (binary) and uses containers API. By doing that we're able to opimize the use of storage (scratch) space, storage I/O and download bandwith. Signed-off-by: Tomasz Baranski <tbaransk@redhat.com> * Fixing rebase - dependencies kerfuffle. Signed-off-by: Tomasz Baranski <tbaransk@redhat.com> * Handling docker-format images as well as OCI. Signed-off-by: Tomasz Baranski <tbaransk@redhat.com> * Fix for missing code-generator module. Signed-off-by: Tomasz Baranski <tbaransk@redhat.com> * Remove regex, image file in registry images are matched by a path prefix. Signed-off-by: Tomasz Baranski <tbaransk@redhat.com> * Added nginx proxy in front of docker registry for a rate-limited access. Signed-off-by: Tomasz Baranski <tbaransk@redhat.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package hns
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/Microsoft/hcsshim/internal/hcserror"
|
|
"github.com/Microsoft/hcsshim/internal/interop"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func hnsCallRawResponse(method, path, request string) (*hnsResponse, error) {
|
|
var responseBuffer *uint16
|
|
logrus.Debugf("[%s]=>[%s] Request : %s", method, path, request)
|
|
|
|
err := _hnsCall(method, path, request, &responseBuffer)
|
|
if err != nil {
|
|
return nil, hcserror.New(err, "hnsCall ", "")
|
|
}
|
|
response := interop.ConvertAndFreeCoTaskMemString(responseBuffer)
|
|
|
|
hnsresponse := &hnsResponse{}
|
|
if err = json.Unmarshal([]byte(response), &hnsresponse); err != nil {
|
|
return nil, err
|
|
}
|
|
return hnsresponse, nil
|
|
}
|
|
|
|
func hnsCall(method, path, request string, returnResponse interface{}) error {
|
|
hnsresponse, err := hnsCallRawResponse(method, path, request)
|
|
if err != nil {
|
|
return fmt.Errorf("failed during hnsCallRawResponse: %v", err)
|
|
}
|
|
if !hnsresponse.Success {
|
|
return fmt.Errorf("hns failed with error : %s", hnsresponse.Error)
|
|
}
|
|
|
|
if len(hnsresponse.Output) == 0 {
|
|
return nil
|
|
}
|
|
|
|
logrus.Debugf("Network Response : %s", hnsresponse.Output)
|
|
err = json.Unmarshal(hnsresponse.Output, returnResponse)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|