Files
archie/internal/app/statestore/catalogue.go
T
sam 9d8f364af1
Quality / check (push) Successful in 5m53s
deploy / gate (push) Canceled after 0s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
feat(releaseupdate): signed OCI distribution sources for releases and the catalogue (#1715)
2026-10-31 18:18:43 +11:00

52 lines
1.8 KiB
Go

package statestore
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/samcharles93/archie-core/internal/domain/distribution"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
domain "github.com/samcharles93/archie-core/internal/domain/storepkg"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanestore"
registry "github.com/samcharles93/archie-core/internal/infrastructure/storepkg"
)
// settingsCatalogue fetches the catalogue from the source the extension
// settings name, read on every fetch so an edit applies without a restart.
type settingsCatalogue struct {
resources auditRetentionResources
}
// liveCatalogue is the catalogue the dashboard lists; a store that cannot
// read resources lists the official catalogue.
func (b *server) liveCatalogue() domain.CatalogueSource {
resources, ok := b.st.(auditRetentionResources)
if !ok {
return registry.Catalogue(distribution.DefaultCatalogue())
}
return settingsCatalogue{resources: resources}
}
func (c settingsCatalogue) Fetch(ctx context.Context) (domain.Catalogue, error) {
var settings controlplanerpc.ExtensionSettings
resource, err := c.resources.Resource(ctx, storecontract.DefaultOrgID, controlplanestore.ExtensionSettingsKind)
switch {
case errors.Is(err, storecontract.ErrResourceNotFound):
case err != nil:
return domain.Catalogue{}, fmt.Errorf("read extension settings: %w", err)
}
if len(resource.Value) > 0 {
if err := json.Unmarshal(resource.Value, &settings); err != nil {
return domain.Catalogue{}, fmt.Errorf("decode extension settings: %w", err)
}
}
source, err := settings.Catalogue()
if err != nil {
return domain.Catalogue{}, err
}
return registry.Catalogue(source).Fetch(ctx)
}