Class: EPC::Command::DeleteConfigCommand

Inherits:
DeleteCommand show all
Defined in:
lib/epc/command/config/delete_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
# File 'lib/epc/command/config/delete_config_command.rb', line 4

def execute(args = [])

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

  config_type, config_id = extract_configuration_level(path, [target_type, target_id])
  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)

  raise FatalError, "Configuration retrieval failed with [#{response[:message]}]" if status.failure?

  existing_keys = response

  if existing_keys.empty?
    say("There are no configurations defined for this project.")
    return 1
  end

  key_id = existing_keys.detect{|k| k[:name] == key }[:id] rescue nil
  if key_id.nil?
    say_err("#{key} is not defined.")
    return 1
  end

  question = "Are you sure you want to delete the config value [#{key}] defined on [#{config_type}-#{config_id}"
  if ["solution", "project"].include?(config_type.downcase) && !@options[:stage].nil?
    question += "-#{@options[:stage]}"
  end

  question += "]. Correct? [Yn] "

  proceed = ask_yn(question)
  if proceed.upcase == 'N'
    return 1
  end

  status, response, headers = client.delete(EPC::Config::CONFIGURATIONS_PATH + "/#{key_id}")
  if status.successful?
    say("#{key} succesfully removed.")
  else
    say_err("Request failed: [#{response[:message]}]")
  end
  return status

end