logical_model 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c54ee15e0413bd22ec9565523d2c9717913acc6475dbb65c0a130fb8b74cb1b
4
- data.tar.gz: e74b18396a817b26aef40359788048e5a58c78c71cd43c2ad0de44cca6626b6c
3
+ metadata.gz: 4427e8262cf667f4e97829c6879dbd70a6ad77286d920b7efa7c12a814d7ded5
4
+ data.tar.gz: 874f8ffc549cf80e745801e1b974529193c5b9749e45767c43697014fb472a6c
5
5
  SHA512:
6
- metadata.gz: 92209ab1bf6f806bf873cba8baa7e56753e0ddf68d7fcec333760e622b180f868dbdfaa47beae8b7b535aa39dc7b8ed23b6882e1a02147c671480063d144377a
7
- data.tar.gz: 28693c7d61c83359dd9fbfe6b9056f74a86f4aeac28bc4913656bfb78404243db76d5dc45050326a6a32a77ee8c34ea85ca3217e41b0c84972ecbf61ba14701d
6
+ metadata.gz: d92b9520a346e124e09e6449c27ab1003cd14c05345c86b025719dda4e8a4cacf649dab9c3083e4e2d1b5b85868a7a8daaa2b22050454a58472d79d535bc1829
7
+ data.tar.gz: 136c046e39c0c8f70e7e80af9eda65ce895b8a704a43eadc6b4412d35c446960140128cfdb3b70ffac8eeef88e6a484d7dba8d7c438cc4418913252f27046beb
data/Gemfile.lock CHANGED
@@ -33,14 +33,14 @@ GEM
33
33
  crass (1.0.6)
34
34
  diff-lcs (1.1.3)
35
35
  erubis (2.7.0)
36
- ethon (0.6.3)
37
- ffi (>= 1.3.0)
38
- mime-types (~> 1.18)
36
+ ethon (0.16.0)
37
+ ffi (>= 1.15.0)
39
38
  ffi (1.15.4)
40
39
  formatador (0.3.0)
41
40
  gemcutter (0.7.1)
42
41
  git (1.9.1)
43
42
  rchardet (~> 1.8)
43
+ growl (1.0.3)
44
44
  guard (2.18.0)
45
45
  formatador (>= 0.2.4)
46
46
  listen (>= 2.7, < 4.0)
@@ -72,8 +72,6 @@ GEM
72
72
  activerecord
73
73
  kaminari-core (= 1.2.1)
74
74
  kaminari-core (1.2.1)
75
- libnotify (0.9.4)
76
- ffi (>= 1.0.11)
77
75
  listen (3.7.0)
78
76
  rb-fsevent (~> 0.10, >= 0.10.3)
79
77
  rb-inotify (~> 0.9, >= 0.9.10)
@@ -82,7 +80,6 @@ GEM
82
80
  nokogiri (>= 1.5.9)
83
81
  lumberjack (1.2.8)
84
82
  method_source (1.0.0)
85
- mime-types (1.25.1)
86
83
  mini_portile2 (2.6.1)
87
84
  minitest (5.14.4)
88
85
  nenv (0.3.0)
@@ -144,8 +141,8 @@ GEM
144
141
  thor (1.1.0)
145
142
  thread_safe (0.3.6)
146
143
  tilt (1.4.1)
147
- typhoeus (0.6.4)
148
- ethon (~> 0.6.0)
144
+ typhoeus (1.4.1)
145
+ ethon (>= 0.9.0)
149
146
  tzinfo (1.2.9)
150
147
  thread_safe (~> 0.1)
151
148
 
@@ -157,20 +154,20 @@ DEPENDENCIES
157
154
  activerecord
158
155
  activesupport (= 4.2.11.3)
159
156
  bundler (>= 1.2.2)
160
- ethon (= 0.6.3)
157
+ ethon (>= 0.8.0)
161
158
  gemcutter
159
+ growl
162
160
  guard-rspec
163
161
  jeweler (~> 1.6.4)
164
162
  json (= 2.0.0)
165
163
  kaminari (~> 1.2.1)
166
- libnotify
167
164
  rake
168
- rb-inotify
165
+ rb-fsevent
169
166
  rspec-rails (= 2.11.0)
170
167
  shoulda
171
168
  sinatra (~> 1.2.6)
172
169
  sqlite3
173
- typhoeus (= 0.6.4)
170
+ typhoeus (>= 1.0.1)
174
171
 
175
172
  BUNDLED WITH
176
173
  1.17.2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.6
1
+ 0.6.4
@@ -2,6 +2,7 @@ require 'logger'
2
2
 
3
3
  class LogicalModel
4
4
  module SafeLog
5
+ SECRET_PLACEHOLDER = "[SECRET]"
5
6
 
6
7
  def self.included(base)
7
8
  base.send(:include, InstanceMethods)
@@ -17,6 +18,9 @@ class LogicalModel
17
18
  self.class.log_failed(response)
18
19
  end
19
20
 
21
+ def sensitive_attributes
22
+ self.class.sensitive_attributes
23
+ end
20
24
  end
21
25
 
22
26
  module ClassMethods
@@ -27,8 +31,8 @@ class LogicalModel
27
31
  end
28
32
 
29
33
  def log_ok(response)
