logical_model 0.2.15 → 0.2.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,13 +53,6 @@ In your Gemfile:
53
53
 
54
54
  == Testing
55
55
 
56
- For runnings specs you must have the service running locally. Do like this:
57
-
58
- ruby service.rb -p 3000 -e test
59
-
60
- Also note that after a single run of the tests the server must be restarted to reset
61
- the database. We could change this by deleting all users in the test setup.
62
-
63
56
  To run spec:
64
57
 
65
58
  bundle exec rspec spec/client_spec.rb --color
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.15
1
+ 0.2.16
@@ -4,6 +4,7 @@ require 'typhoeus'
4
4
  require 'active_support/all' # todo migrate to yajl
5
5
  require 'logger'
6
6
  require 'kaminari'
7
+ require 'safe_log'
7
8
 
8
9
  # Logical Model, not persistant on DB, works through API. (replaces ActiveResource)
9
10
  #
@@ -41,6 +42,8 @@ require 'kaminari'
41
42
  # RemoteResource#destroy
42
43
  class LogicalModel
43
44
 
45
+ extend SafeLog
46
+
44
47
  # include ActiveModel Modules that are usefull
45
48
  extend ActiveModel::Naming
46
49
  include ActiveModel::Conversion
@@ -198,7 +201,7 @@ class LogicalModel
198
201
  end
199
202
 
200
203
  def self.log_ok(response)
201
- self.logger.info("LogicalModel Log: #{response.code} #{response.request.url} in #{response.time}s")
204
+ self.logger.info("LogicalModel Log: #{response.code} #{mask_api_key(response.request.url)} in #{response.time}s")
202
205
  self.logger.debug("LogicalModel Log RESPONSE: #{response.body}")
203
206
  end
204
207
 
@@ -212,7 +215,7 @@ class LogicalModel
212
215
  rescue => e
213
216
  error_message = "error"
214
217
  end
215
- msg = "LogicalModel Log: #{response.code} #{response.request.url} in #{response.time}s FAILED: #{error_message}"
218
+ msg = "LogicalModel Log: #{response.code} #{mask_api_key(response.request.url)} in #{response.time}s FAILED: #{error_message}"
216
219
  self.logger.warn(msg)
217
220
  self.logger.debug("LogicalModel Log RESPONSE: #{response.body}")
218
221
  end
@@ -0,0 +1,11 @@
1
+ module SafeLog
2
+
3
+ # Filters api_key
4
+ # @return [String]
5
+ def mask_api_key(str)
6
+ if use_api_key
7
+ str = str.gsub(api_key,'[SECRET]')
8
+ end
9
+ str
10
+ end
11
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "logical_model"
8
- s.version = "0.2.15"
8
+ s.version = "0.2.16"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dwayne Macgowan"]
12
- s.date = "2012-01-26"
12
+ s.date = "2012-07-14"
13
13
  s.description = "LogicalModel allows to use a resource as a model. It is based on web presentation http://www.slideshare.net/ihower/serviceoriented-design-and-implement-with-rails3"
14
14
  s.email = "dwaynemac@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "db/development.sqlite3",
33
33
  "db/migrate/001_create_users.rb",
34
34
  "lib/logical_model.rb",
35
+ "lib/safe_log.rb",
35
36
  "logical_model.gemspec",
36
37
  "models/user.rb",
37
38
  "service.rb",
@@ -44,7 +45,7 @@ Gem::Specification.new do |s|
44
45
  s.homepage = "http://github.com/dwaynemac/logical_model"
45
46
  s.licenses = ["MIT"]
46
47
  s.require_paths = ["lib"]
47
- s.rubygems_version = "1.8.10"
48
+ s.rubygems_version = "1.8.24"
48
49
  s.summary = "LogicalModel allows to use a resource as a model."
49
50
 
50
51
  if s.respond_to? :specification_version then
@@ -89,6 +89,45 @@ describe "LogicalModel User client" do
89
89
  end
90
90
  end
91
91
 
92
+ describe "use_api_key" do
93
+ context "when true" do
94
+ before(:each) do
95
+ class User < LogicalModel; self.use_api_key=true; self.api_key_name='keyname'; self.api_key="secret_api_key"; end
96
+ end
97
+ it "should send api key in requests" do
98
+ Typhoeus::Request.should_receive(:new).with(User.resource_uri(1),{:params=>{'keyname'=>'secret_api_key'}})
99
+ begin
100
+ User.find(1)
101
+ rescue
102
+ end
103
+ end
104
+ it "should mask api key in logs" do
105
+ response = mock(
106
+ code: 200,
107
+ body: {}.to_json,
108
+ request: mock(url: "server?keyname=secret_api_key"),
109
+ time: 1234
110
+ )
111
+ Logger.any_instance.should_receive(:info).with(/\[SECRET\]/)
112
+ User.log_ok(response)
113
+ Logger.any_instance.should_receive(:warn).with(/\[SECRET\]/)
114
+ User.log_failed(response)
115
+ end
116
+ end
117
+ context "when false" do
118
+ before(:each) do
119
+ class User < LogicalModel; self.use_api_key=false; self.api_key_name='keyname'; self.api_key="secret_api_key"; end
120
+ end
121
+ it "should not send api key in requests" do
122
+ Typhoeus::Request.should_not_receive(:new).with(User.resource_uri(1),{:params=>{'keyname'=>'secret_api_key'}})
123
+ begin
124
+ User.find(1)
125
+ rescue
126
+ end
127
+ end
128
+ end
129
+ end
130
+
92
131
  describe "#https" do
