51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"sultan/pkg/license"
|
|
"sultan/pkg/policy"
|
|
"sultan/pkg/registry"
|
|
"sultan/pkg/store"
|
|
)
|
|
|
|
// directory liefert der Registry Mandant, Lizenz und Drain-Status eines
|
|
// Knotens aus dem Store.
|
|
//
|
|
// Solange Migration v2 fehlt (Spec Abschnitt 9), wird die Lizenz aus dem
|
|
// Mandanten-Datensatz abgeleitet: ohne Features und ohne Mahnstufe.
|
|
type directory struct {
|
|
store *store.Store
|
|
}
|
|
|
|
func (d *directory) NodeContext(ctx context.Context, nodeID string) (registry.NodeContext, error) {
|
|
node, err := d.store.GetNode(ctx, nodeID)
|
|
if errors.Is(err, store.ErrNotFound) {
|
|
return registry.NodeContext{}, fmt.Errorf("%w: %s", registry.ErrUnknownNode, nodeID)
|
|
}
|
|
if err != nil {
|
|
return registry.NodeContext{}, err
|
|
}
|
|
t, err := d.store.GetTenant(ctx, node.TenantID)
|
|
if errors.Is(err, store.ErrNotFound) {
|
|
return registry.NodeContext{}, fmt.Errorf("%w: Mandant von %s fehlt", registry.ErrUnknownNode, nodeID)
|
|
}
|
|
if err != nil {
|
|
return registry.NodeContext{}, err
|
|
}
|
|
return registry.NodeContext{
|
|
Tenant: policy.Tenant{ID: t.ID, Status: t.Status},
|
|
License: license.License{
|
|
TenantID: t.ID,
|
|
Tier: license.Tier(t.Tier),
|
|
MaxRoutes: t.MaxRoutes,
|
|
AllowedDomains: t.AllowedDomains,
|
|
Features: []license.Feature{},
|
|
ValidUntil: t.ValidUntil,
|
|
},
|
|
Drained: node.Status == store.NodeDrained,
|
|
}, nil
|
|
}
|