Sha256: 52138df8e4f24a5002bccfc7cb0a38a2cd54048bb881af3905d95c19cc15036d

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

require "fog"
require "log4r"

module VagrantPlugins
  module AWS
    module Action
      # This action connects to AWS, verifies credentials work, and
      # puts the AWS connection object into the `:aws_compute` key
      # in the environment.
      class ConnectAWS
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant_aws::action::connect_aws")
        end

        def call(env)
          # Get the region we're going to booting up in
          region = env[:machine].provider_config.region

          # Get the configs
          region_config = env[:machine].provider_config.get_region_config(region)

          # Build the fog config
          fog_config = {
            :provider => :aws,
            :region   => region
          }
          if region_config.use_iam_profile
            fog_config[:use_iam_profile] = true
          else
            fog_config[:aws_access_key_id] = region_config.access_key_id
            fog_config[:aws_secret_access_key] = region_config.secret_access_key
            fog_config[:aws_session_token] = region_config.session_token
          end

          fog_config[:endpoint] = region_config.endpoint if region_config.endpoint
          fog_config[:version]  = region_config.version if region_config.version

          @logger.info("Connecting to AWS...")
          env[:aws_compute] = Fog::Compute.new(fog_config)
          env[:aws_elb]     = Fog::AWS::ELB.new(fog_config.except(:provider, :endpoint))

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
vagrant-aws-iam-decoder-0.7.2 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-mkubenka-0.7.2.pre.14 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-mkubenka-0.7.2.pre.11 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-mkubenka-0.7.2.pre.10 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-mkubenka-0.7.2.pre.9 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-mkubenka-0.7.2.pre.8 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-0.7.2 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-0.7.1 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-0.7.0 lib/vagrant-aws/action/connect_aws.rb
vagrant-aws-0.6.0 lib/vagrant-aws/action/connect_aws.rb