mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 11:24:17 +02:00
61 lines
1.2 KiB
Go
61 lines
1.2 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+"?flat_settings", "")
|
|
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 {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(output)
|
|
}
|
|
|
|
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.AddRow(topic, val)
|
|
}
|
|
|
|
return nil
|
|
}
|