Class: CloudJobAws::AwsInternalStorageHandler

Inherits:
CloudJobBase::InternalStorageHandler
  • Object
show all
Defined in:
lib/cloud_storage_aws.rb

Instance Method Summary collapse

Instance Method Details

#init_connectionObject



9
10
11
12
13
14
15
16
17
# File 'lib/cloud_storage_aws.rb', line 9

def init_connection
    raise "Key not set." if ENV['AWS_ACCESS_KEY_ID'].nil?
    @key = ENV['AWS_ACCESS_KEY_ID']
    raise "Secret not set." if ENV['AWS_SECRET_ACCESS_KEY'].nil?
    @secret = ENV['AWS_SECRET_ACCESS_KEY']
    
    @s3_default = Aws::S3::Resource.new(region: "eu-west-1", credentials: Aws::Credentials.new(@key, @secret))
    @default_bucket = @s3_default.bucket("user-exe-files")
end

#presigned_post(bucket_key) ⇒ Object



30
31
32
# File 'lib/cloud_storage_aws.rb', line 30

def presigned_post(bucket_key)
    @default_bucket.presigned_post(key: bucket_key, success_action_status: '201', acl: 'public-read')
end

#put_file(file_path) ⇒ Object



19
20
21
22
23
24
# File 'lib/cloud_storage_aws.rb', line 19

def put_file(file_path)
    name = File.basename(file_path)
    object = @default_bucket.object(name)
    object.upload_file(file_path)
    return object.key
end

#read_file(file_url) ⇒ Object



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

def read_file(file_url)
    @default_bucket.get(file_url)
end