class RHC::Commands::Alias

Public Instance Methods

add(app, app_alias) click to toggle source
# File lib/rhc/commands/alias.rb, line 24
def add(app, app_alias)
  rest_app = find_app
  rest_app.add_alias(app_alias)
  success "Alias '#{app_alias}' has been added."
  0
end
delete_cert(app, app_alias) click to toggle source
# File lib/rhc/commands/alias.rb, line 91
def delete_cert(app, app_alias)
  rest_app = find_app
  rest_alias = rest_app.find_alias(app_alias)
  if rest_client.api_version_negotiated >= 1.4
    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?"
    rest_alias.delete_certificate
    success "SSL certificate successfully deleted."
    0
  else
    raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
  end
end
list(app) click to toggle source
# File lib/rhc/commands/alias.rb, line 108
def list(app)
  rest_app = find_app
  items = rest_app.aliases.map do |a|
    a.is_a?(String) ?
      [a, 'no', '-'] :
      [a.id, a.has_private_ssl_certificate? ? 'yes' : 'no', a.has_private_ssl_certificate? ? Date.parse(a.certificate_added_at) : '-']
  end
  if items.empty?
    info "No aliases associated with the application #{app}."
  else
    say table(items, :header => ["Alias", "Has Certificate?", "Certificate Added"])
  end
  0
end
remove(app, app_alias) click to toggle source
# File lib/rhc/commands/alias.rb, line 36
def remove(app, app_alias)
  rest_app = find_app
  rest_app.remove_alias(app_alias)
  success "Alias '#{app_alias}' has been removed."
  0
end
update_cert(app, app_alias) click to toggle source
# File lib/rhc/commands/alias.rb, line 62
def update_cert(app, app_alias)
  certificate_file_path = options.certificate
  raise ArgumentError, "Certificate file not found: #{certificate_file_path}" if !File.exist?(certificate_file_path) || !File.file?(certificate_file_path)

  private_key_file_path = options.private_key
  raise ArgumentError, "Private key file not found: #{private_key_file_path}" if !File.exist?(private_key_file_path) || !File.file?(private_key_file_path)

  certificate_content = File.read(certificate_file_path)
  raise ArgumentError, "Invalid certificate file: #{certificate_file_path} is empty" if certificate_content.to_s.strip.length == 0

  private_key_content = File.read(private_key_file_path)
  raise ArgumentError, "Invalid private key file: #{private_key_file_path} is empty" if private_key_content.to_s.strip.length == 0

  rest_app = find_app
  rest_alias = rest_app.find_alias(app_alias)
  if rest_client.api_version_negotiated >= 1.4
    rest_alias.add_certificate(certificate_content, private_key_content, options.passphrase)
    success "SSL certificate successfully added."
    0
  else
    raise RHC::Rest::SslCertificatesNotSupported, "The server does not support SSL certificates for custom aliases."
  end
end