witch_doctor 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -3
- data/app/controllers/witch_doctor/virus_scans_controller.rb +8 -2
- data/app/models/virus_scan.rb +1 -39
- data/app/models/witch_doctor/virus_scan.rb +33 -0
- data/app/permiterters/virus_scan_permitter.rb +1 -1
- data/lib/witch_doctor/antivirus_concern.rb +5 -1
- data/lib/witch_doctor/version.rb +1 -1
- data/lib/witch_doctor.rb +11 -1
- data/spec/dummy/config/initializers/witch_doctor.rb +1 -1
- data/spec/dummy/log/development.log +2 -0
- data/spec/dummy/log/test.log +13247 -0
- data/spec/models/virus_scan_spec.rb +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a6d2446df132b40062054df4cefaa444b038a2
|
4
|
+
data.tar.gz: 7a73956f5b7ec02a248628b5d2189297d7637854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bdcbfc8f4ad8ef68d392f243ea1d7a9e58ddd2d938a46ba276cf01fb24507386463860b813206791343fd7f8d1667fc7996d8fb773fe687a91e8bfb93d324c1
|
7
|
+
data.tar.gz: 06078977ef998a31963d69287397148eea095d5ec014fc8b06c50daffbed48ce23b172a2aa218b129e1d9fdc8a162a502cd7b68d61af0be9ab7abf7f6e8cda3a
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ end
|
|
53
53
|
```ruby
|
54
54
|
# /config/initializers/witch_doctor.rb
|
55
55
|
|
56
|
-
|
56
|
+
WitchDoctor.token = Rails
|
57
57
|
.application
|
58
58
|
.secrets
|
59
59
|
.fetch('antivirus_scan')
|
@@ -125,8 +125,33 @@ end
|
|
125
125
|
|
126
126
|
# Testing
|
127
127
|
|
128
|
-
|
129
|
-
|
128
|
+
Make sure you turn of `virus_scan_scheduling_on` option so that gem wont
|
129
|
+
create extra records when your tests are running
|
130
|
+
|
131
|
+
```
|
132
|
+
# config/initializers/witch_doctor.rb
|
133
|
+
WitchDoctor.skip_virus_scan_scheduling = true
|
134
|
+
```
|
135
|
+
|
136
|
+
turn it on only when needed
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# spec/request/virus_scan.rb
|
140
|
+
|
141
|
+
# ...
|
142
|
+
before do
|
143
|
+
WitchDoctor.skip_virus_scan_scheduling = false
|
144
|
+
end
|
145
|
+
|
146
|
+
after do
|
147
|
+
WitchDoctor.skip_virus_scan_scheduling = true
|
148
|
+
end
|
149
|
+
|
150
|
+
# ...
|
151
|
+
```
|
152
|
+
|
153
|
+
The gem/engine is pretty well tested but I recomend to write
|
154
|
+
interation test for every application it is introduced to.
|
130
155
|
|
131
156
|
Example with RSpec request test:
|
132
157
|
|
@@ -53,7 +53,7 @@ module WitchDoctor
|
|
53
53
|
def authenticate!
|
54
54
|
if provided_token == nil
|
55
55
|
render json: { errors: { request: ['Not Authenticated'] } }, status: 401
|
56
|
-
elsif provided_token.to_s ==
|
56
|
+
elsif provided_token.to_s == WitchDoctor.token
|
57
57
|
yield
|
58
58
|
else
|
59
59
|
render json: { errors: { request: ['Not Authorized'] } }, status: 403
|
@@ -61,12 +61,18 @@ module WitchDoctor
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def provided_token
|
64
|
-
|
64
|
+
authorization
|
65
65
|
.to_s
|
66
66
|
.match(/Token\s+(.*)/) { |m| m[1] } \
|
67
67
|
|| params[:token]
|
68
68
|
end
|
69
69
|
|
70
|
+
def authorization
|
71
|
+
(rails4 = request.headers['HTTP_AUTHORIZATION']) \
|
72
|
+
|| (rails3 = request.headers['Authorization']) \
|
73
|
+
|| (rspec = request.headers['rack.session']['Authorization'])
|
74
|
+
end
|
75
|
+
|
70
76
|
def virus_scan_params
|
71
77
|
VirusScanPermitter.new.attributes(params)
|
72
78
|
end
|
data/app/models/virus_scan.rb
CHANGED
@@ -1,39 +1 @@
|
|
1
|
-
|
2
|
-
TokenNotSpecified = Class.new(StandardError)
|
3
|
-
|
4
|
-
class << self
|
5
|
-
attr_writer :token
|
6
|
-
|
7
|
-
def token
|
8
|
-
@token || raise(TokenNotSpecified)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
belongs_to :resource, polymorphic: true
|
13
|
-
scope :not_scanned, -> { where scan_result: nil }
|
14
|
-
validates_inclusion_of :scan_result, in: WitchDoctor::Antivirus::RESULTS, allow_nil: true
|
15
|
-
|
16
|
-
before_update :set_scanned_at, if: :scan_updated?
|
17
|
-
|
18
|
-
def as_json(options={})
|
19
|
-
attributes
|
20
|
-
.slice('id', 'scan_result')
|
21
|
-
.tap { |hash|
|
22
|
-
hash.merge!('file_url' => file_url,
|
23
|
-
'scanned_at' => scanned_at.try(:utc).try(:iso8601))
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
# S3 will give url, file wil show mount point, we care just about s3
|
28
|
-
def file_url
|
29
|
-
resource.send(mount_point).url
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_scanned_at
|
33
|
-
self.scanned_at = WitchDoctor.time_stamper.call
|
34
|
-
end
|
35
|
-
|
36
|
-
def scan_updated?
|
37
|
-
scan_result.in? WitchDoctor::Antivirus::RESULTS
|
38
|
-
end
|
39
|
-
end
|
1
|
+
VirusScan = Class.new(WitchDoctor::VirusScan)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module WitchDoctor
|
2
|
+
class VirusScan < ActiveRecord::Base
|
3
|
+
self.table_name = "virus_scans"
|
4
|
+
|
5
|
+
belongs_to :resource, polymorphic: true
|
6
|
+
scope :not_scanned, -> { where scan_result: nil }
|
7
|
+
validates_inclusion_of :scan_result, in: WitchDoctor::Antivirus::RESULTS, allow_nil: true
|
8
|
+
|
9
|
+
before_update :set_scanned_at, if: :scan_updated?
|
10
|
+
|
11
|
+
def as_json(options={})
|
12
|
+
attributes
|
13
|
+
.slice('id', 'scan_result')
|
14
|
+
.tap { |hash|
|
15
|
+
hash.merge!('file_url' => file_url,
|
16
|
+
'scanned_at' => scanned_at.try(:utc).try(:iso8601))
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
# S3 will give url, file wil show mount point, we care just about s3
|
21
|
+
def file_url
|
22
|
+
resource.send(mount_point).url
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_scanned_at
|
26
|
+
self.scanned_at = WitchDoctor.time_stamper.call
|
27
|
+
end
|
28
|
+
|
29
|
+
def scan_updated?
|
30
|
+
scan_result.in? WitchDoctor::Antivirus::RESULTS
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -6,11 +6,15 @@ module WitchDoctor
|
|
6
6
|
has_many :virus_scans, as: :resource
|
7
7
|
end
|
8
8
|
|
9
|
+
def virus_scan_scheduling_on?
|
10
|
+
!WitchDoctor.skip_virus_scan_scheduling
|
11
|
+
end
|
12
|
+
|
9
13
|
module ClassMethods
|
10
14
|
def schedule_virus_scan(options)
|
11
15
|
mount_point = options.fetch(:on)
|
12
16
|
|
13
|
-
after_save "schedule_#{mount_point}_virus_scan", if: "schedule_#{mount_point}_virus_scan?"
|
17
|
+
after_save "schedule_#{mount_point}_virus_scan", if: ["schedule_#{mount_point}_virus_scan?", :virus_scan_scheduling_on?]
|
14
18
|
|
15
19
|
define_method("schedule_#{mount_point}_virus_scan") do
|
16
20
|
virus_scans.create! do |vs|
|
data/lib/witch_doctor/version.rb
CHANGED
data/lib/witch_doctor.rb
CHANGED
@@ -3,8 +3,10 @@ require "witch_doctor/antivirus"
|
|
3
3
|
require "witch_doctor/antivirus_concern"
|
4
4
|
|
5
5
|
module WitchDoctor
|
6
|
+
TokenNotSpecified = Class.new(StandardError)
|
7
|
+
|
6
8
|
class << self
|
7
|
-
attr_writer :time_stamper, :virus_scan_limit
|
9
|
+
attr_writer :time_stamper, :virus_scan_limit, :token, :skip_virus_scan_scheduling
|
8
10
|
|
9
11
|
def time_stamper
|
10
12
|
@time_stamper ||= -> { Time.now }
|
@@ -13,5 +15,13 @@ module WitchDoctor
|
|
13
15
|
def virus_scan_limit
|
14
16
|
@virus_scan_limit ||= 10
|
15
17
|
end
|
18
|
+
|
19
|
+
def token
|
20
|
+
@token || raise(TokenNotSpecified)
|
21
|
+
end
|
22
|
+
|
23
|
+
def skip_virus_scan_scheduling
|
24
|
+
!!@skip_virus_scan_scheduling
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
WitchDoctor.token = '1234'
|
@@ -279,3 +279,5 @@ Migrating to CreateWitchDoctorVirusScans (20150209121818)
|
|
279
279
|
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
280
280
|
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
281
281
|
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
282
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
283
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|