rhc 1.5.13 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/features/application.feature +1 -1
  2. data/features/cartridge.feature +10 -9
  3. data/features/geared_application.feature +3 -6
  4. data/features/lib/rhc_helper/app.rb +2 -2
  5. data/features/multiple_cartridge.feature +9 -8
  6. data/features/scaled_application.feature +5 -5
  7. data/features/step_definitions/application_steps.rb +4 -3
  8. data/features/step_definitions/cartridge_steps.rb +8 -1
  9. data/features/support/before_hooks.rb +12 -6
  10. data/features/support/env.rb +8 -1
  11. data/features/support/platform_support.rb +29 -0
  12. data/lib/rhc/command_runner.rb +33 -21
  13. data/lib/rhc/commands/account.rb +1 -1
  14. data/lib/rhc/commands/alias.rb +90 -7
  15. data/lib/rhc/commands/app.rb +15 -11
  16. data/lib/rhc/commands/cartridge.rb +9 -2
  17. data/lib/rhc/exceptions.rb +6 -0
  18. data/lib/rhc/helpers.rb +3 -0
  19. data/lib/rhc/output_helpers.rb +12 -3
  20. data/lib/rhc/rest.rb +3 -0
  21. data/lib/rhc/rest/alias.rb +50 -0
  22. data/lib/rhc/rest/application.rb +26 -2
  23. data/lib/rhc/rest/cartridge.rb +16 -1
  24. data/lib/rhc/rest/client.rb +24 -4
  25. data/lib/rhc/rest/mock.rb +66 -2
  26. data/lib/rhc/ssh_helpers.rb +2 -3
  27. data/lib/rhc/wizard.rb +6 -3
  28. data/spec/rhc/assets/cert.crt +22 -0
  29. data/spec/rhc/assets/cert_key_rsa +27 -0
  30. data/spec/rhc/assets/empty.txt +0 -0
  31. data/spec/rhc/cli_spec.rb +5 -0
  32. data/spec/rhc/commands/account_spec.rb +6 -6
  33. data/spec/rhc/commands/alias_spec.rb +179 -5
  34. data/spec/rhc/commands/app_spec.rb +2 -1
  35. data/spec/rhc/commands/authorization_spec.rb +9 -0
  36. data/spec/rhc/commands/cartridge_spec.rb +27 -0
  37. data/spec/rhc/commands/setup_spec.rb +2 -0
  38. data/spec/rhc/commands/sshkey_spec.rb +20 -1
  39. data/spec/rhc/helpers_spec.rb +1 -2
  40. data/spec/rhc/rest_client_spec.rb +26 -5
  41. data/spec/rhc/wizard_spec.rb +22 -0
  42. data/spec/spec_helper.rb +25 -2
  43. data/spec/wizard_spec_helper.rb +1 -1
  44. metadata +153 -144
@@ -3,7 +3,7 @@ Feature: Application Operations
3
3
 
4
4
  @init
5
5
  Scenario: Application Creation
6
- When a php-5.3 application is created
6
+ When a php application is created
7
7
  Then the application should be accessible
8
8
 
9
9
  # The state in these examples should be able to be broken into before hooks when we update cucumber
@@ -10,12 +10,12 @@ Feature: Single Cartridge Tests
10
10
 
11
11
  Examples:
12
12
  | type | command | status |
13
- | mysql-5.1 | added | running |
13
+ | mysql | added | running |
14
14
 
15
15
  Scenario Outline: Cartridge Commands
16
- Given we have a <state> mysql-5.1 cartridge
17
- When the mysql-5.1 cartridge is <command>
18
- Then the mysql-5.1 cartridge should be <status>
16
+ Given we have a <state> mysql cartridge
17
+ When the mysql cartridge is <command>
18
+ Then the mysql cartridge should be <status>
19
19
 
20
20
  Examples:
21
21
  | state | command | status |
