constellation/e2e/internal/upgrade/image.go

65 lines
1.5 KiB
Go
Raw Normal View History

//go:build e2e
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package upgrade
import (
"context"
"net/http"
versionsapi "github.com/edgelesssys/constellation/v2/internal/api/versions"
"github.com/edgelesssys/constellation/v2/internal/attestation/measurements"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
2023-05-23 03:17:27 -04:00
"github.com/edgelesssys/constellation/v2/internal/imagefetcher"
2023-05-22 08:59:28 -04:00
"github.com/edgelesssys/constellation/v2/internal/variant"
)
type upgradeInfo struct {
measurements measurements.M
shortPath string
imageRef string
}
2023-05-22 08:59:28 -04:00
func fetchUpgradeInfo(ctx context.Context, csp cloudprovider.Provider,
2023-05-23 03:17:27 -04:00
attestationVariant variant.Variant, toImage, region string,
2023-05-22 08:59:28 -04:00
) (upgradeInfo, error) {
info := upgradeInfo{
measurements: make(measurements.M),
shortPath: toImage,
}
ver, err := versionsapi.NewVersionFromShortPath(toImage, versionsapi.VersionKindImage)
if err != nil {
return upgradeInfo{}, err
}
2023-05-22 08:59:28 -04:00
measurementsURL, _, err := versionsapi.MeasurementURL(ver)
if err != nil {
return upgradeInfo{}, err
}
2023-05-22 08:59:28 -04:00
fetchedMeasurements := measurements.M{}
if err := fetchedMeasurements.FetchNoVerify(
ctx, http.DefaultClient,
measurementsURL,
2023-05-22 08:59:28 -04:00
ver, csp, attestationVariant,
); err != nil {
return upgradeInfo{}, err
}
info.measurements = fetchedMeasurements
2023-05-23 03:17:27 -04:00
fetcher := imagefetcher.New()
imageRef, err := fetcher.FetchReference(ctx, csp, attestationVariant, toImage, region)
if err != nil {
return upgradeInfo{}, err
}
info.imageRef = imageRef
return info, nil
}