daily_brakeman 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +17 -0
  2. data/lib/daily_brakeman.rb +73 -0
  3. metadata +45 -0
@@ -0,0 +1,17 @@
1
+ ---
2
+ !binary "U0hBMjU2":
3
+ metadata.gz: !binary |-
4
+ ODc1ZTAwZTMxMmRkNWNlN2I5ZWUwYTllYjU3NTBhMTAxODczZGJjMTliOGM1
5
+ NGViYzRlY2E3Zjk4M2NjN2NlNw==
6
+ data.tar.gz: !binary |-
7
+ OTE0NWQzZGI1NjU5MTZjM2U2YzRjMzlhNDExZGMzMGJlMjFmZTA0ZDQwNjJi
8
+ N2U1MGRjYTQ0OWMxNjAxZGEzZQ==
9
+ SHA512:
10
+ metadata.gz: !binary |-
11
+ YzkwNzFjMDk2NDI1YWEwM2QxZDJjYzg5YzFjYmU3MzViNzc1MGE2MDEwMGM5
12
+ YzBkNzY3MTZjYWY5YWI2Mjg3YTA0NTg1OWUxMTIwMzIxYjRhYTMyMzExMTc1
13
+ MzRmNGM3ZmY1ZWM5ZWU3YmJlOTYxYTNlZWU0OWI1MDgzZmJjZTU=
14
+ data.tar.gz: !binary |-
15
+ ODY4YTIwNTY2ZmVhMGJlMzNjYjYwZTJhMTdkNzg5ZjFkZDM2ZmJkMDBiZmJl
16
+ ODViMzI4ZTRjODUyNzY0YjFkOWUxN2YwN2QwMDVjNDhhOTc2YjU1ZTdiYzE0
17
+ YmU4MWMxNjBkMWQ1ZTEwOTc5ZTc2NjBkYzg4YmMwZmFhMGE2ZTQ=
@@ -0,0 +1,73 @@
1
+ require 'fileutils'
2
+
3
+ module DailyBrakeman
4
+ class BrakemanSecurity
5
+
6
+ def initialize(version_control = nil, from = nil, to = nil)
7
+ @version_control = version_control
8
+ @from = from
9
+ @to = to
10
+ end
11
+
12
+ def brakeman_security
13
+ FileUtils.mkdir_p 'brakeman'
14
+ root_folder = "#{Rails.root}/brakeman"
15
+ time_now = Time.now
16
+ time_yesterday = time_now.yesterday
17
+ brakeman_file_format = "security_#{time_format(time_yesterday)}.json"
18
+ comparison_file_format = "security_comparison_#{time_format(time_yesterday)}_to_#{time_format(time_now)}.json"
19
+ format = %w[json html]
20
+ if File.exist?("#{root_folder}/#{brakeman_file_format}")
21
+ comparison_file = "#{root_folder}/#{comparison_file_format}"
22
+ system("brakeman --compare #{root_folder}/#{brakeman_file_format} -o #{comparison_file}")
23
+ format.each { |fr| system("rm -f #{root_folder}/security_#{time_format(time_yesterday)}.#{fr}") }
24
+ create_security_file(root_folder, format, time_format(time_now))
25
+ condition = override_comparison_file(comparison_file)
26
+ else
27
+ create_security_file(root_folder, format, time_format(time_now))
28
+ puts 'Yesterday,Security File not there!!!.In that folder'
29
+ puts 'Create File: brakeman -o brakeman/security_MMDDYYYY.json'
30
+ end
31
+ end
32
+
33
+ def override_comparison_file(file)
34
+ output = {}
35
+ data = File.read(file)
36
+ json_data = JSON.parse(data)
37
+ condition = json_data['new'].blank? && json_data['fixed'].blank?
38
+ return condition if condition
39
+
40
+ # Overwrite JSON Data - Add Blame
41
+ json_data.each do |key, value|
42
+ value.each do |hash|
43
+ output[key] = add_gitblame(hash)
44
+ end
45
+ end
46
+ # Overwrite Comparison File
47
+ File.open(file, 'w') do |f|
48
+ f.puts JSON.pretty_generate(json_data)
49
+ end
50
+ condition
51
+ end
52
+
53
+ def add_gitblame(hash)
54
+ file = hash['file']
55
+ line = hash['line']
56
+ if @version_control == 'git'
57
+ git_blame = `git blame -L #{line},#{line} #{file}`
58
+ hash['blame'] = git_blame
59
+ hash
60
+ else
61
+ hash
62
+ end
63
+ end
64
+
65
+ def create_security_file(root_folder, format, time_format)
66
+ format.each { |fr| system("brakeman -o #{root_folder}/security_#{time_format}.#{fr}") }
67
+ end
68
+
69
+ def time_format(time)
70
+ time.strftime('%m%d%Y')
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daily_brakeman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Honestraj Kandhasamy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Much longer explanation of the example!
14
+ email: honestraj.it@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/daily_brakeman.rb
20
+ homepage: https://rubygems.org/gems/DailyBrakeman
21
+ licenses:
22
+ - MIT
23
+ metadata:
24
+ source_code_uri: https://github.com/example/example
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.7.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: DailyBrakeman
45
+ test_files: []