Class: GitlabChecks::CLI::Application
- Inherits:
-
Object
- Object
- GitlabChecks::CLI::Application
- Defined in:
- lib/gitlab_checks/cli/application.rb
Constant Summary collapse
- STATUS_SUCCESS =
0- STATUS_ERROR =
1
Instance Method Summary collapse
- #do_audit(gitlab_org) ⇒ Object
- #do_output(gitlab_org) ⇒ Object
- #do_stats(_gitlab_org) ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
Constructor Details
#initialize ⇒ Application
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab_checks/cli/application.rb', line 13 def initialize @group_checks = GitlabChecks::Checks::Group.new @member_checks = GitlabChecks::Checks::Members.new @repo_checks = GitlabChecks::Checks::Repository.new @findings = [] = {} OptionParser.new do |opts| opts. = "Usage: gitlab_checks --url URL --group GROUPID --token TOKEN" opts.on("-u", "--url URL", "Url of Gitlab API") do |u| [:endpoint] = u end opts.on("-g", "--group GROUPID", "ID of the root group for processing") do |u| [:group] = u end opts.on("-t", "--token TOKEN", "GitLab private token or OAuth2 access token, default: ENV['GITLAB_API_PRIVATE_TOKEN']") do |u| [:token] = u end opts.on("-h", "--help", "Display this screen") do puts opts exit end end.parse! end |
Instance Method Details
#do_audit(gitlab_org) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gitlab_checks/cli/application.rb', line 67 def do_audit(gitlab_org) @findings.concat(@group_checks.audit(gitlab_org)) @findings.concat(@member_checks.audit(gitlab_org) || []) @findings.concat(@repo_checks.audit(gitlab_org) || []) @findings.sort_by!(&:severity) print "-----------------------------------" print "FINDINGS" print "-----------------------------------" print "" @findings.each(&:print_console) end |
#do_output(gitlab_org) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gitlab_checks/cli/application.rb', line 91 def do_output(gitlab_org) print "-----------------------------------" print "OUTPUT" print "-----------------------------------" print "" @group_checks.output_result @member_checks.output_result @repo_checks.output_result print "" end |
#do_stats(_gitlab_org) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gitlab_checks/cli/application.rb', line 80 def do_stats(_gitlab_org) print "-----------------------------------" print "STATISTICS" print "-----------------------------------" print "" @group_checks.output_statistics @repo_checks.output_statistics @member_checks.output_statistics print "" end |
#execute ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gitlab_checks/cli/application.rb', line 43 def execute if [:endpoint].nil? || [:group].nil? print("Usage: gitlab_checks --url URL --group GROUPID --token TOKEN") exit(STATUS_ERROR) end if [:token].nil? && ENV['GITLAB_API_PRIVATE_TOKEN'].nil? print("No GitLab token specified, please use --token TOKEN or set env variable GITLAB_API_PRIVATE_TOKEN") exit(STATUS_ERROR) end print "-----------------------------------" print "GITLAB CHECKS v#{GitlabChecks::VERSION} by Zerosource (https://zerosource.io)" print "-----------------------------------" print "Running checks on GitLab group: #{@options[:group]}" print "" gitlab_org = GitlabChecks::Connector::Organisation.new([:endpoint], [:token], [:group]) do_audit(gitlab_org) do_stats(gitlab_org) do_output(gitlab_org) STATUS_SUCCESS end |