code_quality 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/code_quality.gemspec +30 -0
- data/lib/code_quality.rb +5 -0
- data/lib/code_quality/railtie.rb +5 -0
- data/lib/code_quality/version.rb +3 -0
- data/lib/tasks/code_quality.rake +105 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 37c28c316373313c706968fba46f52a023f20584
|
4
|
+
data.tar.gz: d6143f5b24da0776c272fa06b5a626976932b739
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: daed8fdb4a6ad0ce29c93c298f55735b7ec9a26a44c96e13c9f292371093739789dab4b4670c9edeffd599e25825f120c67fc3c2ca71b50da9f0c1c776cfde5c
|
7
|
+
data.tar.gz: ac3117746cec3a4bcf35be15c927aa369550609008e60bf4665dfbe6457cb04f68889bdad12da915b2137c8d8dcbac2b01442723db2b4c44b2a663837d8f9af5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 RainChen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# CodeQuality
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/code_quality`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'code_quality'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install code_quality
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/code_quality.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "code_quality"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "code_quality/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "code_quality"
|
8
|
+
spec.version = CodeQuality::VERSION
|
9
|
+
spec.authors = ["RainChen"]
|
10
|
+
spec.email = ["hirainchen@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{run code quality and security audit report with one rake task}
|
13
|
+
spec.description = %q{run code quality and security audit report with one rake task}
|
14
|
+
spec.homepage = "https://github.com/rainchen/code_quality"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "bundler-audit"
|
25
|
+
spec.add_dependency "brakeman"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
data/lib/code_quality.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
namespace :code_quality do
|
2
|
+
|
3
|
+
desc "security audit using bundler-audit, brakeman"
|
4
|
+
task :security_audit => [:"security_audit:default"] do; end
|
5
|
+
namespace :security_audit do
|
6
|
+
# default tasks
|
7
|
+
task :default => [:bundler_audit, :brakeman, :resources] do; end
|
8
|
+
|
9
|
+
# desc "prepare dir"
|
10
|
+
task :prepare => :helpers do
|
11
|
+
@report_dir = "tmp/code_quality/security_audit"
|
12
|
+
prepare_dir @report_dir
|
13
|
+
|
14
|
+
def report_dir
|
15
|
+
@report_dir
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "bundler audit"
|
20
|
+
task :bundler_audit => :prepare do
|
21
|
+
run_audit "bundler audit - checks for vulnerable versions of gems in Gemfile.lock" do
|
22
|
+
# Update the ruby-advisory-db and check Gemfile.lock
|
23
|
+
report = `bundle audit check --update`
|
24
|
+
File.open("#{report_dir}/bundler-audit-report.txt", 'w') {|f| f.write report }
|
25
|
+
puts report
|
26
|
+
audit_faild "Must fix vulnerabilities ASAP" unless report =~ /No vulnerabilities found/
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "brakeman"
|
31
|
+
task :brakeman => :prepare do
|
32
|
+
run_audit "Brakeman audit - checks Ruby on Rails applications for security vulnerabilities" do
|
33
|
+
`brakeman -o #{report_dir}/brakeman-report.txt -o #{report_dir}/brakeman-report.json`
|
34
|
+
puts `cat #{report_dir}/brakeman-report.txt`
|
35
|
+
report = JSON.parse(File.read("#{report_dir}/brakeman-report.json"))
|
36
|
+
audit_faild "There are #{report["errors"].size} errors, must fix them ASAP." if report["errors"].any?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# desc "resources url"
|
41
|
+
task :resources do
|
42
|
+
refs = %w{
|
43
|
+
https://github.com/presidentbeef/brakeman
|
44
|
+
https://github.com/rubysec/bundler-audit
|
45
|
+
http://guides.rubyonrails.org/security.html
|
46
|
+
https://github.com/hardhatdigital/rails-security-audit
|
47
|
+
https://hakiri.io/blog/ruby-security-tools-and-resources
|
48
|
+
https://www.netsparker.com/blog/web-security/ruby-on-rails-security-basics/
|
49
|
+
https://www.owasp.org/index.php/Ruby_on_Rails_Cheatsheet
|
50
|
+
}
|
51
|
+
puts "## Security Resources"
|
52
|
+
puts refs.map { |url| " - #{url}" }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# TODO: code quality audit
|
57
|
+
desc "code quality audit"
|
58
|
+
task :quality_audit => [:"quality_audit:default"] do; end
|
59
|
+
namespace :quality_audit do
|
60
|
+
# default tasks
|
61
|
+
task :default do
|
62
|
+
puts "PENDING"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# desc "helper methods"
|
67
|
+
task :helpers do
|
68
|
+
def run_audit(title, &block)
|
69
|
+
puts "## #{title}"
|
70
|
+
puts "", "```"
|
71
|
+
realtime(&block)
|
72
|
+
puts "```", ""
|
73
|
+
end
|
74
|
+
|
75
|
+
def realtime(&block)
|
76
|
+
realtime = Benchmark.realtime do
|
77
|
+
block.call
|
78
|
+
end.round
|
79
|
+
process_time = humanize_secs(realtime)
|
80
|
+
puts "[ #{process_time} ]"
|
81
|
+
end
|
82
|
+
|
83
|
+
# p humanize_secs 60
|
84
|
+
# => 1m
|
85
|
+
# p humanize_secs 1234
|
86
|
+
#=>"20m 34s"
|
87
|
+
def humanize_secs(secs)
|
88
|
+
[[60, :s], [60, :m], [24, :h], [1000, :d]].map{ |count, name|
|
89
|
+
if secs > 0
|
90
|
+
secs, n = secs.divmod(count)
|
91
|
+
"#{n.to_i}#{name}"
|
92
|
+
end
|
93
|
+
}.compact.reverse.join(' ').chomp(' 0s')
|
94
|
+
end
|
95
|
+
|
96
|
+
def prepare_dir(dir)
|
97
|
+
FileUtils.mkdir_p dir
|
98
|
+
end
|
99
|
+
|
100
|
+
def audit_faild(msg)
|
101
|
+
abort "[AUDIT FAILED] #{msg}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code_quality
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RainChen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler-audit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: brakeman
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: run code quality and security audit report with one rake task
|
84
|
+
email:
|
85
|
+
- hirainchen@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- code_quality.gemspec
|
100
|
+
- lib/code_quality.rb
|
101
|
+
- lib/code_quality/railtie.rb
|
102
|
+
- lib/code_quality/version.rb
|
103
|
+
- lib/tasks/code_quality.rake
|
104
|
+
homepage: https://github.com/rainchen/code_quality
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.14
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: run code quality and security audit report with one rake task
|
128
|
+
test_files: []
|