Sha256: 1b52b1c2d13fd052b1f48bfa5a26743826aa46276a44566222979c4985166fbe

Contents?: true

Size: 913 Bytes

Versions: 2

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

require "aws-sdk"
require "pathname"

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,
          config.version,
          key
        ].join("/")
      end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aws_as_code-1.0.6 lib/aws_as_code/task/upload.rb
aws_as_code-1.0.5 lib/aws_as_code/task/upload.rb