30
- self.logger.info("LogicalModel Log: #{response.code} #{mask_api_key(response.effective_url)} in #{response.time}s")
31
- self.logger.debug("LogicalModel Log RESPONSE: #{response.body}")
34
+ self.logger.info { "LogicalModel Log: #{response.code} #{mask_api_key(response.effective_url)} in #{response.time}s" }
35
+ self.logger.debug { "LogicalModel Log RESPONSE: #{safe_body(response.body)}" }
32
36
  end
33
37
 
34
38
  def log_failed(response)
@@ -38,8 +42,8 @@ class LogicalModel
38
42
  error_message = "error"
39
43
  end
40
44
  msg = "LogicalModel Log: #{response.code} #{mask_api_key(response.effective_url)} in #{response.time}s FAILED: #{error_message}"
41
- self.logger.warn(msg)
42
- self.logger.debug("LogicalModel Log RESPONSE: #{response.body}")
45
+ self.logger.warn { msg }
46
+ self.logger.debug { "LogicalModel Log RESPONSE: #{safe_body(response.body)}" }
43
47
  end
44
48
 
45
49
  def logger
@@ -54,11 +58,54 @@ class LogicalModel
54
58
  @logger
55
59
  end
56
60
 
61
+ # declares an attribute that is sensitive and should be masked in logs
62
+ # si no se llamó antes a attribute, lo declara
63
+ # @param name [Symbol]
64
+ # @example
65
+ # class Client < LogicalModel
66
+ # sensitive_attribute :att_name
67
+ # end
68
+ def sensitive_attribute(name)
69
+ if attribute_keys.blank? || !attribute_keys.include?(name)
70
+ attribute(name)
71
+ end
72
+ @sensitive_attributes ||= []
73
+ @sensitive_attributes << name
74
+ end
75
+
76
+ def sensitive_attributes
77
+ @sensitive_attributes || []
78
+ end
79
+
80
+ def safe_body(body)
81
+ parsed_response = ActiveSupport::JSON.decode(body)
82
+ mask_sensitive_attributes(parsed_response).to_json
83
+ rescue => e
84
+ body
85
+ end
86
+
87
+ def mask_sensitive_attributes(parsed_response)
88
+ if parsed_response.is_a?(Hash)
89
+ parsed_response.each do |k,v|
90
+ if sensitive_attributes.include?(k.to_sym)
91
+ parsed_response[k] = SECRET_PLACEHOLDER
92
+ else
93
+ parsed_response[k] = mask_sensitive_attributes(v)
94
+ end
95
+ end
96
+ elsif parsed_response.is_a?(Array)
97
+ parsed_response.map! do |v|
98
+ mask_sensitive_attributes(v)
99
+ end
100
+ end
101
+ parsed_response
102
+ end
103
+
57
104
  # Filters api_key
58
105
  # @return [String]
59
106
  def mask_api_key(str)
60
107
  if use_api_key && str
61
- str = str.gsub(api_key,'[SECRET]')
108
+ str = str.gsub(api_key,SECRET_PLACEHOLDER)
62
109
  end
63
110
  str
64
111
  end
@@ -0,0 +1,15 @@
1
+ W, [2024-06-06T13:45:05.954491 #69121] WARN -- : LogicalModel Log: 0 http://destroy_multiple/?ids%5B0%5D=id1&ids%5B1%5D=id2 in 0.01899s FAILED: error
2
+ D, [2024-06-06T13:45:05.954740 #69121] DEBUG -- : LogicalModel Log RESPONSE:
3
+ I, [2024-06-06T13:51:04.646626 #70013] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
4
+ D, [2024-06-06T13:51:04.646936 #70013] DEBUG -- : LogicalModel Log RESPONSE: body
5
+ I, [2024-06-06T13:53:22.229744 #70419] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
6
+ D, [2024-06-06T13:53:22.230036 #70419] DEBUG -- : LogicalModel Log RESPONSE: body
7
+ I, [2024-06-06T13:53:48.955991 #70594] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
8
+ D, [2024-06-06T13:53:48.956253 #70594] DEBUG -- : LogicalModel Log RESPONSE: body
9
+ I, [2024-06-06T13:53:48.957211 #70594] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
10
+ I, [2024-06-06T13:54:12.318915 #70730] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
11
+ D, [2024-06-06T13:54:12.319229 #70730] DEBUG -- : LogicalModel Log RESPONSE: body
12
+ I, [2024-06-06T13:54:42.959026 #70876] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
13
+ D, [2024-06-06T13:54:42.959341 #70876] DEBUG -- : LogicalModel Log RESPONSE: body
14
+ I, [2024-06-06T13:57:20.038745 #71936] INFO -- : LogicalModel Log: 200 http://example.com in 0.5s
15
+ D, [2024-06-06T13:57:20.039070 #71936] DEBUG -- : LogicalModel Log RESPONSE: body
@@ -6,7 +6,7 @@
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "logical_model"
9
- s.version = "0.7.5"
9
+ s.version = "0.7.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logical_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dwayne Macgowan
@@ -301,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
301
  - !ruby/object:Gem::Version
302
302
  version: '0'
303
303
  requirements: []
304
- rubygems_version: 3.3.7
304
+ rubygems_version: 3.0.1
305
305
  signing_key:
306
306
  specification_version: 4
307
307
  summary: LogicalModel allows to use a resource as a model.