EncryptConfigSensitiveFields encrypts sensitive fields in the entire Config. This includes both profile-based and legacy fields.
(cfg *Config)
| 243 | // EncryptConfigSensitiveFields encrypts sensitive fields in the entire Config. |
| 244 | // This includes both profile-based and legacy fields. |
| 245 | func EncryptConfigSensitiveFields(cfg *Config) error { |
| 246 | // Encrypt profile fields |
| 247 | for name, profile := range cfg.Profiles { |
| 248 | if err := EncryptSensitiveFields(&profile); err != nil { |
| 249 | return fmt.Errorf("encrypt profile %s: %w", name, err) |
| 250 | } |
| 251 | cfg.Profiles[name] = profile |
| 252 | } |
| 253 | |
| 254 | // Encrypt legacy fields |
| 255 | if cfg.Password != "" && !isEncrypted(cfg.Password) { |
| 256 | var err error |
| 257 | cfg.Password, err = EncryptField(cfg.Password) |
| 258 | if err != nil { |
| 259 | return fmt.Errorf("encrypt legacy password: %w", err) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if cfg.TokenSecret != "" && !isEncrypted(cfg.TokenSecret) { |
| 264 | var err error |
| 265 | cfg.TokenSecret, err = EncryptField(cfg.TokenSecret) |
| 266 | if err != nil { |
| 267 | return fmt.Errorf("encrypt legacy token_secret: %w", err) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if cfg.Plugins.Ansible.DefaultPassword != "" && !isEncrypted(cfg.Plugins.Ansible.DefaultPassword) { |
| 272 | var err error |
| 273 | cfg.Plugins.Ansible.DefaultPassword, err = EncryptField(cfg.Plugins.Ansible.DefaultPassword) |
| 274 | if err != nil { |
| 275 | return fmt.Errorf("encrypt ansible default_password: %w", err) |
| 276 | } |
| 277 | } |
| 278 | if cfg.Plugins.Ansible.Bootstrap.Password != "" && !isEncrypted(cfg.Plugins.Ansible.Bootstrap.Password) { |
| 279 | var err error |
| 280 | cfg.Plugins.Ansible.Bootstrap.Password, err = EncryptField(cfg.Plugins.Ansible.Bootstrap.Password) |
| 281 | if err != nil { |
| 282 | return fmt.Errorf("encrypt ansible bootstrap password: %w", err) |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | return nil |
| 287 | } |
| 288 | |
| 289 | // DecryptConfigSensitiveFields decrypts sensitive fields in the entire Config. |
| 290 | // This includes both profile-based and legacy fields. |
no test coverage detected