mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-09-03 08:14:32 +00:00
seedling: Glob all configs found (#502)
* 🌱 Glob all configs found This allows to read all the configs found during scanning - this is especially useful in first boot as it allows to have separate config file logic split into several files Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> * 🌱 Simplify config merge logic Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * 🌱 Make the function work Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Signed-off-by: mudler <mudler@kairos.io> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> Signed-off-by: mudler <mudler@kairos.io> Co-authored-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
committed by
Itxaka
parent
b92c2eaf6b
commit
b99d55b900
@@ -9,6 +9,35 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func YAMLHasKey(query string, content []byte) (bool, error) {
|
||||
data := map[string]interface{}{}
|
||||
|
||||
err := yaml.Unmarshal([]byte(content), &data)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
c, err := gojq.Parse(fmt.Sprintf(".%s | ..", query))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
code, err := gojq.Compile(c)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
iter := code.Run(data)
|
||||
|
||||
v, _ := iter.Next()
|
||||
|
||||
if err, ok := v.(error); ok {
|
||||
return false, err
|
||||
}
|
||||
if v == nil {
|
||||
return false, fmt.Errorf("not found")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func jq(command string, data map[string]interface{}) (map[string]interface{}, error) {
|
||||
query, err := gojq.Parse(command)
|
||||
if err != nil {
|
||||
@@ -22,7 +51,7 @@ func jq(command string, data map[string]interface{}) (map[string]interface{}, er
|
||||
|
||||
v, ok := iter.Next()
|
||||
if !ok {
|
||||
return nil, errors.New("failed getting rsult from gojq")
|
||||
return nil, errors.New("failed getting result from gojq")
|
||||
}
|
||||
if err, ok := v.(error); ok {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user