Class: Threadfix::Client::Scans::Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/threadfix/client/scans/upload.rb

Constant Summary collapse

API_VERSION =
'v2.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Upload

Returns a new instance of Upload.



12
13
14
15
# File 'lib/threadfix/client/scans/upload.rb', line 12

def initialize(options={})
  @file_path = options[:file_path]
  @app_id = options[:app_id]
end

Instance Attribute Details

#app_idObject (readonly)

Returns the value of attribute app_id.



10
11
12
# File 'lib/threadfix/client/scans/upload.rb', line 10

def app_id
  @app_id
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



10
11
12
# File 'lib/threadfix/client/scans/upload.rb', line 10

def file_path
  @file_path
end

Instance Method Details

#perform!Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/threadfix/client/scans/upload.rb', line 17

def perform!
  begin
    puts "POST #{endpoint.to_s}" if ENV['DEBUG']
    r = RestClient.post(
      endpoint.to_s,
      { file: file },
      { :accept => "application/json", :Authorization => "APIKEY #{apiKey}" }
    )
    JSON.parse(r.body)
  rescue RestClient::NotFound => e
    puts "Endpoint not found (using API version: #{API_VERSION})"
    raise e
  rescue RestClient::ExceptionWithResponse => e
    puts e.message
    raise e
  end
end