mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* Update syft bootstrap tools to latest versions. Signed-off-by: GitHub <noreply@github.com> Signed-off-by: Weston Steimel <weston.steimel@anchore.com> Co-authored-by: Weston Steimel <weston.steimel@anchore.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
//nolint:dupl
|
|
package anchore
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/wagoodman/go-progress"
|
|
|
|
"github.com/anchore/client-go/pkg/external"
|
|
"github.com/anchore/syft/internal/log"
|
|
)
|
|
|
|
type manifestImportAPI interface {
|
|
ImportImageManifest(ctx context.Context, sessionID string, contents interface{}) (external.ImageImportContentResponse, *http.Response, error)
|
|
}
|
|
|
|
func importManifest(ctx context.Context, api manifestImportAPI, sessionID string, manifest []byte, stage *progress.Stage) (string, error) {
|
|
if len(manifest) > 0 {
|
|
log.Debug("importing image manifest")
|
|
stage.Current = "image manifest"
|
|
|
|
// API requires an object, but we do not verify the shape of this object locally
|
|
var sender map[string]interface{}
|
|
if err := json.Unmarshal(manifest, &sender); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
response, httpResponse, err := api.ImportImageManifest(ctx, sessionID, sender)
|
|
if err != nil {
|
|
var openAPIErr external.GenericOpenAPIError
|
|
if errors.As(err, &openAPIErr) {
|
|
log.Errorf("api response: %+v", string(openAPIErr.Body()))
|
|
}
|
|
return "", fmt.Errorf("unable to import Manifest: %w", err)
|
|
}
|
|
|
|
defer httpResponse.Body.Close()
|
|
|
|
if httpResponse.StatusCode != 200 {
|
|
return "", fmt.Errorf("unable to import Manifest: %s", httpResponse.Status)
|
|
}
|
|
|
|
return response.Digest, nil
|
|
}
|
|
return "", nil
|
|
}
|