snapshot of https://github.com/ory/keto.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
69
oryx/configx/koanf_confmap.go
Normal file
69
oryx/configx/koanf_confmap.go
Normal file
@@ -0,0 +1,69 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package configx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/knadh/koanf/maps"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// KoanfConfmap implements a raw map[string]interface{} provider.
|
||||
type KoanfConfmap struct {
|
||||
tuples []tuple
|
||||
}
|
||||
|
||||
// Provider returns a confmap Provider that takes a flat or nested
|
||||
// map[string]interface{}. If a delim is provided, it indicates that the
|
||||
// keys are flat and the map needs to be unflatted by delim.
|
||||
func NewKoanfConfmap(tuples []tuple) *KoanfConfmap {
|
||||
return &KoanfConfmap{tuples: jsonify(tuples)}
|
||||
}
|
||||
|
||||
func jsonify(tuples []tuple) []tuple {
|
||||
for k, t := range tuples {
|
||||
var parsed interface{}
|
||||
switch vt := t.Value.(type) {
|
||||
case string:
|
||||
if gjson.Valid(vt) && json.NewDecoder(bytes.NewBufferString(vt)).Decode(&parsed) == nil {
|
||||
tuples[k].Value = parsed
|
||||
}
|
||||
continue
|
||||
case []byte:
|
||||
if gjson.ValidBytes(vt) && json.NewDecoder(bytes.NewBuffer(vt)).Decode(&parsed) == nil {
|
||||
tuples[k].Value = parsed
|
||||
}
|
||||
continue
|
||||
case json.RawMessage:
|
||||
if gjson.ValidBytes(vt) && json.NewDecoder(bytes.NewBuffer(vt)).Decode(&parsed) == nil {
|
||||
tuples[k].Value = parsed
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
return tuples
|
||||
}
|
||||
|
||||
// ReadBytes is not supported by the env provider.
|
||||
func (e *KoanfConfmap) ReadBytes() ([]byte, error) {
|
||||
return nil, errors.New("confmap provider does not support this method")
|
||||
}
|
||||
|
||||
// Read returns the loaded map[string]interface{}.
|
||||
func (e *KoanfConfmap) Read() (map[string]interface{}, error) {
|
||||
values := map[string]interface{}{}
|
||||
for _, t := range e.tuples {
|
||||
values[t.Key] = t.Value
|
||||
}
|
||||
|
||||
// Ensure any nested values are properly converted as well
|
||||
cp := maps.Copy(values)
|
||||
maps.IntfaceKeysToStrings(cp)
|
||||
cp = maps.Unflatten(cp, Delimiter)
|
||||
|
||||
return cp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user