feat(provision): service token on product lifecycle calls; stage/prod provision URLs (#26)
This commit was merged in pull request #26.
This commit is contained in:
1 parent
209524e5ac
commit
8388e47742
6 files changed
+24
-1
No files matched your search
@@ -91,4 +91,9 @@ type Adapter interface {
|
||||
// Health pings the admin endpoint. Used by readyz and the cluster cold-
|
||||
// start sequence (INFRASTRUCTURE.md §10 scenario F).
|
||||
Health(ctx context.Context) error
|
||||
|
||||
// ServiceToken returns a client_credentials access token of the
|
||||
// registry's own Keycloak client — the bearer for product lifecycle
|
||||
// calls (PRODUCT_INTEGRATION_SPEC 2.0 §4.1; products verify aud + azp).
|
||||
ServiceToken(ctx context.Context) (string, error)
|
||||
}
|
||||
@@ -58,6 +58,9 @@ func NewHTTPAdapter(cfg HTTPConfig) *HTTPAdapter {
|
||||
|
||||
// ─── auth ────────────────────────────────────────────────────────────────
|
||||
|
||||
// ServiceToken exposes the cached client_credentials token (see Adapter).
|
||||
func (a *HTTPAdapter) ServiceToken(ctx context.Context) (string, error) { return a.token(ctx) }
|
||||
|
||||
func (a *HTTPAdapter) token(ctx context.Context) (string, error) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@@ -41,6 +41,9 @@ func (m *Mock) SyncTenantStatus(_ context.Context, slug, status string) error {
|
||||
|
||||
func (m *Mock) Health(_ context.Context) error { return nil }
|
||||
|
||||
// ServiceToken returns a fixed token so provisioning requests carry a bearer.
|
||||
func (m *Mock) ServiceToken(_ context.Context) (string, error) { return "mock-service-token", nil }
|
||||
|
||||
func (m *Mock) CreateOrgAndInvite(_ context.Context, in InviteInput) (*InviteResult, error) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
@@ -370,7 +370,14 @@ func (s *Server) provisionProduct(ctx context.Context, r *http.Request, t *store
|
||||
"id": t.ID, "name": t.Name, "slug": t.Slug, "plan": t.Plan,
|
||||
"product": p.Key, "config": tp.Config, "expires_at": tp.ExpiresAt, "contract_version": "2.0",
|
||||
}
|
||||
if err := product.ProvisionAt(ctx, url, payload, nil, 10*time.Second); err != nil {
|
||||
auth := func(ctx context.Context) (string, error) {
|
||||
tok, err := s.Keycloak.ServiceToken(ctx)
|
||||
if err != nil || tok == "" {
|
||||
return "", err
|
||||
}
|
||||
return "Bearer " + tok, nil
|
||||
}
|
||||
if err := product.ProvisionAt(ctx, url, payload, auth, 10*time.Second); err != nil {
|
||||
s.emitAudit(ctx, r, store.AuditEvent{
|
||||
TenantID: t.ID, Action: "product.provision_failed", TargetID: p.Key, TargetType: "product",
|
||||
Metadata: map[string]interface{}{"url": url, "err": err.Error()},
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
UPDATE products SET provision_urls = '{}'::jsonb WHERE key IN ('pruefwerk', 'firmwerk');
|
||||
@@ -0,0 +1,4 @@
|
||||
-- M-MIG-8: the registry provisions tenants at the products' platform endpoints
|
||||
-- (PRODUCT_INTEGRATION_SPEC 2.0 §4.1) with its own service token.
|
||||
UPDATE products SET provision_urls = '{"stage": "https://pruefwerk-stage.breakpilot.com/api/v1/platform/tenants/{id}/provision", "prod": "https://pruefwerk.breakpilot.com/api/v1/platform/tenants/{id}/provision"}'::jsonb WHERE key = 'pruefwerk';
|
||||
UPDATE products SET provision_urls = '{"stage": "https://firmwerk-stage.breakpilot.com/api/v1/platform/tenants/{id}/provision", "prod": "https://firmwerk.breakpilot.com/api/v1/platform/tenants/{id}/provision"}'::jsonb WHERE key = 'firmwerk';
|
||||
Reference in new issue
Block a user