require "cloud_job_base" require "cloud_storage_handler" require "aws-sdk" module CloudJobAws class AwsInternalStorageHandler < CloudJobBase::InternalStorageHandler 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 def put_file(file_path) name = File.basename(file_path) object = @default_bucket.object(name) object.upload_file(file_path) return object.key end def read_file(file_url) @default_bucket.get(file_url) end def presigned_post(bucket_key) @default_bucket.presigned_post(key: bucket_key, success_action_status: '201', acl: 'public-read') end end end