Class: EPC::Command::UpdateConfigCommand

Inherits:
UpdateCommand show all
Defined in:
lib/epc/command/config/update_config_command.rb

Constant Summary

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:



4
5
6
7
8
9
10
11
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
54
55
# File 'lib/epc/command/config/update_config_command.rb', line 4

def execute(args)

  value = args[0]
  path = File.expand_path(".")

  @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: [#{CreateConfigCommand::CONFIG_LEVELS.values.join(",")}]" if config_type.blank?
  raise InputError, "Configuration context could not be determined" if config_id.blank?

  request_path = EPC::Config::CONFIGURATIONS_PATH+"/#{config_type}/#{config_id}"

  if ["solution", "project"].include?(config_type.downcase) && !@options[:stage].nil?
    request_path += "/#{@options[:stage]}"
  end

  status, response, headers = client.get(request_path)

  if status.failure? 
    say_err("Configuration retrieval failed with [#{response[:message]}]")
    return status
  end

  keys = response

  key_id = keys.detect{|k| k[:name] == object_id}[:id] rescue nil
  
  if key_id.nil?
    say_err("Key does not exist.") 
    return 1
  end

  params = {
    :name => object_id,
  }
  params[:value] = value unless value.nil?
  params[:required] = @options[:required]
  params[:no_override] = @options[:no_override] unless @options[:no_override].nil?

  status, response, headers = client.put(EPC::Config::CONFIGURATIONS_PATH + "/#{key_id}", params)

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