Sha256: 48f467298db025140b92002214b4ba7363f1bd1160af188632154a85a8f3df04

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

module Sanctify
  class ParserError < StandardError; end
  class MatcherList
    def initialize
      @matchers = DEFAULT_MATCHERS
    end

    def add(desc:, regex:)
      if desc.length.zero?
        raise ParserError, "Description must exist and be greater length than zero"
      end

      unless regex.is_a? Regexp
        raise ParserError, "Regex must be of type Regexp"
      end

      @matchers << { description: desc, regex: regex }
      @matchers
    end

    def each(&blk)
      @matchers.each &blk
    end

    DEFAULT_MATCHERS = [
      {
        description: "AWS Access Key ID",
        regex: /AKIA[0-9A-Z]{16}/
      },
      {
        description: "AWS Secret Key",
        regex: /\b[\w\/&?=-@#$%\\^+]{40}\b/
      },
      {
        description: "Redis URL with Password",
        regex: /redis:\/\/[0-9a-zA-Z:@.\\-]+/
      },
      {
        description: "URL Basic auth",
        regex: /https?:\/\/[0-9a-zA-z_]+?:[0-9a-zA-z_]+?@.+?/
      },
      {
        description:"Google Access Token",
        regex: /ya29.[0-9a-zA-Z_\\-]{68}/
      },
      {
        description: "Google API",
        regex: /AIzaSy[0-9a-zA-Z_\\-]{33}/
      },
      {
        description: "Slack API",
        regex: /xoxp-\\d+-\\d+-\\d+-[0-9a-f]+/
      },
      {
        description: "Slack Bot",
        regex: /xoxb-\\d+-[0-9a-zA-Z]+/
      },
      {
        description: "Gem Fury v1",
        regex: /https?:\/\/[0-9a-zA-Z]+@[a-z]+\\.(gemfury.com|fury.io)(\/[a-z]+)?/
      },
      {
        description: "Gem Fury v2",
        regex: /https?:\/\/[a-z]+\\.(gemfury.com|fury.io)\/[0-9a-zA-Z]{20}/
      }
    ]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sanctify-0.1.1 lib/sanctify/matcher_list.rb
sanctify-0.1.0 lib/sanctify/matcher_list.rb