@@ -25,13 +25,14 @@ Feature: Single Cartridge Tests
25
25
 
26
26
  Scenario Outline: Cartridge List
27
27
  When we list cartridges
28
- Then the list should contain the cartridge <cart> with display name "<name>"
28
+ Then the list should contain the cartridge <cart> with display name
29
29
 
30
30
  Examples:
31
- | cart | name |
32
- | php-5.3 | PHP 5.3 |
33
- | mongodb-2.2 | MongoDB NoSQL |
34
- | cron-1.4 | Cron 1.4 |
31
+ | cart |
32
+ | php |
33
+ | mongodb |
34
+ | cron |
35
+
35
36
 
36
37
  # Commenting this out for US2438
37
38
  # Scenario Outline: Cartridge Storage
@@ -1,11 +1,8 @@
1
1
  @geared_application @geared_user_required @domain_required
2
2
  Feature: Scaled Application Operations
3
3
 
4
- @init
4
+ @init @not-origin
5
5
  Scenario: Geared Application Creation
6
- When a php-5.3 application is created with a medium gear
6
+ When a php application is created with a medium gear
7
7
  Then the application should be accessible
8
- Then the application should have a medium gear
9
-
10
-
11
-
8
+ Then the application should have a medium gear
@@ -118,7 +118,7 @@ module RHCHelper
118
118
 
119
119
  def get_index_file
120
120
  case @type
121
- when "php-5.3" then "php/index.php"
121
+ when "php-5.3","php-5.4" then "php/index.php"
122
122
  when "ruby-1.8" then "config.ru"
123
123
  when "python-2.6" then "wsgi/application"
124
124
  when "perl-5.10" then "perl/index.pl"
@@ -130,7 +130,7 @@ module RHCHelper
130
130
 
131
131
  def get_mysql_file
132
132
  case @type
133
- when "php-5.3" then File.expand_path("../misc/php/db_test.php", File.expand_path(File.dirname(__FILE__)))
133
+ when "php-5.3","php-5.4" then File.expand_path("../misc/php/db_test.php", File.expand_path(File.dirname(__FILE__)))
134
134
  end
135
135
  end
136
136
  end
@@ -3,15 +3,16 @@ Feature: Multiple Cartridge Tests
3
3
 
4
4
  @init
5
5
  Scenario: Supporting Cartridge Added
6
- Given an existing or new php-5.3 application with an embedded mysql-5.1 cartridge
7
- When the phpmyadmin-3.4 cartridge is added
8
- Then the phpmyadmin-3.4 cartridge should be running
6
+ Given an existing or new php application with an embedded mysql cartridge
7
+ When the phpmyadmin cartridge is added
8
+ Then the phpmyadmin cartridge should be running
9
9
 
10
+ @not-origin
10
11
  Scenario: Conflicting Cartridge Fails
11
- Then adding the postgresql-8.5 cartridge should fail
12
+ Then adding the postgresql cartridge should fail
12
13
 
13
14
  Scenario: Cartridge Removed
14
- When the phpmyadmin-3.4 cartridge is removed
15
- When the mysql-5.1 cartridge is removed
16
- Then the phpmyadmin-3.4 cartridge should be removed
17
- Then the mysql-5.1 cartridge should be removed
15
+ When the phpmyadmin cartridge is removed
16
+ When the mysql cartridge is removed
17
+ Then the phpmyadmin cartridge should be removed
18
+ Then the mysql cartridge should be removed
@@ -3,7 +3,7 @@ Feature: Scaled Application Operations
3
3
 
4
4
  @init
5
5
  Scenario: Scaled Application Creation
6
- When a scaled php-5.3 application is created
6
+ When a scaled php application is created
7
7
  Then the application should be accessible
8
8
  Then the application should be scalable
9
9
 
@@ -34,9 +34,9 @@ Feature: Scaled Application Operations
34
34
 
35
35
  Examples:
36
36
  | cart | type | value |
