|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
| 5 | + "fmt" |
4 | 6 | "os" |
5 | 7 |
|
6 | 8 | "github.com/BurntSushi/toml" |
@@ -61,19 +63,13 @@ type StaticConfig struct { |
61 | 63 | // If set to "kubeconfig", the clusters will be loaded from those in the kubeconfig. |
62 | 64 | // If set to "in-cluster", the server will use the in cluster config |
63 | 65 | ClusterProviderStrategy string `toml:"cluster_provider_strategy,omitempty"` |
64 | | - // ClusterContexts is which context should be used for each cluster |
65 | | - ClusterContexts map[string]string `toml:"cluster_contexts"` |
66 | | - |
67 | | - // name of the context in the kubeconfig file to look for acm access credentials in. should point to the "hub" cluster |
68 | | - AcmContextName string `toml:"acm_context_name,omitempty"` |
69 | | - // the host for the ACM cluster proxy addon |
70 | | - // if using the acm-kubeconfig strategy, this should be the route for the proxy |
71 | | - // if using the acm strategy, this should be the service for the proxy |
72 | | - AcmClusterProxyAddonHost string `toml:"acm_cluster_proxy_addon_host,omitempty"` |
73 | | - // whether to skip verifiying the tls certs from the cluster proxy |
74 | | - AcmClusterProxyAddonSkipTLSVerify bool `toml:"acm_cluster_proxy_addon_skip_tls_verify"` |
75 | | - // the CA file for the cluster proxy addon |
76 | | - AcmClusterProxyAddonCaFile string `toml:"acm_cluster_proxy_addon_ca_file"` |
| 66 | + |
| 67 | + // ClusterProvider-specific configurations |
| 68 | + // This map holds raw TOML primitives that will be parsed by registered provider parsers |
| 69 | + ClusterProviderConfigs map[string]toml.Primitive `toml:"cluster_provider_configs,omitempty"` |
| 70 | + |
| 71 | + // Internal: parsed provider configs (not exposed to TOML package) |
| 72 | + parsedClusterProviderConfigs map[string]ProviderConfig |
77 | 73 | } |
78 | 74 |
|
79 | 75 | func Default() *StaticConfig { |
@@ -101,8 +97,46 @@ func Read(configPath string) (*StaticConfig, error) { |
101 | 97 | // ReadToml reads the toml data and returns the StaticConfig. |
102 | 98 | func ReadToml(configData []byte) (*StaticConfig, error) { |
103 | 99 | config := Default() |
104 | | - if err := toml.Unmarshal(configData, config); err != nil { |
| 100 | + md, err := toml.NewDecoder(bytes.NewReader(configData)).Decode(config) |
| 101 | + if err != nil { |
| 102 | + return nil, err |
| 103 | + } |
| 104 | + |
| 105 | + if err := config.parseClusterProviderConfigs(md); err != nil { |
105 | 106 | return nil, err |
106 | 107 | } |
| 108 | + |
107 | 109 | return config, nil |
108 | 110 | } |
| 111 | + |
| 112 | +func (c *StaticConfig) GetProviderConfig(strategy string) (ProviderConfig, bool) { |
| 113 | + config, ok := c.parsedClusterProviderConfigs[strategy] |
| 114 | + |
| 115 | + return config, ok |
| 116 | +} |
| 117 | + |
| 118 | +func (c *StaticConfig) parseClusterProviderConfigs(md toml.MetaData) error { |
| 119 | + if c.parsedClusterProviderConfigs == nil { |
| 120 | + c.parsedClusterProviderConfigs = make(map[string]ProviderConfig, len(c.ClusterProviderConfigs)) |
| 121 | + } |
| 122 | + |
| 123 | + for strategy, primitive := range c.ClusterProviderConfigs { |
| 124 | + parser, ok := getProviderConfigParser(strategy) |
| 125 | + if !ok { |
| 126 | + continue |
| 127 | + } |
| 128 | + |
| 129 | + providerConfig, err := parser(primitive, md) |
| 130 | + if err != nil { |
| 131 | + return fmt.Errorf("failed to parse config for ClusterProvider '%s': %w", strategy, err) |
| 132 | + } |
| 133 | + |
| 134 | + if err := providerConfig.Validate(); err != nil { |
| 135 | + return fmt.Errorf("invalid config file for ClusterProvider '%s': %w", strategy, err) |
| 136 | + } |
| 137 | + |
| 138 | + c.parsedClusterProviderConfigs[strategy] = providerConfig |
| 139 | + } |
| 140 | + |
| 141 | + return nil |
| 142 | +} |
0 commit comments