twilio.go 672 B

12345678910111213141516171819202122232425262728293031323334
  1. package rules
  2. import (
  3. "regexp"
  4. "github.com/rs/zerolog/log"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. "github.com/zricethezav/gitleaks/v8/detect"
  7. )
  8. func Twilio() *config.Rule {
  9. // define rule
  10. r := config.Rule{
  11. Description: "Twilio API Key",
  12. RuleID: "twilio-api-key",
  13. Regex: regexp.MustCompile(`SK[0-9a-fA-F]{32}`),
  14. Keywords: []string{"twilio"},
  15. }
  16. // validate
  17. tps := []string{
  18. "twilioAPIKey := \"SK" + sampleHex32Token + "\"",
  19. }
  20. d := detect.NewDetector(config.Config{
  21. Rules: []*config.Rule{&r},
  22. })
  23. for _, tp := range tps {
  24. if len(d.DetectString(tp)) != 1 {
  25. log.Fatal().Msg("Failed to validate twilio")
  26. }
  27. }
  28. return &r
  29. }