-
Notifications
You must be signed in to change notification settings - Fork 23
HYPERFLEET-1158 - feat: config-driven entity registration via LoadDescriptors #267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |
| "github.com/openshift-hyperfleet/hyperfleet-api/pkg/health" | ||
| "github.com/openshift-hyperfleet/hyperfleet-api/pkg/logger" | ||
| "github.com/openshift-hyperfleet/hyperfleet-api/pkg/metrics" | ||
| "github.com/openshift-hyperfleet/hyperfleet-api/pkg/registry" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Panic-based startup validation breaks the established fail-fast pattern (CWE-248).
🛡️ Proposed fix- registry.LoadDescriptors(cfg.Entities)
- registry.Validate()
- registry.ValidateSchemas(cfg.Server.OpenAPISchemaPath)
+ func() {
+ defer func() {
+ if r := recover(); r != nil {
+ logger.With(ctx, "panic", r).Error("Entity registry validation failed")
+ os.Exit(1)
+ }
+ }()
+ registry.LoadDescriptors(cfg.Entities)
+ registry.Validate()
+ registry.ValidateSchemas(cfg.Server.OpenAPISchemaPath)
+ }()Also applies to: 59-65 🤖 Prompt for AI Agents |
||
| "github.com/openshift-hyperfleet/hyperfleet-api/pkg/telemetry" | ||
| ) | ||
|
|
||
|
|
@@ -55,6 +56,13 @@ func runServe(cmd *cobra.Command, args []string) { | |
| // and ensure SessionFactory, clients, services, handlers all use the correct config | ||
| environments.Environment().Config = cfg | ||
|
|
||
| // Load entity descriptors from config before services and routes are built. | ||
| // Descriptors must be registered before Initialize() because services call | ||
| // registry.MustGet() at construction time. | ||
| registry.LoadDescriptors(cfg.Entities) | ||
| registry.Validate() | ||
| registry.ValidateSchemas(cfg.Server.OpenAPISchemaPath) | ||
|
|
||
| // Initialize environment (applies overrides, creates SessionFactory, loads clients, services, handlers) | ||
| err = environments.Environment().Initialize() | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Unquoted entity scalars — YAML injection/malformed-config risk (CWE-1284-adjacent).
Every other string value in this template is piped through
| quote(seehostname,cert_file,issuer_url,dialect,level, etc.). The new entities block does not quotekind,plural,spec_schema_name,parent_kind,on_parent_delete,ref_type,target_kind. Sinceconfig.entitiesis documented as overridable via--set-json, an operator-supplied value containing:, or a bareyes/no/null-like token, will corrupt the rendered YAML or get silently reinterpreted as a non-string type, breakingLoadDescriptorsat startup.🔒 Proposed fix
- kind: {{ .kind }} - plural: {{ .plural }} + - kind: {{ .kind | quote }} + plural: {{ .plural | quote }} {{- if .parent_kind }} - parent_kind: {{ .parent_kind }} + parent_kind: {{ .parent_kind | quote }} {{- end }} {{- if .on_parent_delete }} - on_parent_delete: {{ .on_parent_delete }} + on_parent_delete: {{ .on_parent_delete | quote }} {{- end }} - spec_schema_name: {{ .spec_schema_name }} + spec_schema_name: {{ .spec_schema_name | quote }} @@ - - ref_type: {{ .ref_type }} - target_kind: {{ .target_kind }} + - ref_type: {{ .ref_type | quote }} + target_kind: {{ .target_kind | quote }}Also applies to: 169-170
🤖 Prompt for AI Agents