# frozen_string_literal: true require 'aws-sdk-s3' class MiniS3put def initialize(key: nil, instream: $stdin) @bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') @key = key || ENV.fetch('CPI_FEED_AWS_KEY') @instream = instream end attr_reader :bucket, :key, :instream private :bucket, :key, :instream def put body = instream.read puts Aws::S3::Resource.new.bucket(bucket).object(key).put(body:) puts body puts Aws::S3::Client.new.put_object_acl( bucket:, key:, acl: 'public-read' ) end end if $PROGRAM_NAME == __FILE__ MiniS3put.new(key: ARGV.first).put exit 0 end