access-watch-rails 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.gitignore +11 -0
 - data/access-watch-rails.gemspec +35 -0
 - data/lib/access_watch/logger.rb +57 -0
 - data/lib/access_watch_rails.rb +3 -2
 - metadata +4 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5e91c88dd7c623aaf06d4d7392e562fd7c27b071
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 795bb3aade08b62ba7689ce6d82314d98c8096f3
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 4dc8314982599cc986deb772700538e2119ea0151f0cdb7479d1e8ff96426044a2cb2d842fb70a216b3f9ee6bfe9addb94ea16ea55127cee2c8a7b7eaca9c78c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 74fba29d0153dfcc9ab969f7cde738c63a9ac353b12123d7d1a5884a471efd682eb7ac27b6cc74c19bb09d7245134b8cbd36d54b9053a0cb8a307209400fc3a9
         
     | 
    
        data/.gitignore
    ADDED
    
    
| 
         @@ -0,0 +1,35 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # coding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
            lib = File.expand_path("../lib", __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "access_watch/rails_version"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 7 
     | 
    
         
            +
              spec.name          = "access-watch-rails"
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.version       = AccessWatch::RAILS_VERSION
         
     | 
| 
      
 9 
     | 
    
         
            +
              spec.authors       = ["Alexis Bernard"]
         
     | 
| 
      
 10 
     | 
    
         
            +
              spec.email         = ["alexis@bernard.io"]
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              spec.summary       = "A Rails library to log and analyse HTTP requests using the Access Watch cloud service."
         
     | 
| 
      
 13 
     | 
    
         
            +
              spec.description   = "A Rails library to log and analyse HTTP requests using the Access Watch cloud service."
         
     | 
| 
      
 14 
     | 
    
         
            +
              spec.homepage      = "https://access.watch/"
         
     | 
| 
      
 15 
     | 
    
         
            +
              spec.license       = "MIT"
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
         
     | 
| 
      
 18 
     | 
    
         
            +
              # to allow pushing to a single host or delete this section to allow pushing to any host.
         
     | 
| 
      
 19 
     | 
    
         
            +
              if spec.respond_to?(:metadata)
         
     | 
| 
      
 20 
     | 
    
         
            +
                spec.metadata["allowed_push_host"] = "https://rubygems.org"
         
     | 
| 
      
 21 
     | 
    
         
            +
              else
         
     | 
| 
      
 22 
     | 
    
         
            +
                raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              spec.files         = `git ls-files -z`.split("\x0").reject do |f|
         
     | 
| 
      
 26 
     | 
    
         
            +
                f.match(%r{^(test|spec|features)/})
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              spec.bindir        = "exe"
         
     | 
| 
      
 29 
     | 
    
         
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
      
 30 
     | 
    
         
            +
              spec.require_paths = ["lib"]
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              spec.add_development_dependency "bundler", "~> 1.13"
         
     | 
| 
      
 33 
     | 
    
         
            +
              spec.add_development_dependency "rake", "~> 10.0"
         
     | 
| 
      
 34 
     | 
    
         
            +
              spec.add_dependency "access-watch-ruby", ">= 0.0.1"
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,57 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module AccessWatch
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Logger
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :client
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(config)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @client = AccessWatch::Client.new(config)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @parameter_filter = ActionDispatch::Http::ParameterFilter.new(Rails.application.config.filter_parameters)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  ActiveSupport::Notifications.subscribe("process_action.action_controller", &method(:after_http_request))
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def after_http_request(name, start, finish, id, payload)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  request = payload[:headers].instance_variable_get(:@req)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  post_request(
         
     | 
| 
      
 14 
     | 
    
         
            +
                    time: start,
         
     | 
| 
      
 15 
     | 
    
         
            +
                    address: request.remote_ip,
         
     | 
| 
      
 16 
     | 
    
         
            +
                    host: request.host,
         
     | 
| 
      
 17 
     | 
    
         
            +
                    request: {
         
     | 
| 
      
 18 
     | 
    
         
            +
                      # TODO: Check if is SERVER_PROTOCOL comes from client browser
         
     | 
| 
      
 19 
     | 
    
         
            +
                      # "protocol": "HTTP/1.1",
         
     | 
| 
      
 20 
     | 
    
         
            +
                      method: payload[:method],
         
     | 
| 
      
 21 
     | 
    
         
            +
                      scheme: URI(request.original_url).scheme,
         
     | 
| 
      
 22 
     | 
    
         
            +
                      host: request.host,
         
     | 
| 
      
 23 
     | 
    
         
            +
                      port: request.port,
         
     | 
| 
      
 24 
     | 
    
         
            +
                      url: payload[:path],
         
     | 
| 
      
 25 
     | 
    
         
            +
                      headers: extract_headers(payload)
         
     | 
| 
      
 26 
     | 
    
         
            +
                    },
         
     | 
| 
      
 27 
     | 
    
         
            +
                    response: {status: payload[:status]},
         
     | 
| 
      
 28 
     | 
    
         
            +
                  )
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                #######################
         
     | 
| 
      
 32 
     | 
    
         
            +
                ### Private methods ###
         
     | 
| 
      
 33 
     | 
    
         
            +
                #######################
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                private
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def post_request(data)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  post_async("log".freeze, data)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                def post_async(path, data)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  Thread.new { client.post(path, data) }
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def filter_sensitive_data(hash)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @parameter_filter ? @parameter_filter.filter(hash) : hash
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def filter_environment_variables(hash)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  hash.clone.keep_if { |key,value| key == key.upcase }
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                def extract_headers(payload)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  filter_sensitive_data(filter_environment_variables(payload[:headers].env))
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
      
 57 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/access_watch_rails.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: access-watch-rails
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Alexis Bernard
         
     | 
| 
         @@ -60,6 +60,9 @@ executables: [] 
     | 
|
| 
       60 
60 
     | 
    
         
             
            extensions: []
         
     | 
| 
       61 
61 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       62 
62 
     | 
    
         
             
            files:
         
     | 
| 
      
 63 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 64 
     | 
    
         
            +
            - access-watch-rails.gemspec
         
     | 
| 
      
 65 
     | 
    
         
            +
            - lib/access_watch/logger.rb
         
     | 
| 
       63 
66 
     | 
    
         
             
            - lib/access_watch_rails.rb
         
     | 
| 
       64 
67 
     | 
    
         
             
            homepage: https://access.watch/
         
     | 
| 
       65 
68 
     | 
    
         
             
            licenses:
         
     |