lib/shelly/cli/endpoint.rb in shelly-0.4.42 vs lib/shelly/cli/endpoint.rb in shelly-0.5.0

- old
+ new

@@ -32,11 +32,10 @@ "| #{print_check(endpoint['sni'])}" ] end print_table(to_display, :ident => 2) - else say "No HTTP endpoints available" end end @@ -79,10 +78,22 @@ :desc => "Create SNI endpoint" def create(cert_path = nil, key_path = nil, bundle_path = nil) app = multiple_clouds(options[:cloud], "endpoint create [CERT_PATH] [KEY_PATH] [BUNDLE_PATH]") + say "Every unique IP address assigned to endpoint costs 10€/month" + say "It's required for SSL/TLS" + if cert_path == nil && key_path == nil + say "You didn't provide certificate but it can be added later" + say "Assigned IP address can be used to catch all domains pointing to that address, without SSL/TLS enabled" + exit(0) unless yes?("Are you sure you want to create endpoint without certificate (yes/no):") + elsif app.endpoints.count > 0 + ask_if_endpoints_were_already_created(app) + else + exit(0) unless yes?("Are you sure you want to create endpoint? (yes/no):") + end + certificate, key = read_certificate_components(cert_path, key_path, bundle_path) endpoint = app.create_endpoint(certificate, key, options["sni"]) @@ -92,10 +103,12 @@ say "Point your domain to private IP address: #{endpoint['ip_address']}" else say "Private IP address was requested for your cloud." say "Support has been notified and will contact you shortly." end + rescue Client::ConflictException => e + say_error e['message'] rescue Client::ValidationException => e e.each_error { |error| say_error error, :with_exit => false } exit 1 end @@ -125,10 +138,12 @@ say "Support has been notified and will contact you shortly." end rescue Client::ValidationException => e e.each_error { |error| say_error error, :with_exit => false } exit 1 + rescue Client::ConflictException => e + say_error e['message'] rescue Client::NotFoundException => e raise unless e.resource == :certificate say_error "Endpoint not found" end @@ -165,9 +180,19 @@ certificate = certificate + "\n" + bundle [certificate, key] end + end + + def ask_if_endpoints_were_already_created(app) + cli = Shelly::CLI::Endpoint.new + cli.options = {:cloud => app} + cli.list + say_new_line + exit(0) unless yes?("You already have assigned endpoint(s). Are " \ + "you sure you want to create another one with a new IP address? " \ + "(yes/no):") end end end end end