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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d03fa4509bea5b712d0dcfe3636e9f04e527b714
4
- data.tar.gz: abbbd7649770fbe12a851c9ee45551db63b44564
3
+ metadata.gz: 10b25501425618f4192f3478fbc7c8f726220f50
4
+ data.tar.gz: d457ffe22015eaf5f946f8c463ac2bbeac39435f
5
5
  SHA512:
6
- metadata.gz: cf273290780505684a3b4651b31d5d50baa0d69b4606231a3d2d85cdfba46db118fae8d03fcc5fa0b58b07b442a2618244192ada4c8b74abe4f2ca64a5218022
7
- data.tar.gz: 07900113c8151e2c319b29b99a75bcd102c2f5ff551462482027196f2a761b9fbf05d5f8487023cec655cb0335f0bf9e2134cb9c30726bd06756486d761c14c1
6
+ metadata.gz: 6ba4e3c32d92863c92e4b67e567040782ca220ad5f7e1beaf83a5553b22bedb4797f219517f73819b665896ff892cac58dad5ebc4b4c2e0d8f880de7bc8b8a09
7
+ data.tar.gz: e36ed8895ae16120b3007570183e72af987b7520f0f1a76df926e4cddfc02bf164b3e0fad883581c2b9f7955002f2c9585a5410da932a689d072a5bdac86f227
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/filecop.svg)](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.
@@ -1,63 +1,8 @@
1
1
  require "json"
2
2
  require "pathname"
3
3
 
4
- require "filecop/version"
5
- require "filecop/options"
6
- require "filecop/rule"
7
-
8
- module Filecop
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"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Filecop
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-03 00:00:00.000000000 Z
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