Sha256: 78819514d131952a8e6c76458cce3420fb44a99777f79c0e27ac5d4fbb4c17e8

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

module AwsEc2
  class Profile
    include TemplateHelper

    def initialize(options)
      @options = options
    end

    def load
      return @profile_params if @profile_params

      check!

      @profile_params = load_profile(profile_file)
    end

    def check!
      return if File.exist?(profile_file)

      puts "Unable to find a #{profile_file.colorize(:green)} profile file."
      puts "Please double check that it exists or that you specified the right profile."
      exit # EXIT HERE
    end

    def load_profile(file)
      return {} unless File.exist?(file)

      puts "Using profile: #{file}"
      data = YAML.load(erb_result(file))
      data ? data : {} # in case the file is empty
      data.has_key?("run_instances") ? data["run_instances"] : data
    end

    def profile_file
      "#{AwsEc2.root}/profiles/#{profile_name}.yml"
    end

    def profile_name
      # allow user to specify the path also
      if @options[:profile] && File.exist?(@options[:profile])
        profile = File.basename(@options[:profile], '.yml')
      end

      # conventional profile is the name of the ec2 instance
      profile || @options[:profile] || "default"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
aws-ec2-0.8.4 lib/aws_ec2/profile.rb
aws-ec2-0.8.3 lib/aws_ec2/profile.rb
aws-ec2-0.8.2 lib/aws_ec2/profile.rb
aws-ec2-0.8.1 lib/aws_ec2/profile.rb
aws-ec2-0.8.0 lib/aws_ec2/profile.rb
aws-ec2-0.7.0 lib/aws_ec2/profile.rb