github_bitbucket_audit 0.0.1 → 0.0.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/bin/gh_bb_audit.rb +9 -2
- data/gh_bb_audit.gemspec +1 -1
- data/lib/gh_bb_audit.rb +4 -1
- data/lib/gh_bb_audit/github_api.rb +22 -0
- data/lib/gh_bb_audit/github_repo.rb +12 -5
- data/lib/gh_bb_audit/github_scanner.rb +15 -1
- data/lib/gh_bb_audit/github_user.rb +11 -2
- data/lib/gh_bb_audit/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 921a09fbd5331053c1322d830e7c13f4302ed215
|
4
|
+
data.tar.gz: 2e6c845eba869dd2bac4384e90b30087bead25ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ec5bd3e4de6d5f181ab00773fd5aaa6afc9cd3bcfe03c4d9aabd351a60dd9f80667965bddb5b7e355d0d1318e4f9d274cbb8e83823acab09c2b3be9061a8eb0
|
7
|
+
data.tar.gz: 8d701d9a6c8afd8d12a72d83b032f441cafe94a7e220917ac5db977e980d6abc133481a6041387a14f59edbf97c4eb16e3f352f3bc2dfd8058222a58e37f55ec
|
data/bin/gh_bb_audit.rb
CHANGED
@@ -5,7 +5,7 @@ require 'optparse'
|
|
5
5
|
|
6
6
|
options = {}
|
7
7
|
OptionParser.new do |opts|
|
8
|
-
opts.banner = "Usage: gh_bb_audit.rb -u <path_to_user_csv_file> -k <path_tpkeywords_csv_file> -o <path_to_output_file>"
|
8
|
+
opts.banner = "Usage: gh_bb_audit.rb -u <path_to_user_csv_file> -k <path_tpkeywords_csv_file> -o <path_to_output_file> -n <github_user> -p <github_password>"
|
9
9
|
|
10
10
|
opts.on("-users", "-u") do |v|
|
11
11
|
options[:user_file_path] = v
|
@@ -18,7 +18,14 @@ OptionParser.new do |opts|
|
|
18
18
|
opts.on("-output", "-o") do |v|
|
19
19
|
options[:output_file_path] = v
|
20
20
|
end
|
21
|
+
|
22
|
+
opts.on("-github_user", "-n") do |v|
|
23
|
+
options[:github_user] = v
|
24
|
+
end
|
21
25
|
|
26
|
+
opts.on("-github_password", "-p") do |v|
|
27
|
+
options[:github_password] = v
|
28
|
+
end
|
22
29
|
end.parse!
|
23
30
|
|
24
|
-
::GhBbAudit::GithubScanner.new(options[:user_file_path], options[:keywords_file_path], options[:output_file_path]).start_scan
|
31
|
+
::GhBbAudit::GithubScanner.new(options[:user_file_path], options[:keywords_file_path], options[:output_file_path], options[:github_user], options[:github_password]).start_scan
|
data/gh_bb_audit.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'gh_bb_audit/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "github_bitbucket_audit"
|
8
|
-
spec.version = "0.0.
|
8
|
+
spec.version = "0.0.2"
|
9
9
|
spec.summary = "Looks for specific keywords in the public repos of github and bitbucket"
|
10
10
|
spec.date = "2014-04-01"
|
11
11
|
spec.description = "The library takes a list of users and searches their public repos for specific keywords"
|
data/lib/gh_bb_audit.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'semantic_logger' unless defined?(logger)
|
2
2
|
require 'github_api'
|
3
3
|
|
4
|
+
SemanticLogger.default_level = :info
|
5
|
+
SemanticLogger.add_appender('gh_bb_audit.log')
|
6
|
+
|
4
7
|
module GhBbAudit
|
5
8
|
GEM_ROOT = File.join(File.dirname(__FILE__), '..')
|
6
|
-
logger = SemanticLogger['GithubBitbucketAudit']
|
7
9
|
end
|
8
10
|
|
9
11
|
require_relative './gh_bb_audit/version'
|
@@ -13,4 +15,5 @@ require_relative './gh_bb_audit/github_scanner'
|
|
13
15
|
require_relative './gh_bb_audit/keywords_list'
|
14
16
|
require_relative './gh_bb_audit/keyword_matcher'
|
15
17
|
require_relative './gh_bb_audit/users_list'
|
18
|
+
require_relative './gh_bb_audit/github_api'
|
16
19
|
require_relative './gh_bb_audit/output_writer'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'semantic_logger'
|
2
|
+
|
3
|
+
module GhBbAudit
|
4
|
+
class GithubApi
|
5
|
+
include SemanticLogger::Loggable
|
6
|
+
|
7
|
+
def self.set_user_name_pwd(user_name, password)
|
8
|
+
@user_name = user_name
|
9
|
+
@password = password
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_api_accesor
|
13
|
+
if !!@user_name && !!@password
|
14
|
+
logger.info("Using Authentication for Github with Username:: #{@user_name}")
|
15
|
+
Github.new login: @user_name, password: @password
|
16
|
+
else
|
17
|
+
Github.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
|
+
require 'semantic_logger'
|
2
|
+
|
1
3
|
module GhBbAudit
|
2
4
|
class GithubRepo
|
5
|
+
include SemanticLogger::Loggable
|
3
6
|
def initialize(user_name,repo_name)
|
4
7
|
@user_name = user_name
|
5
8
|
@repo_name = repo_name
|
@@ -20,16 +23,20 @@ module GhBbAudit
|
|
20
23
|
|
21
24
|
private
|
22
25
|
def get_tree
|
23
|
-
|
24
|
-
|
26
|
+
all_commits = begin
|
27
|
+
GithubApi.get_api_accesor.repos.commits.all @user_name, @repo_name
|
28
|
+
rescue StandardError => e
|
29
|
+
logger.error "Error in fetching Commits for Repo::#{@repo_name} for User:: #{@user_name} ", error: e.inspect
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
last_commit_sha = all_commits[0].sha rescue nil
|
25
33
|
if !last_commit_sha
|
26
34
|
logger.info("Could not find any commit for Github Repo:: #{@repo_name} for User:: #{@user_name}")
|
27
35
|
return nil
|
28
36
|
end
|
29
|
-
|
30
|
-
@github_tree ||= github.git_data.trees.get @user_name, @repo_name, last_commit_sha , 'recursive' => true rescue nil
|
37
|
+
@github_tree ||= GithubApi.get_api_accesor.git_data.trees.get @user_name, @repo_name, last_commit_sha , 'recursive' => true rescue nil
|
31
38
|
if !@github_tree
|
32
|
-
logger.
|
39
|
+
logger.error("Could not fetch tree for Repo:: #{@repo_name} for User:: #{@user_name}")
|
33
40
|
return
|
34
41
|
end
|
35
42
|
@github_tree.tree
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'semantic_logger'
|
1
2
|
module GhBbAudit
|
2
3
|
class GithubScanner
|
3
|
-
|
4
|
+
include SemanticLogger::Loggable
|
5
|
+
|
6
|
+
def initialize(user_csv_path, keyword_csv_path, output_file_path, github_user =nil, github_password =nil)
|
4
7
|
@user_csv_path = user_csv_path
|
5
8
|
@keyword_csv_path = keyword_csv_path
|
6
9
|
@output_file_path = output_file_path
|
10
|
+
GithubApi.set_user_name_pwd(github_user, github_password) if github_user && github_password
|
7
11
|
end
|
8
12
|
|
9
13
|
def start_scan
|
@@ -13,8 +17,17 @@ module GhBbAudit
|
|
13
17
|
all_github_user = ::GhBbAudit::UsersList.new(@user_csv_path).all_users
|
14
18
|
|
15
19
|
all_github_user.each do |user|
|
20
|
+
logger.info("Scanning for User:: #{user}")
|
16
21
|
::GhBbAudit::GithubUser.new(user).public_repos.each do |public_repo|
|
22
|
+
logger.info("Scanning Repo:: #{public_repo.name} for User:: #{user}")
|
23
|
+
if matcher.repo_contains_keyword?([public_repo.name])
|
24
|
+
output_writer.write_red_flag_record(user,public_repo.name)
|
25
|
+
break
|
26
|
+
end
|
27
|
+
|
28
|
+
|
17
29
|
file_paths = ::GhBbAudit::GithubRepo.new(user,public_repo.name).get_all_file_paths
|
30
|
+
|
18
31
|
if matcher.repo_contains_keyword?(file_paths)
|
19
32
|
output_writer.write_red_flag_record(user,public_repo.name)
|
20
33
|
end
|
@@ -27,6 +40,7 @@ module GhBbAudit
|
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
43
|
+
|
30
44
|
end
|
31
45
|
|
32
46
|
end
|
@@ -1,11 +1,20 @@
|
|
1
|
+
require 'semantic_logger'
|
2
|
+
|
1
3
|
module GhBbAudit
|
2
4
|
class GithubUser
|
5
|
+
include SemanticLogger::Loggable
|
6
|
+
|
3
7
|
def initialize(user_name)
|
4
|
-
|
8
|
+
@user_name = user_name
|
5
9
|
end
|
6
10
|
|
7
11
|
def public_repos
|
8
|
-
@public_repos ||=
|
12
|
+
@public_repos ||= begin
|
13
|
+
GithubApi.get_api_accesor.repos.list user: @user_name
|
14
|
+
rescue StandardError => e
|
15
|
+
logger.error "Error in fetching repos for User:: #{@user_name} ", error: e.inspect
|
16
|
+
[]
|
17
|
+
end
|
9
18
|
end
|
10
19
|
end
|
11
20
|
end
|
data/lib/gh_bb_audit/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_bitbucket_audit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ankur Maheshwari
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- bin/gh_bb_audit.rb
|
68
68
|
- gh_bb_audit.gemspec
|
69
69
|
- lib/gh_bb_audit.rb
|
70
|
+
- lib/gh_bb_audit/github_api.rb
|
70
71
|
- lib/gh_bb_audit/github_repo.rb
|
71
72
|
- lib/gh_bb_audit/github_scanner.rb
|
72
73
|
- lib/gh_bb_audit/github_user.rb
|