(cfg *config.Config, configPath string)
| 162 | } |
| 163 | |
| 164 | func autoEncryptConfig(cfg *config.Config, configPath string) { |
| 165 | if configPath == "" || !cfg.HasCleartextSensitiveData() { |
| 166 | return |
| 167 | } |
| 168 | |
| 169 | // nolint:gosec // configPath is validated and comes from trusted sources (user input or default paths) |
| 170 | data, err := os.ReadFile(configPath) |
| 171 | if err != nil { |
| 172 | return |
| 173 | } |
| 174 | |
| 175 | if config.IsSOPSEncrypted(configPath, data) { |
| 176 | cfg.MarkSensitiveDataEncrypted() |
| 177 | return |
| 178 | } |
| 179 | |
| 180 | cfgCopy := *cfg |
| 181 | cfgCopy.Profiles = make(map[string]config.ProfileConfig) |
| 182 | for k, v := range cfg.Profiles { |
| 183 | cfgCopy.Profiles[k] = v |
| 184 | } |
| 185 | |
| 186 | if err := config.SaveConfigFile(&cfgCopy, configPath); err != nil { |
| 187 | if config.DebugEnabled { |
| 188 | fmt.Println(display.IconText("⚠️", fmt.Sprintf("Warning: Failed to encrypt and save config: %v", err), cfg.ShowIcons)) |
| 189 | } |
| 190 | return |
| 191 | } |
| 192 | |
| 193 | fmt.Println(display.IconText("🔐", "Encrypted sensitive fields in config file", cfg.ShowIcons)) |
| 194 | cfg.MarkSensitiveDataEncrypted() |
| 195 | } |
no test coverage detected