Files
bpmforge e0d82a4ed0 Kryptkeeper 1.0.0
First stable release. Notes: docs/release/RELEASE_NOTES_v1.0.0.md
Lab record: docs/release/LIVE_RESULTS_v1.0.0.md
2026-10-19 14:43:23 -04:00

34 lines
995 B
Go

// Copyright 2026 Kryptkeeper Authors
//
// SPDX-License-Identifier: Apache-2.0
package ca
import (
"errors"
"fmt"
)
// ErrNoCAConfigured means the hub has no CA yet (first-run mode): nothing can
// be issued until an operator creates a root CA (UI onboarding wizard, API, or
// KRYPTKEEPER_BOOTSTRAP_CREATE_ROOT=true). API layers report it as a conflict.
var ErrNoCAConfigured = errors.New("no CA configured yet; create a root CA")
// ResolveCAID returns configured when set, else the first stored CA. The
// lookup happens per call so a CA created after startup is picked up without
// a restart. A ListCAs failure is returned as-is (never read as "no CAs");
// an empty list is ErrNoCAConfigured.
func ResolveCAID(svc Service, configured string) (string, error) {
if configured != "" {
return configured, nil
}
cas, err := svc.ListCAs()
if err != nil {
return "", fmt.Errorf("list CAs: %w", err)
}
if len(cas) == 0 {
return "", ErrNoCAConfigured
}
return cas[0].ID, nil
}