Files
esctl/pkg/es/index_template_settings.go

60 lines
1.2 KiB
Go
Raw Normal View History

2026-06-15 15:18:21 +02:00
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+"?flat_settings", "")
2026-06-15 15:18:21 +02:00
if err != nil {
return err
}
data := Tpl{}
if err = json.Unmarshal(raw, &data); err != nil {
return err
}
if conf.Debug {
output, err := prettyfiJson(conf, raw)
if err != nil {
2026-06-15 15:18:21 +02:00
return err
}
fmt.Println(output)
2026-06-15 15:18:21 +02:00
}
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 {
table.Entries = append(table.Entries, []string{topic, fmt.Sprintf("%v", val)})
2026-06-15 15:18:21 +02:00
}
return nil
}