Class: Belt::CLI::EnvironmentConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/belt/cli/environment_config.rb

Defined Under Namespace

Classes: BackupDSL, ConfigDSL, ConfigEvaluator, EnvDSL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnvironmentConfig

Returns a new instance of EnvironmentConfig.



22
23
24
25
26
# File 'lib/belt/cli/environment_config.rb', line 22

def initialize
  @aws_profile = nil
  @env_vars = {}
  @backup_config = BackupConfig.new
end

Instance Attribute Details

#aws_profileObject (readonly)

Returns the value of attribute aws_profile.



6
7
8
# File 'lib/belt/cli/environment_config.rb', line 6

def aws_profile
  @aws_profile
end

#backup_configObject (readonly)

Returns the value of attribute backup_config.



6
7
8
# File 'lib/belt/cli/environment_config.rb', line 6

def backup_config
  @backup_config
end

#env_varsObject (readonly)

Returns the value of attribute env_vars.



6
7
8
# File 'lib/belt/cli/environment_config.rb', line 6

def env_vars
  @env_vars
end

Class Method Details

.load(env, infra_dir: nil) ⇒ Object

Load environment config from infrastructure//belt.rb Returns an EnvironmentConfig instance (never nil — unconfigured is valid)



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/belt/cli/environment_config.rb', line 10

def self.load(env, infra_dir: nil)
  infra_dir ||= 'infrastructure'
  config_file = File.join(infra_dir, env, 'belt.rb')

  config = new
  return config unless File.exist?(config_file)

  evaluator = ConfigEvaluator.new(config)
  evaluator.evaluate(File.read(config_file), config_file)
  config
end

Instance Method Details

#apply!Object

Apply the configured aws_profile and env vars to the current process. Call this before running terraform, aws cli, etc.



42
43
44
45
# File 'lib/belt/cli/environment_config.rb', line 42

def apply!
  ENV['AWS_PROFILE'] = @aws_profile if aws_profile?
  @env_vars.each { |key, value| ENV[key] = value }
end

#aws_profile?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/belt/cli/environment_config.rb', line 28

def aws_profile?
  !@aws_profile.nil? && !@aws_profile.empty?
end

#backups?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/belt/cli/environment_config.rb', line 36

def backups?
  @backup_config.any?
end

#env_vars?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/belt/cli/environment_config.rb', line 32

def env_vars?
  @env_vars.any?
end