mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-08-31 08:57:14 +02:00
The schema string was the inside of a "properties" block: jwts, oidc, ldap and
required sat at the root with no enclosing "type"/"properties". jsonschema
compiled it as a document with only unknown keywords, so every auth section
validated and no option was ever checked.
Wrapped it correctly and dropped the root-level required: ["jwts"]. Init logs
and continues when the jwts section is absent ("Missing JWT configuration: No
JWT token support!"), so enforcing it would abort OIDC- or LDAP-only
deployments that work today. The per-subsection required lists are unchanged.
Validation errors are now printed with err.Error() instead of %#v, which
rendered a jsonschema.ValidationError unreadably.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
30 lines
730 B
Go
30 lines
730 B
Go
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
|
// All rights reserved. This file is part of cc-backend.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
cclog "github.com/ClusterCockpit/cc-lib/v2/ccLogger"
|
|
"github.com/santhosh-tekuri/jsonschema/v5"
|
|
)
|
|
|
|
func Validate(schema string, instance json.RawMessage) {
|
|
sch, err := jsonschema.CompileString("schema.json", schema)
|
|
if err != nil {
|
|
cclog.Fatalf("%#v", err)
|
|
}
|
|
|
|
var v any
|
|
if err := json.Unmarshal([]byte(instance), &v); err != nil {
|
|
cclog.Fatal(err)
|
|
}
|
|
|
|
if err = sch.Validate(v); err != nil {
|
|
cclog.Fatalf("config validation failed: %s", err.Error())
|
|
}
|
|
}
|