Sha256: 22cbc773d5db3f3613c9240b1caff4e5a84e6f5cadecf59081a0fbb7b0b5ccdc

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require "engineyard"
require "engineyard/thor"
require "engineyard/cli"
require "engineyard/cli/ui"
require "engineyard/error"
module Engineyard
  module Hudson
    class AppcloudEnv
      include EY::UtilityMethods
      
      # Returns [environment, account] based on current .eyrc credentials and/or CLI options
      # Returns [nil, nil] if no unique environment can be selected
      def find_environments(options = {})
        Thor::Base.shell = EY::CLI::UI
        EY.ui = EY::CLI::UI.new
        query_environments = options[:environment] ? [options[:environment]] : default_query_environments
        query_environments.inject([]) do |envs, env_name|
          begin
            if environment = fetch_environment(env_name, options[:account])
              clean_host_name(environment)
              envs << [env_name, environment.account.name, environment]
            end
          rescue EY::NoEnvironmentError
          rescue EY::MultipleMatchesError => e
            # e.message looks something like:
            # Multiple environments possible, please be more specific:
            # 
            #   hudson # ey <command> --environment='hudson' --account='drnic-demo'
            #   hudson # ey <command> --environment='hudson' --account='rails-hudson'
            e.message.scan(/--environment='([^']+)' --account='([^']+)'/) do
              envs << [$1, $2, nil]
            end
          end
          envs
        end
      end
      
      def default_query_environments
        %w[hudson hudson_server hudson_production hudson_server_production]
      end
      
      # Currently the engineyard gem has badly formed URLs in its same data
      # This method cleans app_master_hostname.compute-1.amazonaws.com -> app-master-hostname.compute-1.amazonaws.com
      def clean_host_name(environment)
        environment.instances.first.public_hostname.gsub!(/_/,'-') if environment.instances.first
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
engineyard-hudson-0.3.2 lib/engineyard-hudson/appcloud_env.rb
engineyard-hudson-0.3.1 lib/engineyard-hudson/appcloud_env.rb
engineyard-hudson-0.3.0 lib/engineyard-hudson/appcloud_env.rb