37
- | php-5.3 | min | 1 |
38
- | php-5.3 | max | 5 |
39
- | php-5.3 | max | -1 |
37
+ | php | min | 1 |
38
+ | php | max | 5 |
39
+ | php | max | -1 |
40
40
 
41
41
  Scenario Outline: Invalid Scaling Values
42
42
  When we are updating the <cart> cartridge
@@ -45,4 +45,4 @@ Feature: Scaled Application Operations
45
45
 
46
46
  Examples:
47
47
  | cart | type | value | code |
48
- | php-5.3 | min | a | 1 |
48
+ | php | min | a | 1 |
@@ -18,7 +18,7 @@ end
18
18
  # Use the transformed array so we can reuse this step for all combinations
19
19
  Given /^an existing (or new )?(scaled )?(.+) (application with.*)$/ do |create, scaled, type, embeds|
20
20
  options = { :type => type }
21
- options[:embed] = embeds if embeds
21
+ options[:embed] = embeds.map{ |c| map_cartridge_type(c) } if embeds
22
22
  options[:scalable] = scaled if scaled
23
23
  @app = App.find_on_fs(options)
24
24
 
@@ -51,7 +51,8 @@ When /^(\d+) (.+) applications are created$/ do |app_count, type|
51
51
  @app = old_app
52
52
  end
53
53
 
54
- When /^a (scaled )?(.+) application is created(?: with a (.*) gear)?$/ do |scaled, type, gear_profile|
54
+ When /^a (scaled )?(.+) application is created(?: with a (.*) gear)?$/ do |scaled, type, gear_profile|
55
+ type = map_cartridge_type(type)
55
56
  @app = App.create_unique(type, scaled, gear_profile)
56
57
  @app.rhc_app_create
57
58
  end
@@ -111,7 +112,7 @@ Then /^it should succeed$/ do
111
112
  end
112
113
 
113
114
  Then /^the application should be scalable/ do
114
- step "the haproxy-1.4 cartridge should be running"
115
+ step "the haproxy cartridge should be running"
115
116
  end
116
117
 
117
118
  Then /^the application should have a (.*) gear$/ do |gear_profile|
@@ -4,14 +4,17 @@ require 'rhc/config'
4
4
  include RHCHelper
5
5
 
6
6
  When /^the (.+) cartridge is added$/ do |name|
7
+ name = map_cartridge_type(name)
7
8
  @app.add_cartridge name
8
9
  end
9
10
 
10
11
  When /^the (.+) cartridge is removed$/ do |name|
12
+ name = map_cartridge_type(name)
11
13
  @app.remove_cartridge name
12
14
  end
13
15
 
14
16
  When /^the (.+) cartridge is (stopped|(?:re)?started)$/ do |name,command|
17
+ name = map_cartridge_type(name)
15
18
  cmd = case command.to_sym
16
19
  when :stopped
17
20
  'stop'
@@ -26,6 +29,7 @@ When /^the (.+) cartridge is (stopped|(?:re)?started)$/ do |name,command|
26
29
  end
27
30
 
28
31
  Then /^the (.+) cartridge should be (.*)$/ do |name,status|
32
+ name = map_cartridge_type(name)
29
33
  expected = case status.to_sym
30
34
  when :running
31
35
  "(.+) is running|Uptime:"
@@ -40,10 +44,12 @@ Then /^the (.+) cartridge should be (.*)$/ do |name,status|
40
44
  end
41
45
 
42
46
  Then /^adding the (.+) cartridge should fail$/ do |name|
47
+ name = map_cartridge_type(name)
43
48
  @app.add_cartridge(name).should == 154
44
49
  end
45
50
 
46
51
  When /^we are updating the (.+) cartridge$/ do |cart|
52
+ cart = map_cartridge_type(cart)
47
53
  @cartridge_name = cart
48
54
  end
49
55
 
@@ -81,7 +87,8 @@ Then /^it should fail with code (\d+)$/ do |code|
81
87
  @exitcode.should == code.to_i
