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>
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
//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"
|
|
"github.com/edgelesssys/constellation/v2/internal/imagefetcher"
|
|
"github.com/edgelesssys/constellation/v2/internal/variant"
|
|
)
|
|
|
|
type upgradeInfo struct {
|
|
measurements measurements.M
|
|
shortPath string
|
|
imageRef string
|
|
}
|
|
|
|
func fetchUpgradeInfo(ctx context.Context, csp cloudprovider.Provider,
|
|
attestationVariant variant.Variant, toImage, region string,
|
|
) (upgradeInfo, error) {
|
|
info := upgradeInfo{
|
|
measurements: make(measurements.M),
|
|
shortPath: toImage,
|
|
}
|
|
|
|
ver, err := versionsapi.NewVersionFromShortPath(toImage, versionsapi.VersionKindImage)
|
|
if err != nil {
|
|
return upgradeInfo{}, err
|
|
}
|
|
|
|
measurementsURL, _, err := versionsapi.MeasurementURL(ver)
|
|
if err != nil {
|
|
return upgradeInfo{}, err
|
|
}
|
|
|
|
fetchedMeasurements := measurements.M{}
|
|
if err := fetchedMeasurements.FetchNoVerify(
|
|
ctx, http.DefaultClient,
|
|
measurementsURL,
|
|
ver, csp, attestationVariant,
|
|
); err != nil {
|
|
return upgradeInfo{}, err
|
|
}
|
|
info.measurements = fetchedMeasurements
|
|
|
|
fetcher := imagefetcher.New()
|
|
imageRef, err := fetcher.FetchReference(ctx, csp, attestationVariant, toImage, region)
|
|
if err != nil {
|
|
return upgradeInfo{}, err
|
|
}
|
|
info.imageRef = imageRef
|
|
|
|
return info, nil
|
|
}
|