trufflehog/pkg/detectors/jdbc/sqlite.go
Cody Rose 20b7793828
JDBC indeterminacy (#1507)
This PR adds an indeterminacy check to the JDBC verifiers.
2023-07-19 16:57:57 -04:00

43 lines
986 B
Go

package jdbc
import (
"context"
"errors"
"strings"
_ "github.com/mattn/go-sqlite3"
)
type sqliteJDBC struct {
filename string
params map[string]string
testing bool
}
var cannotVerifySqliteError error = errors.New("sqlite credentials cannot be verified")
func (s *sqliteJDBC) ping(ctx context.Context) pingResult {
if !s.testing {
// sqlite is not a networked database, so we cannot verify
return pingResult{cannotVerifySqliteError, true}
}
return ping(ctx, "sqlite3", isSqliteErrorDeterminate, s.filename)
}
func isSqliteErrorDeterminate(err error) bool {
return true
}
func parseSqlite(subname string) (jdbc, error) {
filename, params, _ := strings.Cut(subname, "?")
if filename == "" {
return nil, errors.New("empty filename")
}
j := &sqliteJDBC{filename: filename, params: map[string]string{}}
for _, keyVal := range strings.Split(params, "&") {
if key, val, found := strings.Cut(keyVal, "="); found {
j.params[key] = val
}
}
return j, nil
}