82
88
  end
83
89
 
84
- Then /^the list should contain the cartridge ([^\s]+) with display name "([^"]+)"$/ do |name, display_name|
90
+ Then /^the list should contain the cartridge ([^\s]+) with display name$/ do |name|
91
+ display_name = map_cartridge_name(name)
85
92
  line = @cartridge_output.each_line.find{ |s| s.include?(name) }
86
93
  line.should_not be_nil
87
94
  line.should match(display_name)
@@ -18,6 +18,12 @@ Before('@geared_user_required') do
18
18
  $namespace = nil
19
19
  end
20
20
 
21
+ Before('@certificates_capable_user_required') do
22
+ $old_username = $username
23
+ $username = "user_with_certificate_capabilities@test.com"
24
+ $namespace = nil
25
+ end
26
+
21
27
  After do
22
28
  if $old_username
23
29
  $username = $old_username
@@ -42,19 +48,19 @@ Before('@client_tools_required') do
42
48
  end
43
49
 
44
50
  Before('@single_cartridge','@init') do
45
- step 'an existing or new php-5.3 application without an embedded cartridge'
51
+ step "an existing or new php application without an embedded cartridge"
46
52
  end
47
53
 
48
54
  # These assumptions help to ensure any steps that are run independently have the same state as after the @init step
49
55
  {
50
- :application => 'an existing or new php-5.3 application without an embedded cartridge',
51
- :scaled_application => 'an existing or new scaled php-5.3 application without an embedded cartridge',
56
+ :application => "an existing or new php application without an embedded cartridge",
57
+ :scaled_application => "an existing or new scaled php application without an embedded cartridge",
52
58
  :domain => 'we have an existing domain',
53
59
  :client => 'we have the client tools setup',
54
- :single_cartridge => 'an existing or new php-5.3 application with an embedded mysql-5.1 cartridge',
55
- :multiple_cartridge => 'an existing or new php-5.3 application with embedded mysql-5.1 and phpmyadmin-3.4 cartridges',
60
+ :single_cartridge => "an existing or new php application with an embedded mysql cartridge",
61
+ :multiple_cartridge => "an existing or new php application with embedded mysql and phpmyadmin cartridges",
56
62
  }.each do |tag,assumption|
57
63
  Before("@#{tag}",'~@init') do
58
64
  step assumption
59
65
  end
60
- end
66
+ end
@@ -70,7 +70,14 @@ raise "Password not found in environment (RHC_PASSWORD)" unless $password
70
70
  $user_register_script_format = "oo-register-user -l admin -p admin --username %s --userpass %s"
71
71
  if ENV['REGISTER_USER']
72
72
  command = $user_register_script_format % [$username,$password]
