Class: Vigilion::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/vigilion/http.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTTP

Returns a new instance of HTTP.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vigilion/http.rb', line 5

def initialize
  validate_access_keys
  @conn = ::Faraday.new(url: Configuration.server_url) do |c|
    c.request :multipart
    c.request :json
    c.response :json, content_type: /\bjson$/
    if Configuration.debug
      c.response :detailed_logger, Configuration.logger
    end
    c.adapter ::Faraday.default_adapter
    c.headers = {
      'X-Api-Key' => Configuration.access_key_id,
      'User-Agent' => "Vigilion #{Vigilion::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})"
    }
  end
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/vigilion/http.rb', line 3

def method
  @method
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/vigilion/http.rb', line 3

def options
  @options
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/vigilion/http.rb', line 3

def url
  @url
end

Class Method Details

.digest(body) ⇒ Object



40
41
42
# File 'lib/vigilion/http.rb', line 40

def self.digest(body)
  Digest::MD5.hexdigest("#{body}#{Vigilion::Configuration.secret_access_key}")
end

Instance Method Details

#get(uuid) ⇒ Object



30
31
32
33
# File 'lib/vigilion/http.rb', line 30

def get(uuid)
  response = @conn.get "/scans/#{uuid}"
  response.body
end

#scan_path(key, path, options = {}) ⇒ Object



26
27
28
# File 'lib/vigilion/http.rb', line 26

def scan_path(key, path, options = {})
  send scan: options.merge({ key: key, file: Faraday::UploadIO.new(path, 'application') })
end

#scan_url(key, url, options = {}) ⇒ Object



22
23
24
# File 'lib/vigilion/http.rb', line 22

def scan_url(key, url, options = {})
  send scan: options.merge({ key: key, url: Addressable::URI.unescape(url) })
end

#validateObject



35
36
37
38
# File 'lib/vigilion/http.rb', line 35

def validate
  response = @conn.get "/projects/validate"
  process_response("", response)
end