mn_middleware_gem 1.2.0 → 1.3.0
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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0dcc70086267dde8dd81032660c7722a9a43dc1ea585ba7f8cab8c760691eaea
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7e848ae5a0e189cbed0285eaac80252dddce0b56bcecdb144c668e8ad9bd1768
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e656029783ef8e62180d7bf08d240ed5f0db42eccf982f1ef262cc55598d2ccafc05aad0446d9d8796a9d7b77e85ca14d74abd8c0ab97c078580a3ae1e11d747
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 1fd1d5f8bf712c45ce18df4b536691c4d1c1243fe357f80889202ee2d7da95966e995906b2993f74f087df22de5e45b32fb29cdd632497791333f3ac9442a9e1
         
     | 
| 
         @@ -1,42 +1,44 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'securerandom'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'net/http'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              def call(env)
         
     | 
| 
       10 
     | 
    
         
            -
                request_id = nil
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                # see if you can get an existing request id
         
     | 
| 
       13 
     | 
    
         
            -
                # from these sources, in order of priority
         
     | 
| 
       14 
     | 
    
         
            -
                if env['HTTP_X_REQUEST_ID']
         
     | 
| 
       15 
     | 
    
         
            -
                  request_id = env['HTTP_X_REQUEST_ID']
         
     | 
| 
       16 
     | 
    
         
            -
                  Rails.logger.debug "Found HTTP_X_REQUEST_ID #{request_id}"
         
     | 
| 
       17 
     | 
    
         
            -
                elsif env['HTTP_X_AMZN_TRACE_ID']
         
     | 
| 
       18 
     | 
    
         
            -
                  request_id = env['HTTP_X_REQUEST_ID'] = env['HTTP_X_AMZN_TRACE_ID'].match(/^.*Root=([^;]*).*$/).captures[0]
         
     | 
| 
       19 
     | 
    
         
            -
                  Rails.logger.debug "Found HTTP_X_AMZN_TRACE_ID #{request_id}"
         
     | 
| 
      
 4 
     | 
    
         
            +
            module MnMiddleware
         
     | 
| 
      
 5 
     | 
    
         
            +
              class CorrelationId
         
     | 
| 
      
 6 
     | 
    
         
            +
                def initialize app
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @app = app
         
     | 
| 
       20 
8 
     | 
    
         
             
                end
         
     | 
| 
       21 
9 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
                   
     | 
| 
      
 10 
     | 
    
         
            +
                def call(env)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  request_id = nil
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  # see if you can get an existing request id
         
     | 
| 
      
 14 
     | 
    
         
            +
                  # from these sources, in order of priority
         
     | 
| 
      
 15 
     | 
    
         
            +
                  if env['HTTP_X_REQUEST_ID']
         
     | 
| 
      
 16 
     | 
    
         
            +
                    request_id = env['HTTP_X_REQUEST_ID']
         
     | 
| 
      
 17 
     | 
    
         
            +
                    Rails.logger.debug "Found HTTP_X_REQUEST_ID #{request_id}"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  elsif env['HTTP_X_AMZN_TRACE_ID']
         
     | 
| 
      
 19 
     | 
    
         
            +
                    request_id = env['HTTP_X_REQUEST_ID'] = env['HTTP_X_AMZN_TRACE_ID'].match(/^.*Root=([^;]*).*$/).captures[0]
         
     | 
| 
      
 20 
     | 
    
         
            +
                    Rails.logger.debug "Found HTTP_X_AMZN_TRACE_ID #{request_id}"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  # if no request id is available, generate one
         
     | 
| 
      
 24 
     | 
    
         
            +
                  if request_id.nil?
         
     | 
| 
      
 25 
     | 
    
         
            +
                    request_id = env['HTTP_X_REQUEST_ID'] = SecureRandom.uuid
         
     | 
| 
      
 26 
     | 
    
         
            +
                    Rails.logger.debug "Set request_id #{request_id}"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  # set the request id in the request store
         
     | 
| 
      
 30 
     | 
    
         
            +
                  # so we can use it later in the Net::HTTPHeader monkey patch
         
     | 
| 
      
 31 
     | 
    
         
            +
                  RequestStore.store[:request_id] = request_id
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  # call the superclass and get the app return values
         
     | 
| 
      
 34 
     | 
    
         
            +
                  status, headers, response = @app.call(env)
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                  # set the request id in the response header
         
     | 
| 
      
 37 
     | 
    
         
            +
                  headers['X-Request-Id'] = request_id
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  # return all the values back up
         
     | 
| 
      
 40 
     | 
    
         
            +
                  [status, headers, response]
         
     | 
| 
       26 
41 
     | 
    
         
             
                end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                # set the request id in the request store
         
     | 
| 
       29 
     | 
    
         
            -
                # so we can use it later in the Net::HTTPHeader monkey patch
         
     | 
| 
       30 
     | 
    
         
            -
                RequestStore.store[:request_id] = request_id
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                # call the superclass and get the app return values
         
     | 
| 
       33 
     | 
    
         
            -
                status, headers, response = @app.call(env)
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                # set the request id in the response header
         
     | 
| 
       36 
     | 
    
         
            -
                headers['X-Request-Id'] = request_id
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                # return all the values back up
         
     | 
| 
       39 
     | 
    
         
            -
                [status, headers, response]
         
     | 
| 
       40 
42 
     | 
    
         
             
              end
         
     | 
| 
       41 
43 
     | 
    
         
             
            end
         
     | 
| 
       42 
44 
     | 
    
         | 
| 
         @@ -1,15 +1,17 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            module MnMiddleware
         
     | 
| 
      
 2 
     | 
    
         
            +
              class RemoteIpLogger
         
     | 
| 
      
 3 
     | 
    
         
            +
                def initialize(app)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  @app = app
         
     | 
| 
      
 5 
     | 
    
         
            +
                end
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
                def call(env)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if env["HTTP_X_FORWARDED_FOR"]
         
     | 
| 
      
 9 
     | 
    
         
            +
                    remote_ip = env["HTTP_X_FORWARDED_FOR"].split(",")[0]
         
     | 
| 
      
 10 
     | 
    
         
            +
                    env['REMOTE_ADDR'] = env["action_dispatch.remote_ip"] = env["HTTP_X_FORWARDED_FOR"] = remote_ip
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @app.call(env)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  else
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @app.call(env)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
       13 
15 
     | 
    
         
             
                end
         
     | 
| 
       14 
16 
     | 
    
         
             
              end
         
     | 
| 
       15 
17 
     | 
    
         
             
            end
         
     |