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 => "RuntimeEnvironment",
  :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, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, required_options

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(target, *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
50
51
52
53
# File 'lib/epc/command/config/create_config_command.rb', line 12

def execute(target, *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)

  raise FatalError, "You need to specify a config type" if config_type.blank?

  params = []
  if @options[:file].present?
    params = EPC::Config.read_content_as_json(@options[:file])
    params.each do |param|
      if param[:configurable_type].nil? || param[:configurable_id].nil?
        param[:configurable_type] = config_type
        param[:configurable_id] = config_id
      end
    end
  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("Request failed with message [#{response[:message]}]")
  end
  return status
end