Class: Cnvrg::LogJob

Inherits:
Object
  • Object
show all
Includes:
SuckerPunch::Job
Defined in:
lib/cnvrg/job.rb

Instance Method Summary collapse

Instance Method Details

#perform(upload_resp, file_path) ⇒ Object



11
12
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
# File 'lib/cnvrg/job.rb', line 11

def perform(upload_resp, file_path)
    begin
        sts_path = upload_resp["result"]["path_sts"]
        uri = URI.parse(sts_path)
        http_object = Net::HTTP.new(uri.host, uri.port)
        http_object.use_ssl = true if uri.scheme == 'https'
        request = Net::HTTP::Get.new(sts_path)
        body = ""
        http_object.start do |http|
            response = http.request request
            body = response.read_body
        end
        URLcrypt::key = [body].pack('H*')
        s3 = Aws::S3::Resource.new(
            :access_key_id => URLcrypt.decrypt(upload_resp["result"]["sts_a"]),
            :secret_access_key => URLcrypt.decrypt(upload_resp["result"]["sts_s"]),
            :session_token => URLcrypt.decrypt(upload_resp["result"]["sts_st"]),
            :region => URLcrypt.decrypt(upload_resp["result"]["region"]))
        resp = s3.bucket(URLcrypt.decrypt(upload_resp["result"]["bucket"])).
            object(upload_resp["result"]["path"]+"/"+File.basename(file_path)).
            upload_file(file_path)
        return resp
    rescue =>e
        return false

    end
    return true
end