githack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d580c81976aa556c3c84fd93c7394a473dd08d11
4
+ data.tar.gz: 768611bf8d2d7bcd8b71c34fb4d2624c4e9b20f2
5
+ SHA512:
6
+ metadata.gz: e9f21fb4bc6e718d7e52d08c9c53044bea0d67c2369492226fd74bdb38f0a30bc2b76a8c243911abbe168a9369637fab7e3f1b0c8d67fb1aefc4dde9e6b70308
7
+ data.tar.gz: e8b34e95ca079a6dbc8aa8a90f56adb63e32e6f170e0a6a5e820f4e6c371f3734599fb67059308226515e46a7b8ee3f84d238795e09bc87e21309ebc53c8e21a
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at contact@rousseau-alexandre.Fr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in githack.gemspec
6
+ gemspec
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ githack (0.1.0)
5
+ git (~> 1.5)
6
+ tty-spinner (~> 0.8)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.3)
12
+ git (1.5.0)
13
+ rake (10.5.0)
14
+ rspec (3.8.0)
15
+ rspec-core (~> 3.8.0)
16
+ rspec-expectations (~> 3.8.0)
17
+ rspec-mocks (~> 3.8.0)
18
+ rspec-core (3.8.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-expectations (3.8.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-mocks (3.8.0)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.8.0)
26
+ rspec-support (3.8.0)
27
+ tty-cursor (0.6.0)
28
+ tty-spinner (0.8.0)
29
+ tty-cursor (>= 0.5.0)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.16)
36
+ githack!
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.1
@@ -0,0 +1,86 @@
1
+ # Githack
2
+
3
+ Crawl [Git][git]'s commits of a given repository to find forgotten credentials
4
+
5
+ Currently support:
6
+
7
+ - [Ruby on Rails](https://rubyonrails.org)
8
+
9
+ - _config/secrets.yml_
10
+ - _config/database.yml_
11
+
12
+ ## Dependencies
13
+
14
+ You need to install [Git][git]. Exemple for Debian based distributions:
15
+
16
+ ```bash
17
+ $ sudo apt install git
18
+ ```
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'githack'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install githack
35
+
36
+ ## Usage
37
+
38
+ ### As library
39
+
40
+ Simply use tis to clone the remote repository in your temporary folder
41
+
42
+ ```ruby
43
+ require 'githack'
44
+
45
+ repository = Repository.new 'https://github.com/RaspberryCook/website'
46
+ ```
47
+
48
+ And then you can search on repository like this:
49
+
50
+ ```ruby
51
+ repository.search_rails_config_database
52
+ # [{"adapter"=>"mysql2", "database"=>"raspberry_cook", "encoding"=>"utf8", "username"=>"raspberry_cook", "password"=>"secret", "host"=>"localhost", "pool"=>5, "timeout"=>5000}])
53
+
54
+ repository.search_rails_config_secrets
55
+ # [{"development"=>{"marmiton_password"=>"20462046"}, "production"=>{"marmiton_password"=>"20462046"}, "test"=>{"marmiton_password"=>"20462046"}}])
56
+ ```
57
+
58
+ Theses methods will:
59
+
60
+ 1. Search all commit were file changed
61
+ 2. Checkout on theses commit to get file content
62
+ 3. Filter only usefull informations
63
+
64
+ ### As command line tool
65
+
66
+ Simply use
67
+
68
+ ```bash
69
+ $ githack.rb https://github.com/RaspberryCook/website
70
+ ```
71
+
72
+ ## Development
73
+
74
+ 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.
75
+
76
+ 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).
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/githack. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
+
82
+ ## Code of Conduct
83
+
84
+ Everyone interacting in the Githack project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/githack/blob/master/CODE_OF_CONDUCT.md).
85
+
86
+ [git]: https://git-scm.com/
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "githack"
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__)
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ require 'githack'
3
+ require 'optparse'
4
+ require 'tty-spinner'
5
+ require 'pp'
6
+
7
+ url = nil
8
+
9
+ options = {
10
+ skip_config_secrets: false,
11
+ skip_config_database: false
12
+ }
13
+
14
+ OptionParser.new do |opts|
15
+ opts.banner = 'Usage: githack.rb URL with URL as remote URL of a Git repository (currently works only for Rails project)'
16
+
17
+ url = ARGV.pop
18
+
19
+ opts.on '--skip_config_secrets', 'Not search for config/secrets.yml' do |_o|
20
+ options[:skip_config_secrets] = true
21
+ end
22
+
23
+ opts.on '--skip_config_database', 'Not search for config/database.yml' do |_o|
24
+ options[:skip_config_secrets] = true
25
+ end
26
+
27
+ unless url
28
+ puts "You must provide a Git remote URL\r\n\r\n"
29
+ puts opts
30
+ exit
31
+ end
32
+ end.parse!
33
+
34
+ spinner = TTY::Spinner.new '[:spinner] Cloning repository ...'
35
+ spinner.auto_spin
36
+ repository = Repository.new url
37
+ spinner.stop('Done!')
38
+
39
+ unless options[:skip_config_database]
40
+ spinner = TTY::Spinner.new '[:spinner] Search in config/database.yml (Rails) ...'
41
+ spinner.auto_spin
42
+ result = repository.search_rails_config_database
43
+ spinner.stop('Done!')
44
+ pp result
45
+ end
46
+
47
+ unless options[:skip_config_secrets]
48
+ spinner = TTY::Spinner.new '[:spinner] Search in config/secrets.yml (Rails) ...'
49
+ spinner.auto_spin
50
+ result = repository.search_rails_config_secrets
51
+ spinner.stop('Done!')
52
+ pp result
53
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'githack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'githack'
8
+ spec.version = Githack::VERSION
9
+ spec.authors = ['Rousseau Alexandre']
10
+ spec.email = ['contact@rousseau-alexandre.Fr']
11
+
12
+ spec.summary = "Crawl git's commits of a given repository to find forgotten credentials"
13
+ spec.description = "Crawl git's commits of a given repository to find forgotten credentials"
14
+ spec.homepage = 'https://github.com/madeindjs/githack'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'bin'
29
+ spec.executables = ['githack.rb']
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'git', '~> 1.5'
33
+ spec.add_dependency 'tty-spinner', '~> 0.8'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.16'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ end
@@ -0,0 +1,6 @@
1
+ require "githack/version"
2
+ require "githack/repository"
3
+
4
+ module Githack
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,87 @@
1
+ require 'tmpdir'
2
+ require 'yaml'
3
+ require 'git'
4
+
5
+ class Repository
6
+ SENSIBLES_FILES = [
7
+ File.join('config', 'database.yml')
8
+ ].freeze
9
+
10
+ attr_reader :git, :remote, :name, :path
11
+
12
+ def initialize(remote)
13
+ @remote = remote
14
+ @name = remote.gsub /[^0-9A-Z]/i, '_'
15
+ @path = File.join(Dir.tmpdir, name)
16
+
17
+ @git = if File.directory? @path
18
+ Git.open @path
19
+ else
20
+ Git.clone @remote, @name, path: Dir.tmpdir
21
+ end
22
+ end
23
+
24
+ # Get all changements for config/secrets.yml file (who contains some API keys)
25
+ def search_rails_config_secrets
26
+ results = []
27
+
28
+ absolute_file_path = File.join @path, 'config', 'secrets.yml'
29
+
30
+ checkout_on_yaml_file_change(absolute_file_path) do |secrets|
31
+ results << secrets
32
+ end
33
+
34
+ results.uniq
35
+ end
36
+
37
+ # Get all changements for config/database.yml file (who contains database configuration for Ruby on Rails Framework)
38
+ def search_rails_config_database
39
+ results = []
40
+
41
+ absolute_file_path = File.join @path, 'config', 'database.yml'
42
+
43
+ checkout_on_yaml_file_change(absolute_file_path) do |configs|
44
+ configs.each do |config|
45
+ config_data = config[1]
46
+ next if config_data['adapter'] == 'sqlite3'
47
+ results << config_data
48
+ end
49
+ end
50
+
51
+ results.uniq
52
+ end
53
+
54
+ # Checkout on all file changes
55
+ #
56
+ # @param file <String> absolute filepath
57
+ # @yield <Hash> YAML file parsed
58
+ def checkout_on_yaml_file_change(file)
59
+ checkout_on_file_change(file) do
60
+ begin
61
+ data = YAML.safe_load(File.read(file))
62
+ yield data
63
+ rescue Psych::SyntaxError => e
64
+ # can't parse YAML file
65
+ end
66
+ end
67
+ end
68
+
69
+ # Checkout on all file changes
70
+ #
71
+ # @param file <String> absolute filepath
72
+ # @yield <Git::Log>
73
+ def checkout_on_file_change(file)
74
+ @git.checkout 'master'
75
+ begin
76
+ @git.log.object(file).each do |commit|
77
+ @git.checkout commit
78
+ next unless File.exist? file
79
+
80
+ yield commit
81
+ end
82
+ rescue StandardError
83
+ Psych::BadAlias
84
+ end
85
+ @git.checkout 'master'
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module Githack
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: githack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rousseau Alexandre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: git
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-spinner
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
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: Crawl git's commits of a given repository to find forgotten credentials
84
+ email:
85
+ - contact@rousseau-alexandre.Fr
86
+ executables:
87
+ - githack.rb
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/githack.rb
101
+ - bin/setup
102
+ - githack.gemspec
103
+ - lib/githack.rb
104
+ - lib/githack/repository.rb
105
+ - lib/githack/version.rb
106
+ homepage: https://github.com/madeindjs/githack
107
+ licenses: []
108
+ metadata:
109
+ allowed_push_host: https://rubygems.org/
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.14
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Crawl git's commits of a given repository to find forgotten credentials
130
+ test_files: []