mirror of
https://github.com/siderolabs/image-factory.git
synced 2025-12-12 13:01:12 +01:00
Fixes #13 This builds on top of extensions catalog (see https://github.com/siderolabs/extensions/pull/225), and existing support for specifying extension in the flavor. Image Service resolve the list of extensions requested for a specific version of Talos into a list of container images, pulls them, and attaches them to the image request. Image Service also provides endpoints to get information about available Talos versions, supported extensions for each version, etc. I also refactored a bit flow around fetching & verifying image to re-use it in other flows, added support for authentication to the registry. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package http
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/blang/semver/v4"
|
|
"github.com/julienschmidt/httprouter"
|
|
"github.com/siderolabs/gen/xslices"
|
|
|
|
"github.com/siderolabs/image-service/internal/artifacts"
|
|
)
|
|
|
|
// handleVersions handles list of Talos versions available.
|
|
func (f *Frontend) handleVersions(ctx context.Context, w http.ResponseWriter, _ *http.Request, _ httprouter.Params) error {
|
|
versions, err := f.artifactsManager.GetTalosVersions(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return json.NewEncoder(w).Encode(
|
|
xslices.Map(versions, func(v semver.Version) string {
|
|
return "v" + v.String()
|
|
}),
|
|
)
|
|
}
|
|
|
|
// handleOfficialExtensions handles list of available official extensions per Talos version.
|
|
func (f *Frontend) handleOfficialExtensions(ctx context.Context, w http.ResponseWriter, _ *http.Request, p httprouter.Params) error {
|
|
versionTag := p.ByName("version")
|
|
if !strings.HasPrefix(versionTag, "v") {
|
|
versionTag = "v" + versionTag
|
|
}
|
|
|
|
version, err := semver.Parse(versionTag[1:])
|
|
if err != nil {
|
|
return fmt.Errorf("error parsing version: %w", err)
|
|
}
|
|
|
|
extensions, err := f.artifactsManager.GetOfficialExtensions(ctx, version.String())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
type extensionInfo struct {
|
|
Name string `json:"name"`
|
|
Ref string `json:"ref"`
|
|
Digest string `json:"digest"`
|
|
}
|
|
|
|
return json.NewEncoder(w).Encode(
|
|
xslices.Map(extensions, func(e artifacts.ExtensionRef) extensionInfo {
|
|
return extensionInfo{
|
|
Name: e.TaggedReference.RepositoryStr(),
|
|
Ref: e.TaggedReference.String(),
|
|
Digest: e.Digest,
|
|
}
|
|
}),
|
|
)
|
|
}
|