Module: EY::Metadata::Outsider

Defined in:
lib/engineyard-metadata/outsider.rb

Overview

This gets pulled in when you’re running from your developer machine (i.e., not on a cloud instance).

Constant Summary collapse

UNGETTABLE =
METHODS.grep(/present/) + METHODS.grep(/password/) + METHODS.grep(/mysql/)
GETTABLE =
METHODS - UNGETTABLE - %w{ environment_name }

Instance Method Summary collapse

Instance Method Details

#app_nameObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/engineyard-metadata/outsider.rb', line 32

def app_name
  return @app_name if @app_name.is_a?(String)
  if ENV['EY_APP_NAME']
    @app_name = ENV['EY_APP_NAME']
  elsif engine_yard_cloud_api.possible_to_detect_app_from_environment_name?
    @app_name = engine_yard_cloud_api.app_name
  elsif engine_yard_cloud_api.possible_to_detect_app_from_git_config?
    @app_name = engine_yard_cloud_api.app_name
  end
  @app_name
end

#engine_yard_cloud_apiObject

An adapter that reads from the public EngineYard Cloud API (cloud.engineyard.com)



84
85
86
# File 'lib/engineyard-metadata/outsider.rb', line 84

def engine_yard_cloud_api
  @engine_yard_cloud_api ||= EngineYardCloudApi.new ey_cloud_token
end

#environment_nameObject

The name of the EngineYard AppCloud environment.

Raises:

  • (RuntimeError)


54
55
56
57
58
59
60
61
62
63
# File 'lib/engineyard-metadata/outsider.rb', line 54

def environment_name
  return @environment_name if @environment_name.is_a? String
  if ENV['EY_ENVIRONMENT_NAME']
    @environment_name = ENV['EY_ENVIRONMENT_NAME']
  elsif engine_yard_cloud_api.possible_to_detect_environment_from_git_config?
    @environment_name = engine_yard_cloud_api.environment_name
  end
  raise RuntimeError, "[engineyard-metadata gem] You need to run this from the application repo, set EY.metadata.environment_name= or set ENV['EY_ENVIRONMENT_NAME']" unless @environment_name.to_s.strip.length > 0
  @environment_name
end

#environment_name=(str) ⇒ Object

Sets the environment you want, in case it can’t be detected from ENV or .git/config



49
50
51
# File 'lib/engineyard-metadata/outsider.rb', line 49

def environment_name=(str)
  @environment_name = str
end

#ey_cloud_tokenObject

The secret API token to access cloud.engineyard.com

Raises:

  • (RuntimeError)


72
73
74
75
76
77
78
79
80
81
# File 'lib/engineyard-metadata/outsider.rb', line 72

def ey_cloud_token
  return @ey_cloud_token if @ey_cloud_token.is_a? String
  if ENV['EY_CLOUD_TOKEN']
    @ey_cloud_token = ENV['EY_CLOUD_TOKEN']
  elsif File.exist? eyrc_path
    @ey_cloud_token = YAML.load(File.read(eyrc_path))['api_token']
  end
  raise RuntimeError, "[engineyard-metadata gem] You need to have #{eyrc_path}, set EY.metadata.ey_cloud_token= or set ENV['EY_CLOUD_TOKEN']" unless @ey_cloud_token.to_s.strip.length > 0
  @ey_cloud_token
end

#ey_cloud_token=(str) ⇒ Object

Sets the (secret) cloud token, in case it’s not in ENV or ~/.eyrc



66
67
68
69
# File 'lib/engineyard-metadata/outsider.rb', line 66

def ey_cloud_token=(str)
  @engine_yard_cloud_api = nil # because it depends on cloud token
  @ey_cloud_token = str
end

#eyrc_pathObject



24
25
26
# File 'lib/engineyard-metadata/outsider.rb', line 24

def eyrc_path
  File.join File.expand_path("~#{Etc.getpwuid.name}"), '.eyrc'
end

#preset_app_name?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/engineyard-metadata/outsider.rb', line 28

def preset_app_name?
  @app_name.is_a?(String) or ENV['EY_APP_NAME']
end

#preset_environment_name?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/engineyard-metadata/outsider.rb', line 44

def preset_environment_name?
  @environment_name.is_a?(String) or ENV['EY_ENVIRONMENT_NAME']
end