Class: Neetob::CLI::Github::Repositories::GetSecurityDetails

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/github/repositories/get_security_details.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from Base

#access_token, #client

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(repos, sandbox = false) ⇒ GetSecurityDetails

Returns a new instance of GetSecurityDetails.



12
13
14
15
16
# File 'lib/neetob/cli/github/repositories/get_security_details.rb', line 12

def initialize(repos, sandbox = false)
  super()
  @repos = repos
  @sandbox = sandbox
end

Instance Attribute Details

#reposObject

Returns the value of attribute repos.



10
11
12
# File 'lib/neetob/cli/github/repositories/get_security_details.rb', line 10

def repos
  @repos
end

#sandboxObject

Returns the value of attribute sandbox.



10
11
12
# File 'lib/neetob/cli/github/repositories/get_security_details.rb', line 10

def sandbox
  @sandbox
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/neetob/cli/github/repositories/get_security_details.rb', line 18

def run
  matching_repos = find_all_matching_apps_or_repos(repos, :github, sandbox)
  data = []
  matching_repos.each do |repo|
    begin
      uri = URI("https://api.github.com/repos/#{repo}/code-security-configuration")
      request = Net::HTTP::Get.new(uri)
      headers = {
        "Accept" => "application/vnd.github+json",
        "Authorization" => "Bearer #{@access_token}"
      }
      headers.each { |key, value| request[key] = value }

      response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
        http.request(request)
      end
      JSON.parse(response.body, symbolize_names: true)
    rescue StandardError => e
      ExceptionHandler.new(e).process
    end
  end
  data
end