mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 17:03:17 +01:00
* add support to upload results to enterprise Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add package sbom upload Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add dockerfile support Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add manifest, index, and dockerfile import functions Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * schema version to json output + enhance json schema generation Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * modify package SBOM shape to be entire syft document + add etui updates Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add import image config and manifest support Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add config options for import to enterprise Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * incorporate final stereoscope and client-go deps Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
// nolint: dupl
|
|
package anchore
|
|
|
|
import (
|
|
"context"
|
|
"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 string) (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"
|
|
|
|
response, httpResponse, err := api.ImportImageManifest(ctx, sessionID, string(manifest))
|
|
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
|
|
}
|