93
132
  context "when use_ssl is tue" do
94
133
  before(:each) do
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.2.15
4
+ version: 0.2.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000Z
12
+ date: 2012-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &74451060 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74451060
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activesupport
27
- requirement: &74450420 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *74450420
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: typhoeus
38
- requirement: &74449870 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: 0.2.4
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *74449870
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.4
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: kaminari
49
- requirement: &74449280 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: 0.13.0
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *74449280
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.13.0
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: activerecord
60
- requirement: &74448640 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *74448640
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: shoulda
71
- requirement: &74448040 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *74448040
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: bundler
82
- requirement: &74447280 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ~>
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: 1.0.10
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *74447280
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.0.10
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: jeweler
93
- requirement: &74446520 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ~>
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: 1.6.4
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *74446520
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.6.4
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: rcov
104
- requirement: &74445870 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *74445870
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: sqlite3-ruby
115
- requirement: &74445300 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,10 +165,15 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *74445300
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  - !ruby/object:Gem::Dependency
125
175
  name: sinatra
126
- requirement: &74414950 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
127
177
  none: false
128
178
  requirements:
129
179
  - - ~>
@@ -131,10 +181,15 @@ dependencies:
131
181
  version: 1.2.6
132
182
  type: :development
133
183
  prerelease: false
134
- version_requirements: *74414950
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ~>
188
+ - !ruby/object:Gem::Version
189
+ version: 1.2.6
135
190
  - !ruby/object:Gem::Dependency
136
191
  name: json
137
- requirement: &74413470 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
138
193
  none: false
139
194
  requirements:
140
195
  - - ! '>='
@@ -142,10 +197,15 @@ dependencies:
142
197
  version: '0'
143
198
  type: :development
144
199
  prerelease: false
145
- version_requirements: *74413470
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
146
206
  - !ruby/object:Gem::Dependency
147
207
  name: rspec-rails
148
- requirement: &74412580 !ruby/object:Gem::Requirement
208
+ requirement: !ruby/object:Gem::Requirement
149
209
  none: false
150
210
  requirements:
151
211
  - - ! '>='
@@ -153,10 +213,15 @@ dependencies:
153
213
  version: '0'
154
214
  type: :development
155
215
  prerelease: false
156
- version_requirements: *74412580
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ none: false
218
+ requirements:
219
+ - - ! '>='
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
157
222
  - !ruby/object:Gem::Dependency
158
223
  name: guard-rspec
159
- requirement: &74412060 !ruby/object:Gem::Requirement
224
+ requirement: !ruby/object:Gem::Requirement
160
225
  none: false
161
226
  requirements:
162
227
  - - ! '>='
@@ -164,10 +229,15 @@ dependencies:
164
229
  version: '0'
165
230
  type: :development
166
231
  prerelease: false
167
- version_requirements: *74412060
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ none: false
234
+ requirements:
235
+ - - ! '>='
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
168
238
  - !ruby/object:Gem::Dependency
169
239
  name: rb-inotify
170
- requirement: &74411420 !ruby/object:Gem::Requirement
240
+ requirement: !ruby/object:Gem::Requirement
171
241
  none: false
172
242
  requirements:
173
243
  - - ! '>='
@@ -175,10 +245,15 @@ dependencies:
175
245
  version: '0'
176
246
  type: :development
177
247
  prerelease: false
178
- version_requirements: *74411420
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
179
254
  - !ruby/object:Gem::Dependency
180
255
  name: libnotify
181
- requirement: &74410840 !ruby/object:Gem::Requirement
256
+ requirement: !ruby/object:Gem::Requirement
182
257
  none: false
183
258
  requirements:
184
259
  - - ! '>='
@@ -186,7 +261,12 @@ dependencies:
186
261
  version: '0'
187
262
  type: :development
188
263
  prerelease: false
189
- version_requirements: *74410840
264
+ version_requirements: !ruby/object:Gem::Requirement
265
+ none: false
266
+ requirements:
267
+ - - ! '>='
268
+ - !ruby/object:Gem::Version
269
+ version: '0'
190
270
  description: LogicalModel allows to use a resource as a model. It is based on web
191
271
  presentation http://www.slideshare.net/ihower/serviceoriented-design-and-implement-with-rails3
192
272
  email: dwaynemac@gmail.com
@@ -211,6 +291,7 @@ files:
211
291
  - db/development.sqlite3
212
292
  - db/migrate/001_create_users.rb
213
293
  - lib/logical_model.rb
294
+ - lib/safe_log.rb
214
295
  - logical_model.gemspec
215
296
  - models/user.rb
216
297
  - service.rb
@@ -234,7 +315,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
315
  version: '0'
235
316
  segments:
236
317
  - 0
237
- hash: -931436209
318
+ hash: 630634381
238
319
  required_rubygems_version: !ruby/object:Gem::Requirement
239
320
  none: false
240
321
  requirements:
@@ -243,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
324
  version: '0'
244
325
  requirements: []
245
326
  rubyforge_project:
246
- rubygems_version: 1.8.10
327
+ rubygems_version: 1.8.24
247
328
  signing_key:
248
329
  specification_version: 3
249
330
  summary: LogicalModel allows to use a resource as a model.