2023-02-03 05:05:42 -05:00
|
|
|
//go:build e2e
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2023-06-02 03:19:23 -04:00
|
|
|
versionsapi "github.com/edgelesssys/constellation/v2/internal/api/versions"
|
2023-02-03 05:05:42 -05:00
|
|
|
"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"
|
2023-02-03 05:05:42 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type upgradeInfo struct {
|
|
|
|
measurements measurements.M
|
|
|
|
shortPath string
|
2023-04-27 10:40:29 -04:00
|
|
|
imageRef string
|
2023-02-03 05:05:42 -05:00
|
|
|
}
|
|
|
|
|
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) {
|
2023-02-03 05:05:42 -05:00
|
|
|
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)
|
2023-02-03 05:05:42 -05:00
|
|
|
if err != nil {
|
|
|
|
return upgradeInfo{}, err
|
|
|
|
}
|
|
|
|
|
2023-05-22 08:59:28 -04:00
|
|
|
fetchedMeasurements := measurements.M{}
|
|
|
|
if err := fetchedMeasurements.FetchNoVerify(
|
2023-02-03 05:05:42 -05:00
|
|
|
ctx, http.DefaultClient,
|
|
|
|
measurementsURL,
|
2023-05-22 08:59:28 -04:00
|
|
|
ver, csp, attestationVariant,
|
|
|
|
); err != nil {
|
2023-02-03 05:05:42 -05:00
|
|
|
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)
|
2023-02-03 05:05:42 -05:00
|
|
|
if err != nil {
|
|
|
|
return upgradeInfo{}, err
|
|
|
|
}
|
2023-04-27 10:40:29 -04:00
|
|
|
info.imageRef = imageRef
|
2023-02-03 05:05:42 -05:00
|
|
|
|
|
|
|
return info, nil
|
|
|
|
}
|