| 27 | } |
| 28 | |
| 29 | func runtimeConfigFromConfig(cfg *config.Config) runtimeConfig { |
| 30 | out := runtimeConfig{ |
| 31 | Dir: "plugins", |
| 32 | Items: make(map[string]runtimeItemConfig), |
| 33 | } |
| 34 | if cfg == nil { |
| 35 | return out |
| 36 | } |
| 37 | |
| 38 | out.Enabled = cfg.Plugins.Enabled |
| 39 | out.Dir = strings.TrimSpace(cfg.Plugins.Dir) |
| 40 | if out.Dir == "" { |
| 41 | out.Dir = "plugins" |
| 42 | } |
| 43 | |
| 44 | ids := make([]string, 0, len(cfg.Plugins.Configs)) |
| 45 | for id := range cfg.Plugins.Configs { |
| 46 | ids = append(ids, id) |
| 47 | } |
| 48 | sort.Strings(ids) |
| 49 | |
| 50 | for _, id := range ids { |
| 51 | item := cfg.Plugins.Configs[id] |
| 52 | enabled := false |
| 53 | if item.Enabled != nil { |
| 54 | enabled = *item.Enabled |
| 55 | } |
| 56 | |
| 57 | out.Items[id] = runtimeItemConfig{ |
| 58 | ID: id, |
| 59 | Enabled: enabled, |
| 60 | Priority: item.Priority, |
| 61 | Version: pluginConfigDesiredVersion(item), |
| 62 | ConfigYAML: runtimeConfigYAML(item, enabled), |
| 63 | } |
| 64 | } |
| 65 | return out |
| 66 | } |
| 67 | |
| 68 | func defaultRuntimeItemConfig(id string) runtimeItemConfig { |
| 69 | return runtimeItemConfig{ |