73
- %x[#{command}]
73
+ if Object.const_defined?('Bundler')
74
+ Bundler::with_clean_env do
75
+ system "gem install activeresource bundler parseconfig --no-ri --no-rdoc"
76
+ system command
77
+ end
78
+ else
79
+ system command
80
+ end
74
81
  end
75
82
 
76
83
  def _log(msg)
@@ -0,0 +1,29 @@
1
+ if File.exist?("/etc/fedora-release")
2
+ CARTRIDGE_MAP = {
3
+ "php" => { type: "php-5.4", name: "PHP 5.4" },
4
+ "mysql" => { type: "mysql-5.1", name: "MySQL Database 5.1" },
5
+ "phpmyadmin" => { type: "phpmyadmin-3.5", name: "phpMyAdmin 3.5" },
6
+ "mongodb" => { type: "mongodb-2.2", name: "MongoDB NoSQL Database 2.2" },
7
+ "postgresql" => { type: "postgresql-9.2", name: "PostgreSQL Database 9.2" },
8
+ "cron" => { type: "cron-1.4", name: "Cron 1.4" },
9
+ "haproxy" => { type: "haproxy-1.4", name: "" }
10
+ }
11
+ else
12
+ CARTRIDGE_MAP = {
13
+ "php" => { type: "php-5.3", name: "PHP 5.3" },
14
+ "mysql" => { type: "mysql-5.1", name: "MySQL Database 5.1" },
15
+ "phpmyadmin" => { type: "phpmyadmin-3.4", name: "phpMyAdmin 3.4" },
16
+ "mongodb" => { type: "mongodb-2.2", name: "MongoDB NoSQL Database 2.2" },
17
+ "postgresql" => { type: "postgresql-8.4", name: "PostgreSQL Database 8.4" },
18
+ "cron" => { type: "cron-1.4", name: "Cron 1.4" },
19
+ "haproxy" => { type: "haproxy-1.4", name: "" }
20
+ }
21
+ end
22
+
23
+ def map_cartridge_type(type)
24
+ CARTRIDGE_MAP[type][:type]
25
+ end
26
+
27
+ def map_cartridge_name(type)
28
+ CARTRIDGE_MAP[type][:name]
29
+ end
@@ -29,6 +29,16 @@ module RHC
29
29
  end
30
30
  end
31
31
 
32
+ HELP_OPTIONS = ['--help', '-h']
33
+
34
+ def options_parse_help
35
+ if (@args & HELP_OPTIONS).present?
36
+ args = (@args -= HELP_OPTIONS)
37
+ args.shift if args.first == 'help' && !command_exists?(args.join(' '))
38
+ exit run_help(args, nil)
39
+ end
40
+ end
41
+
32
42
  # override so we can do our own error handling
33
43
  def run!
34
44
  trace = false
@@ -36,12 +46,8 @@ module RHC
36
46
  #trap('INT') { abort program(:int_message) } if program(:int_message)
37
47
  #trap('INT') { program(:int_block).call } if program(:int_block)
38
48
 
39
- global_option('-h', '--help', 'Help on any command', :hide => true) do
40
- args = @args - %w[-h --help]
41
- command(:help).run(*args)
42
- return
43
- end
44
- global_option('--version', 'Display version information', :hide => true) { say version; return }
49
+ global_option('-h', '--help', 'Help on any command', :hide => true)
50
+ global_option('--version', 'Display version information', :hide => true)
45
51
 
46
52
  # remove these because we monkey patch Commands to process all options
47
53
  # at once, avoiding conflicts between the global and command options
@@ -56,6 +62,9 @@ module RHC
56
62
  # special case --version so it is processed before an invalid command
57
63
  options_parse_version
58
64
 
65
+ # help is a special branch prior to command execution
66
+ options_parse_help
67
+
59
68
  unless trace
60
69
  begin
61
70
  run_active_command
@@ -110,7 +119,6 @@ module RHC
110
119
 
111
120
  def create_default_commands
112
121
  command 'help options' do |c|
113
- # c.syntax = ''
114
122
  c.description = "Display all global options and information about configuration"
115
123
  c.when_called do |args, options|
116
124
  say help_formatter.render_options self
@@ -119,21 +127,25 @@ module RHC
119
127
  command :help do |c|
120
128
  c.syntax = '<command>'
121
129
  c.description = 'Display global or <command> help documentation.'
122
- c.when_called do |args, options|
123
- cmd = (1..args.length).reverse_each.map{ |n| args[0,n].join(' ') }.find{ |cmd| command_exists?(cmd) }
130
+ c.when_called(&method(:run_help))
131
+ end
132
+ end
124
133
 
125
- if args.empty?
126
- say help_formatter.render
127
- elsif cmd.nil?
128
- RHC::Helpers.error "The command '#{program :name} #{provided_arguments.join(' ')}' is not recognized.\n"
129
- say "See '#{program :name} help' for a list of valid commands."
130
- next
131
- else
132
- command = command(cmd)
133
- help_bindings = CommandHelpBindings.new command, commands, self
134
- say help_formatter.render_command help_bindings
135
- end
136
- end
134
+ def run_help(args, options)
135
+ cmd = (1..args.length).reverse_each.map{ |n| args[0,n].join(' ') }.find{ |cmd| command_exists?(cmd) }
136
+
137
+ if args.empty?
138
+ say help_formatter.render
139
+ 0
140
+ elsif cmd.nil?
141
+ RHC::Helpers.error "The command '#{program :name} #{provided_arguments.join(' ')}' is not recognized.\n"
142
+ say "See '#{program :name} help' for a list of valid commands."
143
+ 1
144
+ else
145
+ command = command(cmd)
146
+ help_bindings = CommandHelpBindings.new command, commands, self
147
+ say help_formatter.render_command help_bindings
148
+ 0
137
149
  end
138
150
  end
139
151
  end
@@ -12,7 +12,7 @@ module RHC::Commands
12
12
  def run
13
13
  user = rest_client.user
14
14
 
15
- say_table nil, get_properties(user, :login, :plan_id, :consumed_gears, :max_gears) + get_properties(user.capabilities, :gear_sizes).unshift(['Server', openshift_server]), :delete => true
15
+ say_table nil, get_properties(user, :login, :plan_id, :consumed_gears, :max_gears) + get_properties(user.capabilities, :gear_sizes).unshift(['Server:', openshift_server]) << ['SSL Certificates Supported:', user.capabilities.private_ssl_certificates ? 'yes' : 'no'], :delete => true
16
16
 
17
17
  if openshift_online_server?
18
18
  else
@@ -3,34 +3,117 @@ require 'rhc/config'
3
3
 
4
4
  module RHC::Commands
5
5
  class Alias < Base
6
- summary "Add or remove a custom domain name for the application"
6
+ summary "Add or remove a custom domain name (alias) for the application"
7
7
  syntax "<command> <application> <alias> [--namespace namespace]"
8
8
  default_action :help
9
9
 
10
10
  summary "Add a custom domain name for the application"
11
11
  syntax "<application> <alias> [--namespace namespace]"
12
- argument :app, "Application name (required)", []
12
+ argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
13
13
  argument :app_alias, "Custom domain name for the application", []
14
14
  option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
15
15
  alias_action :"app add-alias", :root_command => true, :deprecated => true
16
16
  def add(app, app_alias)
17
17
  rest_app = rest_client.find_application(options.namespace, app)
18
- response = rest_app.add_alias(app_alias)
19
- results { say response.messages.first } if response.messages
18
+ rest_app.add_alias(app_alias)
19
+ results { say "Alias '#{app_alias}' has been added." }
20
20
  0
21
21
  end
22
22
 
23
23
  summary "Remove a custom domain name for the application"
24
24
  syntax "<application> <alias> [--namespace namespace]"
25
- argument :app, "Application name (required)", []
25
+ argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
26
26
  argument :app_alias, "Custom domain name for the application", []
27
27
  option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
28
28
  alias_action :"app remove-alias", :root_command => true, :deprecated => true
29
29
  def remove(app, app_alias)
30
30
  rest_app = rest_client.find_application(options.namespace, app)
31
- response = rest_app.remove_alias(app_alias)
32
- results { say response.messages.first } if response.messages
31
+ rest_app.remove_alias(app_alias)
32
+ results { say "Alias '#{app_alias}' has been removed." }
33
33
  0
34
34
  end
35
+
36
+ summary "Add or change the SSL certificate for an existing alias"
37
+ description <<-DESC
38
+ Add or update the SSL certificate for your custom domain alias to
39
+ allow secure HTTPS communication with your app.
40
+
41
+ Certificate files must be Base64 PEM-encoded and typically have a
42
+ .crt or .pem extension. You may combine multiple certificates and
43
+ certificate chains in a single file. The RSA or DSA private key
44
+ must always be provided in a separate file.
45
+
46
+ Pass phrase for the certificate private key is required if the
47
+ provided private key is encrypted.
48
+ DESC
49
+ syntax "<application> <alias> --certificate FILE --private-key FILE [--passphrase passphrase]"
50
+ argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
51
+ argument :app_alias, "Custom domain name for the application (required)", []
52
+ option ["--certificate FILE"], "SSL certificate filepath (file in .crt or .pem format)", :required => true
53
+ option ["--private-key FILE"], "Private key filepath for the given SSL certificate", :required => true
54
+ option ["--passphrase passphrase"], "Private key pass phrase, required if the private key is encripted", :required => false
55
+ option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
56
+ def update_cert(app, app_alias)
57
+ certificate_file_path = options.certificate
58
+ raise ArgumentError, "Certificate file not found: #{certificate_file_path}" if !File.exist?(certificate_file_path) || !File.file?(certificate_file_path)
59
+
60
+ private_key_file_path = options.private_key
61
+ raise ArgumentError, "Private key file not found: #{private_key_file_path}" if !File.exist?(private_key_file_path) || !File.file?(private_key_file_path)
62
+
63
+ certificate_content = File.read(certificate_file_path)
64
+ raise ArgumentError, "Invalid certificate file: #{certificate_file_path} is empty" if certificate_content.to_s.strip.length == 0
65
+
66
+ private_key_content = File.read(private_key_file_path)
67
+ raise ArgumentError, "Invalid private key file: #{private_key_file_path} is empty" if private_key_content.to_s.strip.length == 0
68
+
69
+ rest_app = rest_client.find_application(options.namespace, app)
70
+ rest_alias = rest_app.find_alias(app_alias)
71
+ if rest_client.api_version_negotiated >= 1.4
72
+ rest_alias.add_certificate(certificate_content, private_key_content, options.passphrase)
73
+ results { say "SSL certificate successfully added." }
74
+ 0
75
+ else
76
+ raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
77
+ end
78
+ end
79
+
80
+ summary "Delete the SSL certificate from an existing alias"
81
+ syntax "<application> <alias>"
82
+ argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
83
+ argument :app_alias, "Custom domain name for the application (required)", []
84
+ option ["--confirm"], "Pass to confirm deleting the application"
85
+ option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
86
+ def delete_cert(app, app_alias)
87
+ rest_app = rest_client.find_application(options.namespace, app)
88
+ rest_alias = rest_app.find_alias(app_alias)
89
+ if rest_client.api_version_negotiated >= 1.4
90
+ confirm_action "#{color("This is a non-reversible action! Your SSL certificate will be permanently deleted from application '#{app}'.", :yellow)}\n\nAre you sure you want to delete the SSL certificate?"
91
+ rest_alias.delete_certificate
92
+ results { say "SSL certificate successfully deleted." }
93
+ 0
94
+ else
95
+ raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
96
+ end
97
+ end
98
+
99
+ summary "List the aliases on an application"
100
+ syntax "<application>"
101
+ argument :app, "Application name (required)", ["-a", "--app name"], :context => :app_context, :required => true
102
+ option ["-n", "--namespace namespace"], "Namespace of your application", :context => :namespace_context, :required => true
103
+ def list(app)
104
+ rest_app = rest_client.find_application(options.namespace, app)
105
+ items = rest_app.aliases.map do |a|
106
+ a.is_a?(String) ?
107
+ [a, 'no', '-'] :
108
+ [a.id, a.has_private_ssl_certificate? ? 'yes' : 'no', a.has_private_ssl_certificate? ? Date.parse(a.certificate_added_at) : '-']
109
+ end
110
+ if items.empty?
111
+ results { say "No aliases associated with the application #{app}." }
112
+ else
113
+ table(items, :header => ["Alias", "Has Certificate?", "Certificate Added"]).each { |s| say s }
114
+ end
115
+ 0
116
+ end
117
+
35
118
  end
36
119
  end