use constants for default CDN paths

This commit is contained in:
Malte Poll 2022-11-30 11:48:39 +01:00 committed by Malte Poll
parent 3aa51df74d
commit 9537fb73c0
4 changed files with 6 additions and 4 deletions

View File

@ -175,12 +175,12 @@ func getCompatibleImageMeasurements(ctx context.Context, cmd *cobra.Command, cli
) (map[string]config.UpgradeConfig, error) {
upgrades := make(map[string]config.UpgradeConfig)
for _, img := range images {
measurementsURL, err := url.Parse(constants.CDNRepositoryURL + path.Join("/constellation/v1/measurements/", img, strings.ToLower(csp.String()), "measurements.json"))
measurementsURL, err := url.Parse(constants.CDNRepositoryURL + path.Join("/", constants.CDNMeasurementsPath, img, strings.ToLower(csp.String()), "measurements.json"))
if err != nil {
return nil, err
}
signatureURL, err := url.Parse(constants.CDNRepositoryURL + path.Join("/constellation/v1/measurements/", img, strings.ToLower(csp.String()), "measurements.json.sig"))
signatureURL, err := url.Parse(constants.CDNRepositoryURL + path.Join("/", constants.CDNMeasurementsPath, img, strings.ToLower(csp.String()), "measurements.json.sig"))
if err != nil {
return nil, err
}

View File

@ -314,7 +314,7 @@ func granularityFromVersion(version string) (string, error) {
}
func versionJSONPath(granularity, base string) string {
return path.Join("constellation/v1/updates", stream, granularity, base, imageKind+".json")
return path.Join(constants.CDNUpdatesPath, stream, granularity, base, imageKind+".json")
}
func versionURL(granularity, base string) string {

View File

@ -154,6 +154,8 @@ const (
CDNImagePath = "constellation/v1/images"
// CDNMeasurementsPath is the default path to image measurements in the CDN repository.
CDNMeasurementsPath = "constellation/v1/measurements"
// CDNUpdatesPath is the default path to updates in the CDN repository.
CDNUpdatesPath = "constellation/v1/updates"
)
// VersionInfo is the version of a binary. Left as a separate variable to allow override during build.

View File

@ -152,7 +152,7 @@ func getFromURL(ctx context.Context, client httpc, stream, granularity, base, ki
return nil, fmt.Errorf("parsing image version repository URL: %w", err)
}
kindFilename := path.Base(kind) + ".json"
url.Path = path.Join("constellation/v1/updates", stream, granularity, base, kindFilename)
url.Path = path.Join(constants.CDNUpdatesPath, stream, granularity, base, kindFilename)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), http.NoBody)
if err != nil {
return nil, err