Sha256: 069857f6b107fafe1639bffdc47bb7d7dbc00686368c5fccef1a713d740202b5

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

require "aws-sdk"
require "pathname"

# frozen_string_literal: true
module AwsAsCode
  module Task
    class Upload < Base
      def execute
        input_files.each { |filename| upload_single_file filename }
      end

      private

      def upload_single_file(filename)
        bucket
          .object(s3_object_name(filename))
          .upload_file filename
      end

      def bucket
        s3 = Aws::S3::Resource.new
        s3.bucket config.bucket
      end

      def s3_object_name(filename)
        template_path = Pathname.new filename
        config_path = Pathname.new config.json_dir

        key = template_path
              .relative_path_from(config_path)
              .to_s

        [config.stack, key].join("/")
      end

      def input_files
        Dir.glob File.join(config.json_dir, "**/*.json")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aws_as_code-1.0.1 lib/aws_as_code/task/upload.rb