2023-04-21 04:47:07 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/osimage"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/osimage/archive"
|
|
|
|
nopupload "github.com/edgelesssys/constellation/v2/internal/osimage/nop"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func runNOP(cmd *cobra.Command, provider cloudprovider.Provider, _ []string) error {
|
|
|
|
workdir := os.Getenv("BUILD_WORKING_DIRECTORY")
|
|
|
|
if len(workdir) > 0 {
|
|
|
|
must(os.Chdir(workdir))
|
|
|
|
}
|
|
|
|
|
|
|
|
flags, err := parseCommonFlags(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
flags.provider = provider
|
|
|
|
log := logger.New(logger.PlainLog, flags.logLevel)
|
|
|
|
log.Debugf("Parsed flags: %+v", flags)
|
|
|
|
|
2023-06-02 05:20:01 -04:00
|
|
|
archiveC, archiveCClose, err := archive.New(cmd.Context(), flags.region, flags.bucket, flags.distributionID, log)
|
2023-04-21 04:47:07 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-02 05:20:01 -04:00
|
|
|
defer func() {
|
|
|
|
if err := archiveCClose(cmd.Context()); err != nil {
|
|
|
|
log.Errorf("closing archive client: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
2023-04-21 04:47:07 -04:00
|
|
|
|
|
|
|
uploadC := nopupload.New(log)
|
|
|
|
|
|
|
|
file, err := os.Open(flags.rawImage)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("uploading image: opening image file %w", err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
size, err := file.Seek(0, io.SeekEnd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := file.Seek(0, io.SeekStart); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
out := cmd.OutOrStdout()
|
|
|
|
if len(flags.out) > 0 {
|
|
|
|
outF, err := os.Create(flags.out)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("uploading image: opening output file %w", err)
|
|
|
|
}
|
|
|
|
defer outF.Close()
|
|
|
|
out = outF
|
|
|
|
}
|
|
|
|
|
|
|
|
sbDatabase, uefiVarStore, err := loadSecureBootKeys(flags.pki)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadReq := &osimage.UploadRequest{
|
2023-05-23 03:17:27 -04:00
|
|
|
Provider: flags.provider,
|
|
|
|
Version: flags.version,
|
|
|
|
AttestationVariant: flags.attestationVariant,
|
|
|
|
SBDatabase: sbDatabase,
|
|
|
|
UEFIVarStore: uefiVarStore,
|
|
|
|
Size: size,
|
|
|
|
Timestamp: flags.timestamp,
|
|
|
|
Image: file,
|
2023-04-21 04:47:07 -04:00
|
|
|
}
|
|
|
|
return uploadImage(cmd.Context(), archiveC, uploadC, uploadReq, out)
|
|
|
|
}
|