qodex-rails 0.1.14 → 0.1.16

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: 33fdd4101a6afdcb2a1379bcb2a832ca25045132668c5c6c156df5645f3965fb
4
- data.tar.gz: 9ee4fcd3756c9664006c1c9a628645c0f2197d0e58c85fc165ed63a189ceb08b
3
+ metadata.gz: e88448baabd3c75fe3d312fe1b58fa9a0ba449d457f5acd4b4727efb1f9dcc5c
4
+ data.tar.gz: 40239b7f2e897ef1f6ed3ca51f54b4a1af66a3c95c28cf3d3ac1d12090d5004c
5
5
  SHA512:
6
- metadata.gz: 39a1a63dcd110356ee18edeae01b7b9642946a3beb5d495cf870e28fe080bbfa08eb73ae0354e4ab082c2d7c19e9febe3f01fe8ffba8626a577af0bb01ffa82c
7
- data.tar.gz: d50dd079002906880ce5d6344bd28255fc05dece50703ea6bce3c26b79c7a2ffd2f4ea70e973fd7d84e6771d91f2eee5d71b8ef6e459b5f26e330528ed746044
6
+ metadata.gz: 40233126d4c00ca269c1f04f0038c5222d365496b0eb6d5ee8b9233d8d47d1a34a850fac55022738b69c2b04d6d641bbb19659e011f1a6f097c43fa7e9693a97
7
+ data.tar.gz: 89246f891ba54b5617b77e1811b53200cec88bbdf097bb80fa9fe254a3d3d4ae50a4d44a2f3123d8a64e9e67394f710b784008819a1305e92121075087b247af
data/README.md CHANGED
@@ -17,7 +17,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
17
17
  ## Configuration
18
18
  # config/initializers/qodex_rails.rb
19
19
 
20
-
20
+
21
21
  QodexRails.configure do |config|
22
22
  # Your configuration settings for qodex-rails in the staging environment
23
23
  project_name = Rails.application.class.module_parent_name rescue 'qodex'
@@ -25,8 +25,9 @@ If bundler is not being used to manage dependencies, install the gem by executin
25
25
  config.allowed_environments = ['staging', 'production'] # Default value is staging if not set. Add production to enable in production
26
26
  config.frequency = 'high' #default value is medium. to control the speed of the logs processing
27
27
  config.api_key = 'Your API Key'
28
- end
29
-
28
+ config.pii_masking = ['api-key', 'access-token'] # add keys to skip sending actual value to qodex server
29
+ end
30
+
30
31
  ## Contributing
31
32
 
32
33
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/qodex-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/qodex-rails/blob/main/CODE_OF_CONDUCT.md).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Qodex
4
4
  module Rails
5
- VERSION = "0.1.14"
5
+ VERSION = "0.1.16"
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  module QodexRails
2
2
  class Configuration
3
- attr_accessor :collection_name, :api_key, :allowed_environments, :frequency, :api_host
3
+ attr_accessor :collection_name, :api_key, :allowed_environments,
4
+ :frequency, :api_host, :pii_masking
4
5
 
5
6
  def initialize
6
7
  @collection_name = nil
@@ -8,6 +9,7 @@ module QodexRails
8
9
  @allowed_environments = ['staging']
9
10
  @frequency = 'medium'
10
11
  @api_host = nil
12
+ @pii_masking = nil
11
13
  end
12
14
  end
13
15
  end
