githack 0.1.0 → 0.2.0
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/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/bin/githack.rb +1 -1
- data/lib/githack.rb +2 -2
- data/lib/githack/rails_repository.rb +35 -0
- data/lib/githack/repository.rb +43 -73
- data/lib/githack/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45b9752319cd83954a52829df8728540731f5fe7
|
4
|
+
data.tar.gz: 99461ea4306976cdcedfea9927d13b778c96fda4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5908cddcecc60d86ba4ccf49a9685af8e930ccdf88d9a48507c2bfb442e7ec0274460c01ae1e2e85f800042d6e43723fcda6dd8090b53c080575dfd789b26af
|
7
|
+
data.tar.gz: 6da3344fb2cbd29c67d0648d947bfa82b0a9a09b04a47497f4db7825072632500864fd1b9a25258b623d9dbb28a1329e925b8f2f8c4f5140d44249ea43b87848
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Githack
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/githack)
|
4
|
+
|
3
5
|
Crawl [Git][git]'s commits of a given repository to find forgotten credentials
|
4
6
|
|
5
7
|
Currently support:
|
@@ -42,7 +44,7 @@ Simply use tis to clone the remote repository in your temporary folder
|
|
42
44
|
```ruby
|
43
45
|
require 'githack'
|
44
46
|
|
45
|
-
repository =
|
47
|
+
repository = Githack::RailsRepository.new 'https://github.com/RaspberryCook/website'
|
46
48
|
```
|
47
49
|
|
48
50
|
And then you can search on repository like this:
|
data/bin/githack.rb
CHANGED
data/lib/githack.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'githack/repository'
|
2
|
+
|
3
|
+
module Githack
|
4
|
+
class RailsRepository < Repository
|
5
|
+
# Get all changements for config/secrets.yml file (who contains some API keys)
|
6
|
+
def search_rails_config_secrets
|
7
|
+
results = []
|
8
|
+
|
9
|
+
absolute_file_path = File.join @path, 'config', 'secrets.yml'
|
10
|
+
|
11
|
+
checkout_on_yaml_file_change(absolute_file_path) do |secrets|
|
12
|
+
results << secrets
|
13
|
+
end
|
14
|
+
|
15
|
+
results.uniq
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get all changements for config/database.yml file (who contains database configuration for Ruby on Rails Framework)
|
19
|
+
def search_rails_config_database
|
20
|
+
results = []
|
21
|
+
|
22
|
+
absolute_file_path = File.join @path, 'config', 'database.yml'
|
23
|
+
|
24
|
+
checkout_on_yaml_file_change(absolute_file_path) do |configs|
|
25
|
+
configs.each do |config|
|
26
|
+
config_data = config[1]
|
27
|
+
next if config_data['adapter'] == 'sqlite3'
|
28
|
+
results << config_data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
results.uniq
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/githack/repository.rb
CHANGED
@@ -2,86 +2,56 @@ require 'tmpdir'
|
|
2
2
|
require 'yaml'
|
3
3
|
require 'git'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
5
|
+
module Githack
|
6
|
+
class Repository
|
7
|
+
attr_reader :git, :remote, :name, :path
|
8
|
+
|
9
|
+
def initialize(remote)
|
10
|
+
@remote = remote
|
11
|
+
@name = remote.gsub /[^0-9A-Z]/i, '_'
|
12
|
+
@path = File.join(Dir.tmpdir, name)
|
13
|
+
|
14
|
+
@git = if File.directory? @path
|
15
|
+
Git.open @path
|
16
|
+
else
|
17
|
+
Git.clone @remote, @name, path: Dir.tmpdir
|
18
|
+
end
|
32
19
|
end
|
33
20
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
21
|
+
protected
|
22
|
+
|
23
|
+
# Checkout on all file changes
|
24
|
+
#
|
25
|
+
# @param file <String> absolute filepath
|
26
|
+
# @yield <Hash> YAML file parsed
|
27
|
+
def checkout_on_yaml_file_change(file)
|
28
|
+
checkout_on_file_change(file) do
|
29
|
+
begin
|
30
|
+
data = YAML.safe_load(File.read(file))
|
31
|
+
yield data
|
32
|
+
rescue Psych::SyntaxError => e
|
33
|
+
# can't parse YAML file
|
34
|
+
end
|
48
35
|
end
|
49
36
|
end
|
50
37
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# @yield <Hash> YAML file parsed
|
58
|
-
def checkout_on_yaml_file_change(file)
|
59
|
-
checkout_on_file_change(file) do
|
38
|
+
# Checkout on all file changes
|
39
|
+
#
|
40
|
+
# @param file <String> absolute filepath
|
41
|
+
# @yield <Git::Log>
|
42
|
+
def checkout_on_file_change(file)
|
43
|
+
@git.checkout 'master'
|
60
44
|
begin
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
45
|
+
@git.log.object(file).each do |commit|
|
46
|
+
@git.checkout commit
|
47
|
+
next unless File.exist? file
|
48
|
+
|
49
|
+
yield commit
|
50
|
+
end
|
51
|
+
rescue StandardError
|
52
|
+
Psych::BadAlias
|
81
53
|
end
|
82
|
-
|
83
|
-
Psych::BadAlias
|
54
|
+
@git.checkout 'master'
|
84
55
|
end
|
85
|
-
@git.checkout 'master'
|
86
56
|
end
|
87
57
|
end
|
data/lib/githack/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: githack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rousseau Alexandre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- bin/setup
|
102
102
|
- githack.gemspec
|
103
103
|
- lib/githack.rb
|
104
|
+
- lib/githack/rails_repository.rb
|
104
105
|
- lib/githack/repository.rb
|
105
106
|
- lib/githack/version.rb
|
106
107
|
homepage: https://github.com/madeindjs/githack
|