A package is now a set of immutable versions with declared grants and a default version that installations run unless they pin another. Adopting a version is what accepts its grants, replacing the per-extension lifecycle actions with version, pin and update-policy commands.
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package connectors
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"slices"
|
|
|
|
"github.com/danielgtaylor/huma/v2"
|
|
|
|
"github.com/samcharles93/archie-core/internal/platform/httpapi"
|
|
"github.com/samcharles93/archie-core/modules/connectors/internal/store"
|
|
"github.com/samcharles93/archie-core/modules/governance"
|
|
)
|
|
|
|
// listExtensions returns every installation the caller can see, whatever its
|
|
// contract and scope: the extensions page shows one list rather than one per
|
|
// kind.
|
|
func (m *Module) listExtensions(ctx context.Context, _ *struct{}) (*httpapi.Reply[[]ExtensionView], error) {
|
|
return m.listViews(ctx, func(store.Installed) bool { return true })
|
|
}
|
|
|
|
// removePackage removes an accepted package without naming its contract
|
|
// first. The contract is read from the package's instance installation and
|
|
// handed to the same removal the per-kind routes use.
|
|
func (m *Module) removePackage(ctx context.Context, in *packageNameInput) (*httpapi.Reply[packageState], error) {
|
|
installed, err := m.store.List(ctx)
|
|
if err != nil {
|
|
m.log.ErrorContext(ctx, "list installations", "error", err)
|
|
return nil, huma.NewError(http.StatusInternalServerError, "couldn't read the installations")
|
|
}
|
|
i := slices.IndexFunc(installed, func(a store.Installed) bool { return a.Scope == store.ScopeInstance && a.Name == in.Name })
|
|
if i < 0 {
|
|
return nil, huma.NewError(http.StatusNotFound, fmt.Sprintf("no accepted package named %s", in.Name))
|
|
}
|
|
managed := installed[i].Managed
|
|
reply, err := m.removeAs(ctx, &nameInput{Name: in.Name}, installed[i].Contract)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if managed {
|
|
if err := m.fetcher.Forget(in.Name); err != nil {
|
|
m.log.WarnContext(ctx, "keep extension artifacts", "package", in.Name, "error", err)
|
|
}
|
|
}
|
|
return reply, nil
|
|
}
|
|
|
|
func (m *Module) registerExtensions(api huma.API) {
|
|
tags := []string{"Extensions"}
|
|
httpapi.Register(api, httpapi.Authorized(governance.ActionRead, governance.KindConnector), huma.Operation{
|
|
OperationID: "list-extensions", Method: http.MethodGet, Path: "/api/extensions",
|
|
Summary: "List every installation the caller can see, whatever its contract and scope", Tags: tags,
|
|
}, m.listExtensions)
|
|
}
|