MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / autoEncryptConfig

Function autoEncryptConfig

internal/app/run.go:164–195  ·  view source on GitHub ↗
(cfg *config.Config, configPath string)

Source from the content-addressed store, hash-verified

162}
163
164func 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}

Callers 1

Calls 5

IsSOPSEncryptedFunction · 0.92
SaveConfigFileFunction · 0.92
IconTextFunction · 0.92

Tested by

no test coverage detected