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, #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(name = nil, *args) ⇒ Object



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
# File 'lib/epc/command/config/update_config_command.rb', line 4

def execute(name = nil, *args )

  target = args[0]
  value = args[1]

  path = "."
  path = File.expand_path(path)

  @options[:required] = false if @options[:required].nil?

  config_type, config_id = extract_configuration_level(path, target)
  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("Configuration retrieval failed with [#{response[:message]}]")
    return status
  end

  keys = response

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

  params = {
    :name => name,
  }
  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("#{name} saved.")
    end
  else
    say("Request failed with message [#{response[:message]}]")
  end
  return status
end