IsSOPSEncrypted checks if a file is SOPS-encrypted.
(path string, data []byte)
| 223 | |
| 224 | // IsSOPSEncrypted checks if a file is SOPS-encrypted. |
| 225 | func IsSOPSEncrypted(path string, data []byte) bool { |
| 226 | // Check for SOPS header patterns in the entire content |
| 227 | content := string(data) |
| 228 | // Check for "sops:" YAML key (most common) or "\"sops\":" JSON key |
| 229 | hasSopsKey := contains(content, "sops:") || contains(content, "\"sops\":") |
| 230 | // Check for ENC[ marker which is specific to SOPS/Age |
| 231 | hasEnc := contains(content, "ENC[") |
| 232 | |
| 233 | if DebugEnabled { |
| 234 | // Use global logger for debug output to avoid UI corruption |
| 235 | if globalLogger := logger.GetGlobalLogger(); globalLogger != nil { |
| 236 | globalLogger.Debug("SOPS detection for %s: hasSopsKey=%v, hasEnc=%v", path, hasSopsKey, hasEnc) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | return hasSopsKey || hasEnc |
| 241 | } |
| 242 | |
| 243 | // contains checks if a string contains a substring (case-insensitive). |
| 244 | func contains(s, substr string) bool { |
no test coverage detected