Class: EPC::Command::CreateConfigCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/config/create_config_command.rb

Constant Summary collapse

CONFIG_LEVELS =
{
  :org => "Organization",
  :runtime => "RuntimeEnv",
  :stage => "DeploymentStage",
  :solution => "Solution",
  :project => "Project",
  :user => "User"
}

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(args = []) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/epc/command/config/create_config_command.rb', line 12

def execute(args = [])
  raise FatalError, "You have to specify a key and its value." if args.empty? && @options[:file].nil?

  path = File.expand_path(".")
  
  @options[:value_type] = "text" if @options[:value_type].nil?
  @options[:required] = false if @options[:required].nil?

  config_type, config_id = extract_configuration_level(path, [target_type, target_id])

  raise InputError, "Config type invalid. Must be one of: [#{CONFIG_LEVELS.values.join(",")}]" if config_type.blank?

  raise InputError, "Configuration context could not be determined" if config_id.blank?

  params = []
  if @options[:file].present?
    params = parse_config_value_file(@options[:file], config_type, config_id) 
  else
    args.each do |arg|
      name, value = arg.split("=")
      params << {:name => name, :value => value, :value_type => @options[:value_type], :configurable_id => config_id, :configurable_type => config_type, :required => options[:required], :no_override => @options[:no_override]}
      if ["solution", "project"].include?(config_type.downcase) && @options[:stage].present?
        params.last[:stage_name] = @options[:stage]
      end
    end
  end

  raise FatalError, "You must specify at least one config value" if params.nil? || params.empty?

  status, response, headers = client.post(EPC::Config::CONFIGURATIONS_PATH, {:config_values => params})

  if status.successful?
    say("Configuration values saved.")
  else
    say_err("Request failed with message [#{response[:message]}]")
  end
  return status
end