@@ -0,0 +1,44 @@
1
+ module MaskingUtil
2
+ extend self
3
+
4
+ def mask_data(data, pii_masking)
5
+ return data if pii_masking.blank?
6
+
7
+ # Base case: If data is not a hash or array, return it as is
8
+ return data unless data.is_a?(Hash) || data.is_a?(Array)
9
+
10
+ # If the data is an array, apply the function recursively to each element
11
+ if data.is_a?(Array)
12
+ return data.map { |value| MaskingUtil.mask_data(value, pii_masking) }
13
+ end
14
+
15
+ # If the data is a hash, transform each value
16
+ data.transform_keys! { |k| k.to_s.downcase } # Convert keys to downcase for case-insensitive comparison
17
+ data.each do |key, value|
18
+ if pii_masking.include?(key.downcase) # Check if the key matches PII fields (case-insensitive)
19
+ data[key] = 'MASKED_' + '{{' + key + '}}' # Mask the value
20
+ elsif value.is_a?(Hash) || value.is_a?(Array)
21
+ data[key] = MaskingUtil.mask_data(value, pii_masking) # Recurse for nested hashes or arrays
22
+ end
23
+ end
24
+ end
25
+
26
+ def mask_query_params(url, pii_masking)
27
+ return url if pii_masking.blank?
28
+ uri = URI.parse(url)
29
+ query_params = CGI.parse(uri.query || '') # Parse query params into a hash
30
+
31
+ # Mask sensitive query params
32
+ query_params.each do |key, values|
33
+ if pii_masking.include?(key.downcase) # Check if key matches PII fields (case-insensitive)
34
+ query_params[key] = ['{{' + 'MASKED_' + key + '}}'] # Replace value with 'XXXX'
35
+ end
36
+ end
37
+
38
+ # Reconstruct the query string with masked values
39
+ uri.query = URI.encode_www_form(query_params)
40
+
41
+ uri.to_s # Return the new URL with masked query params
42
+ end
43
+
44
+ end
@@ -11,6 +11,10 @@ module QodexRails
11
11
  @frequency = QodexRails.configuration.frequency || 'low'
12
12
  end
13
13
 
14
+ def pii_masking
15
+ @pii_masking ||= QodexRails.configuration.pii_masking
16
+ end
17
+
14
18
  def call(env)
15
19
 
16
20
  # Check if the current environment is allowed
@@ -60,6 +64,17 @@ module QodexRails
60
64
  action_name = parsed_route_info[:action]
61
65
  additional_info = parsed_route_info.except(:controller, :action)
62
66
 
67
+ request_headers = extract_request_headers(env)
68
+ response_headers = extract_headers(headers)
69
+ request_params = request.params.merge(additional_info)
70
+
71
+ request_headers = MaskingUtil.mask_data(request_headers, pii_masking)
72
+ response_headers = MaskingUtil.mask_data(response_headers, pii_masking)
73
+ request_params = MaskingUtil.mask_data(request_params, pii_masking)
74
+ response_body = MaskingUtil.mask_data(response_body, pii_masking)
75
+ request_body = MaskingUtil.mask_data(request_body, pii_masking)
76
+ request_url = MaskingUtil.mask_query_params(request.url, pii_masking)
77
+
63
78
  # Construct the logs
64
79
  logs = {
65
80
  collection_name: QodexRails.configuration.collection_name,
@@ -73,11 +88,11 @@ module QodexRails
73
88
  body_type: 'none-type',
74
89
  request_type: request.request_method,
75
90
  timestamp: Time.now.to_i,
76
- url: request.url,
91
+ url: request_url,
77
92
  status: status,
78
- headers: extract_request_headers(env),
79
- response_headers: extract_headers(headers),
80
- params: request.params.merge(additional_info) # Using Rails' parameter filtering
93
+ headers: request_headers,
94
+ response_headers: response_headers,
95
+ params: request_params # Using Rails' parameter filtering
81
96
  }
82
97
  }
83
98
 
@@ -1,3 +1,3 @@
1
1
  module QodexRails
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.16"
3
3
  end
data/lib/qodex-rails.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "qodex-rails/version"
2
+ require "qodex-rails/masking_util"
2
3
  require "qodex-rails/middleware"
3
4
  require "qodex-rails/configuration" # Require the new configuration file
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qodex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - sid
@@ -26,6 +26,7 @@ files:
26
26
  - Rakefile
27
27
  - lib/qodex-rails.rb
28
28
  - lib/qodex-rails/configuration.rb
29
+ - lib/qodex-rails/masking_util.rb
29
30
  - lib/qodex-rails/middleware.rb
30
31
  - lib/qodex-rails/version.rb
31
32
  - lib/qodex/rails.rb