vigilion-rails 1.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +33 -0
- data/app/controllers/vigilion/vigilion_controller.rb +21 -0
- data/config/routes.rb +3 -0
- data/lib/generators/vigilion/install_generator.rb +22 -0
- data/lib/generators/vigilion/scan/USAGE +7 -0
- data/lib/generators/vigilion/scan/scan_generator.rb +20 -0
- data/lib/generators/vigilion/scan/templates/add_scan_results_columns.rb.erb +5 -0
- data/lib/tasks/vigilion.rake +12 -0
- data/lib/vigilion-rails.rb +55 -0
- data/lib/vigilion-rails/configuration.rb +13 -0
- data/lib/vigilion-rails/engine.rb +10 -0
- data/lib/vigilion-rails/integrations/local_integration.rb +7 -0
- data/lib/vigilion-rails/integrations/url_integration.rb +7 -0
- data/lib/vigilion-rails/version.rb +3 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/agnostic_document.rb +7 -0
- data/spec/dummy/app/models/carrierwave_document.rb +4 -0
- data/spec/dummy/app/models/dragonfly_document.rb +4 -0
- data/spec/dummy/app/models/paperclip_document.rb +4 -0
- data/spec/dummy/app/uploaders/attachment_uploader.rb +50 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20150616144220_create_carrierwave_documents.rb +8 -0
- data/spec/dummy/db/migrate/20150616144227_create_paperclip_documents.rb +8 -0
- data/spec/dummy/db/migrate/20150616144235_create_dragonfly_documents.rb +8 -0
- data/spec/dummy/db/migrate/20150616144544_create_agnostic_documents.rb +8 -0
- data/spec/dummy/db/schema.rb +61 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helper_methods.rb +11 -0
- data/spec/lib/integrations/local_integration_spec.rb +13 -0
- data/spec/lib/vigilion_rails_spec.rb +122 -0
- data/spec/routing/vigilion_routing_spec.rb +9 -0
- data/spec/spec_helper.rb +87 -0
- data/spec/vigilion_rails_helper.rb +34 -0
- metadata +229 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 01e901bc9f20315c84b9cbbb0b6c71ed82fc4ab8
|
4
|
+
data.tar.gz: b5c38585a91c7da6c76de2456c4654f3023b900c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 388400a8bc15441dfc68415f24dafb069c9e736514f5b5e4e9ba4d1a21abece700e66aeaf527185fa3cfff98de7e411252550f9f699a3fe11f84a4cf8039c3d4
|
7
|
+
data.tar.gz: 310542b30ee4d339a470e0c9fec30dbbc28b793d1bda9ac3d89c30449114d33c10f41c309631fcde9fe48a4895aa824271259e8ff59ef549cf8f9fbf5c19d6a8
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Bit Zesty Ltd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
require "rdoc/task"
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = "rdoc"
|
11
|
+
rdoc.title = "VigilionRails"
|
12
|
+
rdoc.options << "--line-numbers"
|
13
|
+
rdoc.rdoc_files.include("README.rdoc")
|
14
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load "rails/tasks/engine.rake"
|
19
|
+
|
20
|
+
load "rails/tasks/statistics.rake"
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require "rake/testtask"
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << "lib"
|
28
|
+
t.libs << "test"
|
29
|
+
t.pattern = "test/**/*_test.rb"
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Vigilion::VigilionController < ActionController::Base
|
2
|
+
skip_before_filter :verify_authenticity_token
|
3
|
+
before_action :verify_api_auth
|
4
|
+
|
5
|
+
def callback
|
6
|
+
identity = JSON.parse(params[:key])
|
7
|
+
model = identity["model"].constantize.find(identity["id"])
|
8
|
+
on_scan = "on_scan_#{identity["column"]}"
|
9
|
+
if model.present? && model.respond_to?(on_scan)
|
10
|
+
model.send(on_scan, params)
|
11
|
+
end
|
12
|
+
head :ok
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def verify_api_auth
|
17
|
+
unless Vigilion::HTTP.digest(request.raw_post) == request.headers["X-Request-Signature"]
|
18
|
+
render json: { message: "unauthorized" }, status: 401
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class Vigilion::InstallGenerator < Rails::Generators::Base
|
2
|
+
def create_initializer_file
|
3
|
+
create_file "config/initializers/vigilion.rb", <<INITIALIZER
|
4
|
+
Vigilion.configure do |config|
|
5
|
+
config.access_key_id = ENV["VIGILION_ACCESS_KEY_ID"]
|
6
|
+
config.secret_access_key = ENV["VIGILION_SECRET_ACCESS_KEY"]
|
7
|
+
|
8
|
+
# Integration strategy (default is :url)
|
9
|
+
# config.integration = :local
|
10
|
+
|
11
|
+
# By default vigilion will be bypassed in development and test environments.
|
12
|
+
# Disable vigilion scanning entirely even in production environments:
|
13
|
+
# config.loopback = true
|
14
|
+
# Enable vigilion scanning even in development and test environments:
|
15
|
+
# (Note that the callback URL probably won't be reached)
|
16
|
+
# config.loopback = false
|
17
|
+
# Specify different loopback_response (default is 'clean')
|
18
|
+
# config.loopback_response = 'infected'
|
19
|
+
end
|
20
|
+
INITIALIZER
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class Vigilion::ScanGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
argument :model_name, :type => :string
|
8
|
+
argument :attribute_name, :type => :string
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_model_file
|
15
|
+
@table_name = model_name.tableize
|
16
|
+
@column_name = "#{attribute_name}_scan_results"
|
17
|
+
@migration_name = "vigilion_scan_#{@table_name}_#{attribute_name}"
|
18
|
+
migration_template "add_scan_results_columns.rb.erb", "db/migrate/#{@migration_name}.rb"
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
namespace :vigilion do
|
2
|
+
desc "Ensure vigilion credentials are valid and can connect to the server"
|
3
|
+
task test: :environment do
|
4
|
+
project = Vigilion::HTTP.new.validate
|
5
|
+
|
6
|
+
puts "Credentials OK!"
|
7
|
+
puts " Project: #{project['name']}"
|
8
|
+
puts " Callback: #{project['callback_url']}"
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "vigilion-rails/engine"
|
2
|
+
require "vigilion-rails/integrations/url_integration"
|
3
|
+
require "vigilion-rails/integrations/local_integration"
|
4
|
+
require "vigilion-rails/configuration"
|
5
|
+
|
6
|
+
module VigilionRails
|
7
|
+
|
8
|
+
module ActiveRecord
|
9
|
+
def scan_file column, options={}
|
10
|
+
default = { scan_column: "#{column}_scan_results", integration: Vigilion::Configuration.integration }
|
11
|
+
options = default.merge(options)
|
12
|
+
integration_class = "VigilionRails::#{options[:integration].to_s.camelize}Integration"
|
13
|
+
class_eval <<-RUBY, __FILE__, __LINE__+1
|
14
|
+
|
15
|
+
def scan_#{column}!
|
16
|
+
key = { model: self.class.name, column: '#{column}', id: id }.to_json
|
17
|
+
|
18
|
+
if Vigilion::Configuration.loopback
|
19
|
+
logger.info 'vigilion scan request was simulated'
|
20
|
+
|
21
|
+
self.class.find(id).on_scan_#{column} status: Vigilion::Configuration.loopback_response
|
22
|
+
else
|
23
|
+
#{integration_class}.new.scan key, self, :#{column}
|
24
|
+
end
|
25
|
+
@#{column}_old_url = #{column}.url
|
26
|
+
return true
|
27
|
+
end
|
28
|
+
|
29
|
+
# Vigilion service callback
|
30
|
+
def on_scan_#{column} params
|
31
|
+
update_attribute('#{options[:scan_column]}', params[:status])
|
32
|
+
end
|
33
|
+
|
34
|
+
after_initialize :remember_#{column}_url
|
35
|
+
after_save :check_scan_#{column}
|
36
|
+
|
37
|
+
def remember_#{column}_url
|
38
|
+
@#{column}_old_url = #{column}.try(:url) unless new_record?
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_scan_#{column}
|
42
|
+
if @#{column}_old_url != #{column}.url
|
43
|
+
scan_#{column}!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def clean?
|
48
|
+
#{options[:scan_column]} == "clean"
|
49
|
+
end
|
50
|
+
RUBY
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
ActiveRecord::Base.extend VigilionRails::ActiveRecord
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module VigilionRails
|
2
|
+
class Configuration < Rails::Railtie
|
3
|
+
initializer "configuration.configure_default_values" do
|
4
|
+
# Sets default configuration.
|
5
|
+
# Please see https://github.com/vigilion/vigilion-ruby/blob/master/lib/vigilion/configuration.rb
|
6
|
+
Vigilion.configure do |config|
|
7
|
+
config.integration = :url
|
8
|
+
config.loopback = Rails.env.development? || Rails.env.test?
|
9
|
+
config.loopback_response = 'clean'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class AttachmentUploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
# include CarrierWave::RMagick
|
7
|
+
# include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Choose what kind of storage to use for this uploader:
|
10
|
+
# storage :fog
|
11
|
+
|
12
|
+
# Override the directory where uploaded files will be stored.
|
13
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
14
|
+
def store_dir
|
15
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
19
|
+
# def default_url
|
20
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
21
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
22
|
+
#
|
23
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Process files as they are uploaded:
|
27
|
+
# process :scale => [200, 300]
|
28
|
+
#
|
29
|
+
# def scale(width, height)
|
30
|
+
# # do something
|
31
|
+
# end
|
32
|
+
|
33
|
+
# Create different versions of your uploaded files:
|
34
|
+
# version :thumb do
|
35
|
+
# process :resize_to_fit => [50, 50]
|
36
|
+
# end
|
37
|
+
|
38
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
39
|
+
# For images you might use something like this:
|
40
|
+
# def extension_white_list
|
41
|
+
# %w(jpg jpeg gif png)
|
42
|
+
# end
|
43
|
+
|
44
|
+
# Override the filename of the uploaded files:
|
45
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
46
|
+
# def filename
|
47
|
+
# "something.jpg" if original_filename
|
48
|
+
# end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|