Permalink
Browse files

Use domo-rb for domain splitting. Upgrade engineyard and fog.

Add periods to the ends of sentences.
Add my name to the authors.
  • Loading branch information...
1 parent d1d8fc9 commit 00cf756bed732799c01c783759701f6e666dbef3 @martinemde martinemde committed Nov 27, 2011
View
@@ -1,4 +1,4 @@
-source "http://rubygems.org"
+source :rubygems
# Specify your gem's dependencies in engineyard-dns.gemspec
gemspec
View
@@ -1,16 +1,15 @@
# -*- encoding: utf-8 -*-
-$:.push File.expand_path("../lib", __FILE__)
-require "engineyard-dns/version"
+require File.join(File.dirname(__FILE__), 'lib', 'engineyard-dns', 'version')
Gem::Specification.new do |s|
s.name = "engineyard-dns"
s.version = EngineYard::DNS::VERSION
s.platform = Gem::Platform::RUBY
- s.authors = ["Dr Nic Williams"]
- s.email = ["drnicwilliams@gmail.com"]
+ s.authors = ["Dr Nic Williams", "Martin Emde"]
+ s.email = ["drnicwilliams@gmail.com", "memde@engineyard.com"]
s.homepage = "https://github.com/engineyard/engineyard-dns#readme"
- s.summary = %q{Configure your Engine Yard AppCloud environment and your DNSimple domain.}
- s.description = %q{Easily configure your DNS with Engine Yard AppCloud via DNSimple.}
+ s.summary = %q{Configure DNS for your Engine Yard AppCloud environment.}
+ s.description = %q{Easily configure your DNS with Engine Yard AppCloud via Fog.}
s.rubyforge_project = "engineyard-dns"
@@ -19,9 +18,10 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency("engineyard", "1.3.20")
- s.add_dependency("fog", "~> 0.8.2")
+ s.add_dependency("engineyard", "1.4.10")
+ s.add_dependency("fog", "~> 1.0")
s.add_dependency("ipaddress", "~> 0.8")
+ s.add_dependency("domo-rb")
s.add_development_dependency("rake", ["~> 0.9.0"])
s.add_development_dependency("cucumber", ["~> 0.10"])
@@ -14,13 +14,13 @@ Feature: Assign DNS to environment IP address via DNSimple
Fetching AppCloud environment information...
AppCloud environment main/giblets has IP 127.0.0.0
- Searching for myapp.com amongst your DNS providers...
- Found myapp.com in DNSimple account
+ Searching for myapp.com in your DNS providers...
+ Found myapp.com in DNSimple account.
Assigning myapp.com --> 127.0.0.0 (main/giblets)
- Created A record for myapp.com
+ A record for myapp.com created.
Assigning www.myapp.com --> 127.0.0.0 (main/giblets)
- Created A record for www.myapp.com
+ A record for www.myapp.com created.
Complete!
"""
@@ -36,15 +36,15 @@ Feature: Assign DNS to environment IP address via DNSimple
Fetching AppCloud environment information...
AppCloud environment main/giblets has IP 127.0.0.0
- Searching for myapp.com amongst your DNS providers...
- Found myapp.com in DNSimple account
+ Searching for myapp.com in your DNS providers...
+ Found myapp.com in DNSimple account.
- Deleted myapp.com
+ myapp.com deleted.
Assigning myapp.com --> 127.0.0.0 (main/giblets)
- Created A record for myapp.com
- Deleted www.myapp.com
+ A record for myapp.com created.
+ www.myapp.com deleted.
Assigning www.myapp.com --> 127.0.0.0 (main/giblets)
- Created A record for www.myapp.com
+ A record for www.myapp.com created.
Complete!
"""
@@ -53,17 +53,17 @@ Feature: Assign DNS to environment IP address via DNSimple
# www.myapp.com (A)-> 127.0.0.0 (ttl:60, id:\d+)
Scenario: Assign subdomain A Record to an environment
- When I run local executable "ey-dns" with arguments "assign myapp.com staging --account main --environment giblets"
+ When I run local executable "ey-dns" with arguments "assign staging.myapp.com --account main --environment giblets"
Then I should see exactly
"""
Fetching AppCloud environment information...
AppCloud environment main/giblets has IP 127.0.0.0
- Searching for myapp.com amongst your DNS providers...
- Found myapp.com in DNSimple account
+ Searching for myapp.com in your DNS providers...
+ Found myapp.com in DNSimple account.
Assigning staging.myapp.com --> 127.0.0.0 (main/giblets)
- Created A record for staging.myapp.com
+ A record for staging.myapp.com created.
Complete!
"""
@@ -1,7 +1,6 @@
Given /^I have setup my engineyard email\/password for API access$/ do
ENV['EYRC'] = File.join(@home_path, ".eyrc")
- token = { ENV['CLOUD_URL'] => {
- "api_token" => "f81a1706ddaeb148cfb6235ddecfc1cf"} }
+ token = { "api_token" => "f81a1706ddaeb148cfb6235ddecfc1cf"}
File.open(ENV['EYRC'], "w"){|f| YAML.dump(token, f) }
end
@@ -7,7 +7,7 @@ def shared_examples_for(title)
support = Dir[File.join(EY_ROOT,'/spec/support/*.rb')]
support.each{|helper| require helper }
-World(Spec::Helpers)
+World(SpecHelpers)
require "fakeweb"
@@ -21,4 +21,4 @@ def shared_examples_for(title)
ENV.delete('CLOUD_URL')
ENV.delete('EYRC')
ENV.delete('NO_SSH')
-end
+end
View
@@ -7,6 +7,7 @@
require "fog"
require "fog/bin"
require "ipaddress"
+require "domo"
module EngineYard
module DNS
@@ -19,27 +20,35 @@ def self.start(*)
super
end
- desc "assign DOMAIN [SUBDOMAIN]", "Assign DNS domain/tld (or name.tld) to your AppCloud environment"
+ desc "assign [SUBDOMAIN.]DOMAIN.TLD", "Assign DNS domain/tld (or name.tld) to your AppCloud environment"
method_option :environment, :aliases => ["-e"], :desc => "Environment containing the IP to which to resolve", :type => :string
method_option :account, :aliases => ["-c"], :desc => "Name of the account where the environment is found"
method_option :force, :aliases => ["-f"], :desc => "Override DNS records if they already exist", :type => :boolean
- def assign(domain_name, subdomain = "")
+ def assign(full_domain, deprecated_sub_domain = nil)
$stdout.sync
validate_fog_credentials
+ if deprecated_sub_domain
+ full_domain = combine_domain_name(full_domain, deprecated_sub_domain)
+ say "Subdomain as second argument is deprecated. Please use:"
+ say "% ey assign #{full_domain}"
+ end
+
say "Fetching AppCloud environment information..."
environment = fetch_environment(options[:environment], options[:account])
public_ip = fetch_public_ip(environment)
+ subdomain, domain_name = split_subdomain(full_domain)
+
say ""
- say "Searching for #{domain_name} amongst your DNS providers..."
+ say "Searching for #{domain_name} in your DNS providers..."
domain, provider_name = find_domain(domain_name)
unless domain
- error "Please register domain #{domain_name} with your DNS provider"
+ error "Please register domain #{domain_name} with your DNS provider."
end
- say "Found #{domain_name} in #{provider_name} account"
+ say "Found #{domain.domain} in #{provider_name} account."
say ""
assign_dns(domain, environment.account.name, environment.name, public_ip, subdomain, options[:force])
@@ -110,30 +119,38 @@ def fetch_public_ip(environment)
def find_domain(domain_name)
dns_provider_names.each do |provider|
dns_provider = ::Fog::DNS.new({:provider => provider})
- if domain = dns_provider.zones.select {|z| z.domain == domain_name}.first
+ if domain = dns_provider.zones.detect {|z| z.domain == domain_name}
return [domain, provider]
end
end
[nil, nil]
end
+ def split_subdomain(full_domain)
+ domain = Domo.canonize(full_domain)
+ subdomain = full_domain.sub(/\.?#{Regexp.escape(domain)}/,'')
+ [subdomain, domain]
+ end
+
def assign_dns(domain, account_name, env_name, public_ip, subdomain = "", override = false)
+ combined_domain_name = combine_domain_name(domain, subdomain)
+
if record = domain.records.select {|r| r.name == subdomain}.first
if override || ask_override_dns?(domain, subdomain)
record.destroy
- say "Deleted #{domain_name domain, subdomain}"
+ say "#{combined_domain_name} deleted."
else
- error "Cannot replace existing #{domain_name domain, subdomain} DNS"
+ error "Cannot replace existing #{combined_domain_name} DNS."
end
end
say "Assigning "
- say "#{domain_name domain, subdomain} ", :green
+ say "#{combined_domain_name} ", :green
say "--> "
say "#{public_ip} ", :green
say "(#{account_name}/#{env_name})"
- record = domain.records.create(:ip => public_ip, :name => subdomain, :type => record_type(public_ip), :ttl => "60")
- say "Created #{record.type} record for #{domain_name domain, subdomain}"
+ record = domain.records.create(:value => public_ip, :name => subdomain, :type => record_type(public_ip), :ttl => "60")
+ say "#{record.type} record for #{combined_domain_name} created."
end
# "A" for IPv4 and "AAAA" for IPv6; else display error and exit
@@ -144,7 +161,7 @@ def record_type(public_ip)
elsif address.ipv6?
"AAAA"
else
- error "Cannot recognize IP #{public_ip} as either IPv4 or IPv6 format"
+ error "Cannot recognize IP #{public_ip} as either IPv4 or IPv6 format."
end
end
@@ -155,12 +172,9 @@ def ask_override_dns?(domain, name)
# "myapp.com", "name" => "name.myapp.com"
# "myapp.com", "" => "myapp.com"
- def domain_name(domain, name = nil)
- if name && name.length > 0
- "#{name}.#{domain.domain}"
- else
- domain.domain
- end
+ def combine_domain_name(domain, subdomain)
+ domain_name = domain.respond_to?(:domain) ? domain.domain : domain.to_s
+ subdomain && !subdomain.empty? ? "#{subdomain}.#{domain_name}" : domain_name
end
# Returns the list of DNS providers that the current user has access to

0 comments on commit 00cf756

Please sign in to comment.