mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 14:24:20 +02:00
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
|
|
package es
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||
|
|
"codeberg.org/scip/esctl/pkg/printer"
|
||
|
|
)
|
||
|
|
|
||
|
|
type TplTemplateData struct {
|
||
|
|
Settings map[string]any `json:"settings"`
|
||
|
|
Aliases map[string]any `json:"aliases"`
|
||
|
|
Lifecycle map[string]any `json:"lifecycle"`
|
||
|
|
Mappings map[string]any `json:"mappings"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type TplTemplate struct {
|
||
|
|
Template TplTemplateData `json:"template"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type TplTpl struct {
|
||
|
|
IndexTemplate TplTemplate `json:"index_template"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type Tpl struct {
|
||
|
|
IndexTemplates []TplTpl `json:"index_templates"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func getIndexTemplateSettings(conf *cfg.Config, tplname string, table *printer.Table) error {
|
||
|
|
raw, err := CallAPI(conf, "GET", "/_index_template/"+tplname, "")
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
data := Tpl{}
|
||
|
|
if err = json.Unmarshal(raw, &data); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
if conf.Debug {
|
||
|
|
if err := prettyfiJson(conf, raw); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(data.IndexTemplates) == 0 {
|
||
|
|
return fmt.Errorf("index_template %s not found", tplname)
|
||
|
|
}
|
||
|
|
|
||
|
|
tpl := data.IndexTemplates[0].IndexTemplate.Template.Settings
|
||
|
|
for topic, val := range tpl {
|
||
|
|
paths := getJsonPath(map[string]string{}, val.(map[string]any), topic)
|
||
|
|
|
||
|
|
for setting, value := range paths {
|
||
|
|
table.Entries = append(table.Entries, []string{setting, fmt.Sprintf("%v", value)})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|