(values setupValues)
| 146 | } |
| 147 | |
| 148 | func buildConfig(values setupValues) ([]byte, error) { |
| 149 | if len(configTemplate) == 0 { |
| 150 | return nil, fmt.Errorf("embedded config template is empty") |
| 151 | } |
| 152 | |
| 153 | var node yaml.Node |
| 154 | if err := yaml.Unmarshal(configTemplate, &node); err != nil { |
| 155 | return nil, fmt.Errorf("parse embedded config template: %w", err) |
| 156 | } |
| 157 | if values.Proxy != "" { |
| 158 | setMappingValue(&node, []string{"proxy"}, values.Proxy) |
| 159 | } |
| 160 | setMappingValue(&node, []string{"username"}, values.Username) |
| 161 | setMappingValue(&node, []string{"password"}, values.Password) |
| 162 | if values.DownloadDir != "" { |
| 163 | setMappingValue(&node, []string{"open", "download_dir"}, values.DownloadDir) |
| 164 | } |
| 165 | |
| 166 | out, err := yaml.Marshal(&node) |
| 167 | if err != nil { |
| 168 | return nil, fmt.Errorf("encode config: %w", err) |
| 169 | } |
| 170 | return out, nil |
| 171 | } |
| 172 | |
| 173 | func setMappingValue(node *yaml.Node, path []string, value string) bool { |
| 174 | if node.Kind == yaml.DocumentNode && len(node.Content) > 0 { |
no test coverage detected