filecop 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +11 -1
- data/lib/filecop.rb +5 -60
- data/lib/filecop/cli.rb +31 -0
- data/lib/filecop/runner.rb +28 -0
- data/lib/filecop/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10b25501425618f4192f3478fbc7c8f726220f50
|
4
|
+
data.tar.gz: d457ffe22015eaf5f946f8c463ac2bbeac39435f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ba4e3c32d92863c92e4b67e567040782ca220ad5f7e1beaf83a5553b22bedb4797f219517f73819b665896ff892cac58dad5ebc4b4c2e0d8f880de7bc8b8a09
|
7
|
+
data.tar.gz: e36ed8895ae16120b3007570183e72af987b7520f0f1a76df926e4cddfc02bf164b3e0fad883581c2b9f7955002f2c9585a5410da932a689d072a5bdac86f227
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://badge.fury.io/rb/filecop)
|
2
|
+
|
1
3
|
# Filecop
|
2
4
|
|
3
5
|
Filecop is designed to find sensitive files in a provided list. Ideally this would be integrated into something like a git pre-commit hook or post commit check to reduce instances of leaked credentials.
|
@@ -22,7 +24,7 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
Using filecop is easy, pass no arguments to check all files in the current directory:
|
27
|
+
Using filecop is easy, pass no arguments to check all files in the current directory from the command line:
|
26
28
|
|
27
29
|
$ filecop
|
28
30
|
|
@@ -52,6 +54,14 @@ Or pass the `--json` flag to get a machine parseable output
|
|
52
54
|
]
|
53
55
|
```
|
54
56
|
|
57
|
+
You can also require filecop to use within a Ruby script like so:
|
58
|
+
|
59
|
+
```
|
60
|
+
require('filecop')
|
61
|
+
filecop = Filecop::Runner(['private.key', '.bashrc'])
|
62
|
+
result = filecop.run
|
63
|
+
```
|
64
|
+
|
55
65
|
## Development
|
56
66
|
|
57
67
|
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.
|
data/lib/filecop.rb
CHANGED
@@ -1,63 +1,8 @@
|
|
1
1
|
require "json"
|
2
2
|
require "pathname"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
class CLI
|
10
|
-
|
11
|
-
def run(args = ARGV)
|
12
|
-
@options, @paths = Options.parse!(args)
|
13
|
-
@paths = Dir.entries(".") if @paths.length==0
|
14
|
-
|
15
|
-
unless @options.json
|
16
|
-
puts "Checking #{@paths.length} files\n"
|
17
|
-
end
|
18
|
-
|
19
|
-
files = matching_files
|
20
|
-
|
21
|
-
if @options.json
|
22
|
-
puts JSON.generate files.map { |p| { file: p[:file], message: p[:rule].message } }
|
23
|
-
else
|
24
|
-
if files.length>0
|
25
|
-
puts "\nIssues:\n\n"
|
26
|
-
end
|
27
|
-
puts files.map { |p| "#{p[:file]}: #{p[:rule].message}" }
|
28
|
-
puts "\n"
|
29
|
-
puts "#{@paths.length} files checked, #{files.length} potential problems"
|
30
|
-
end
|
31
|
-
|
32
|
-
return files.length>0 ? 1 : 0
|
33
|
-
rescue StandardError, SyntaxError => e
|
34
|
-
$stderr.puts e.message
|
35
|
-
$stderr.puts e.backtrace
|
36
|
-
return 1
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def matching_files
|
42
|
-
# load banned patterns from config file
|
43
|
-
patterns = JSON.parse File.read(File.join(File.dirname(__FILE__), 'patterns.json'))
|
44
|
-
rules = patterns.map { |o| Rule.new(o) }
|
45
|
-
output = []
|
46
|
-
|
47
|
-
@paths.each do |file|
|
48
|
-
rules.each do |rule|
|
49
|
-
if rule.matches?(file)
|
50
|
-
output << {
|
51
|
-
file: file,
|
52
|
-
rule: rule
|
53
|
-
}
|
54
|
-
break
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
output
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
4
|
+
require_relative "./filecop/runner"
|
5
|
+
require_relative "./filecop/version"
|
6
|
+
require_relative "./filecop/options"
|
7
|
+
require_relative "./filecop/rule"
|
8
|
+
require_relative "./filecop/cli"
|
data/lib/filecop/cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Filecop
|
2
|
+
class CLI
|
3
|
+
|
4
|
+
def run(args = ARGV)
|
5
|
+
@options, @paths = Options.parse!(args)
|
6
|
+
@paths = Dir.entries(".") if @paths.length==0
|
7
|
+
runner = Runner.new(@paths)
|
8
|
+
|
9
|
+
if @options.json
|
10
|
+
files = runner.run
|
11
|
+
puts JSON.generate files.map { |p| { file: p[:file], message: p[:rule].message } }
|
12
|
+
else
|
13
|
+
puts "Checking #{@paths.length} files\n"
|
14
|
+
files = runner.run
|
15
|
+
|
16
|
+
if files.length>0
|
17
|
+
puts "\nIssues:\n\n"
|
18
|
+
end
|
19
|
+
puts files.map { |p| "#{p[:file]}: #{p[:rule].message}" }
|
20
|
+
puts "\n"
|
21
|
+
puts "#{@paths.length} files checked, #{files.length} potential problems"
|
22
|
+
end
|
23
|
+
|
24
|
+
return files.length>0 ? 1 : 0
|
25
|
+
rescue StandardError, SyntaxError => e
|
26
|
+
$stderr.puts e.message
|
27
|
+
$stderr.puts e.backtrace
|
28
|
+
return 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Filecop
|
2
|
+
class Runner
|
3
|
+
def initialize(paths)
|
4
|
+
@paths = paths
|
5
|
+
end
|
6
|
+
|
7
|
+
def run
|
8
|
+
# load banned patterns from config file
|
9
|
+
patterns = JSON.parse File.read(File.join(File.dirname(__FILE__), '..', 'patterns.json'))
|
10
|
+
rules = patterns.map { |o| Rule.new(o) }
|
11
|
+
output = []
|
12
|
+
|
13
|
+
@paths.each do |file|
|
14
|
+
rules.each do |rule|
|
15
|
+
if rule.matches?(file)
|
16
|
+
output << {
|
17
|
+
file: file,
|
18
|
+
rule: rule
|
19
|
+
}
|
20
|
+
break
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
output
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/filecop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filecop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Moor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,8 +73,10 @@ files:
|
|
73
73
|
- bin/setup
|
74
74
|
- filecop.gemspec
|
75
75
|
- lib/filecop.rb
|
76
|
+
- lib/filecop/cli.rb
|
76
77
|
- lib/filecop/options.rb
|
77
78
|
- lib/filecop/rule.rb
|
79
|
+
- lib/filecop/runner.rb
|
78
80
|
- lib/filecop/version.rb
|
79
81
|
- lib/patterns.json
|
80
82
|
homepage: https://github.com/tommoor/filecop
|