Change path for version API:

- Rename "updates" -> "versions"
- Add explicit "stream" in path to make API self-describing
This commit is contained in:
Malte Poll 2022-11-30 15:19:53 +01:00 committed by Malte Poll
parent 7ee2539645
commit 85d723ccbd
4 changed files with 10 additions and 10 deletions

View File

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

View File

@ -154,8 +154,8 @@ const (
CDNImagePath = "constellation/v1/images" CDNImagePath = "constellation/v1/images"
// CDNMeasurementsPath is the default path to image measurements in the CDN repository. // CDNMeasurementsPath is the default path to image measurements in the CDN repository.
CDNMeasurementsPath = "constellation/v1/measurements" CDNMeasurementsPath = "constellation/v1/measurements"
// CDNUpdatesPath is the default path to updates in the CDN repository. // CDNVersionsPath is the default path to versions in the CDN repository.
CDNUpdatesPath = "constellation/v1/updates" CDNVersionsPath = "constellation/v1/versions"
) )
// VersionInfo is the version of a binary. Left as a separate variable to allow override during build. // 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) return nil, fmt.Errorf("parsing image version repository URL: %w", err)
} }
kindFilename := path.Base(kind) + ".json" kindFilename := path.Base(kind) + ".json"
url.Path = path.Join(constants.CDNUpdatesPath, stream, granularity, base, kindFilename) url.Path = path.Join(constants.CDNVersionsPath, "stream", stream, granularity, base, kindFilename)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), http.NoBody) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url.String(), http.NoBody)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -123,37 +123,37 @@ func TestList(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
client := newTestClient(func(req *http.Request) *http.Response { client := newTestClient(func(req *http.Request) *http.Response {
switch req.URL.Path { switch req.URL.Path {
case "/constellation/v1/updates/stable/major/v1/image.json": case "/constellation/v1/versions/stream/stable/major/v1/image.json":
return &http.Response{ return &http.Response{
StatusCode: http.StatusOK, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBuffer(majorListJSON)), Body: io.NopCloser(bytes.NewBuffer(majorListJSON)),
Header: make(http.Header), Header: make(http.Header),
} }
case "/constellation/v1/updates/stable/minor/v1.1/image.json": case "/constellation/v1/versions/stream/stable/minor/v1.1/image.json":
return &http.Response{ return &http.Response{
StatusCode: http.StatusOK, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBuffer(minorListJSON)), Body: io.NopCloser(bytes.NewBuffer(minorListJSON)),
Header: make(http.Header), Header: make(http.Header),
} }
case "/constellation/v1/updates/stable/major/v1/500.json": // 500 error case "/constellation/v1/versions/stream/stable/major/v1/500.json": // 500 error
return &http.Response{ return &http.Response{
StatusCode: http.StatusInternalServerError, StatusCode: http.StatusInternalServerError,
Body: io.NopCloser(bytes.NewBufferString("Server Error.")), Body: io.NopCloser(bytes.NewBufferString("Server Error.")),
Header: make(http.Header), Header: make(http.Header),
} }
case "/constellation/v1/updates/stable/major/v1/nojson.json": // invalid format case "/constellation/v1/versions/stream/stable/major/v1/nojson.json": // invalid format
return &http.Response{ return &http.Response{
StatusCode: http.StatusOK, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBufferString("not json")), Body: io.NopCloser(bytes.NewBufferString("not json")),
Header: make(http.Header), Header: make(http.Header),
} }
case "/constellation/v1/updates/stable/major/v2/image.json": // inconsistent list case "/constellation/v1/versions/stream/stable/major/v2/image.json": // inconsistent list
return &http.Response{ return &http.Response{
StatusCode: http.StatusOK, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBuffer(inconsistentListJSON)), Body: io.NopCloser(bytes.NewBuffer(inconsistentListJSON)),
Header: make(http.Header), Header: make(http.Header),
} }
case "/constellation/v1/updates/stable/major/v3/image.json": // does not match requested version case "/constellation/v1/versions/stream/stable/major/v3/image.json": // does not match requested version
return &http.Response{ return &http.Response{
StatusCode: http.StatusOK, StatusCode: http.StatusOK,
Body: io.NopCloser(bytes.NewBuffer(minorListJSON)), Body: io.NopCloser(bytes.NewBuffer(minorListJSON)),