mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-12 01:14:28 -05:00
30f2b332b3
* api: rename AttestationVersionRepo to Client * api: move client into separate subpkg for clearer import paths. * api: rename configapi -> attestationconfig * api: rename versionsapi -> versions * api: rename sut to client * api: split versionsapi client and make it public * api: split versionapi fetcher and make it public * config: move attestationversion type to config * api: fix attestationconfig client test Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
/*
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
|
|
versionsapi "github.com/edgelesssys/constellation/v2/internal/api/versions"
|
|
"github.com/edgelesssys/constellation/v2/internal/osimage"
|
|
)
|
|
|
|
func uploadImage(ctx context.Context, archiveC archivist, uploadC uploader, req *osimage.UploadRequest, out io.Writer) error {
|
|
// upload to S3 archive
|
|
archiveURL, err := archiveC.Archive(ctx, req.Version, strings.ToLower(req.Provider.String()), req.AttestationVariant, req.Image)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// rewind reader so we can read again
|
|
if _, err := req.Image.Seek(0, io.SeekStart); err != nil {
|
|
return err
|
|
}
|
|
// upload to CSP
|
|
imageReferences, err := uploadC.Upload(ctx, req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(imageReferences) == 0 {
|
|
imageReferences = []versionsapi.ImageInfoEntry{
|
|
{
|
|
CSP: req.Provider.String(),
|
|
AttestationVariant: req.AttestationVariant,
|
|
Reference: archiveURL,
|
|
},
|
|
}
|
|
}
|
|
|
|
imageInfo := versionsapi.ImageInfo{
|
|
Ref: req.Version.Ref,
|
|
Stream: req.Version.Stream,
|
|
Version: req.Version.Version,
|
|
List: imageReferences,
|
|
}
|
|
|
|
if err := json.NewEncoder(out).Encode(imageInfo); err != nil {
|
|
return fmt.Errorf("uploading image: marshaling output: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|