engineyard-dnsimple 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,9 @@
1
1
  # ChangeLog
2
2
 
3
+ ## v0.2.0 - 2011/5/22
4
+
5
+ * If [domain, name] pair already exists then prompt for override
6
+
3
7
  ## v0.1.2 - 2011/5/22
4
8
 
5
9
  * Cucumber scenario is now working against http://test.dnsimple.com
@@ -7,12 +7,12 @@ Feature: Assign DNS to environment IP address
7
7
  And I have setup my dnsimple credentials
8
8
  And I have DNSimple domain "myapp.com"
9
9
 
10
- Scenario: Assign DNS A Record to an environment
10
+ Scenario: Assign new DNS A Record to an environment
11
11
  When I run local executable "ey-dnsimple" with arguments "assign myapp.com --account main --environment giblets"
12
12
  Then I should see matching
13
13
  """
14
14
  Fetching AppCloud environment information...
15
- Found environment giblets on account main with IP 174.129.7.113
15
+ Found AppCloud environment giblets on account main with IP 174.129.7.113
16
16
  Assigning myapp.com --> 174.129.7.113 (main/giblets)
17
17
  Created A record for myapp.com (id:\d+)
18
18
  Assigning www.myapp.com --> 174.129.7.113 (main/giblets)
@@ -23,5 +23,24 @@ Feature: Assign DNS to environment IP address
23
23
  www.myapp.com (A)-> 174.129.7.113 (ttl:60, id:\d+)
24
24
  """
25
25
 
26
+ Scenario: Resssign DNS A Record to an environment
27
+ When I run local executable "ey-dnsimple" with arguments "assign myapp.com --account main --environment giblets"
28
+ And I run local executable "ey-dnsimple" with arguments "assign myapp.com --account main --environment giblets --override"
29
+ Then I should see matching
30
+ """
31
+ Fetching AppCloud environment information...
32
+ Found AppCloud environment giblets on account main with IP 174.129.7.113
33
+ Deleted \d+ from myapp.com
34
+ Deleted \d+ from myapp.com
35
+ Assigning myapp.com --> 174.129.7.113 (main/giblets)
36
+ Created A record for myapp.com (id:\d+)
37
+ Assigning www.myapp.com --> 174.129.7.113 (main/giblets)
38
+ Created A record for myapp.com (id:\d+)
39
+ Complete!
40
+ Found 2 records for myapp.com
41
+ .myapp.com (A)-> 174.129.7.113 (ttl:60, id:\d+)
42
+ www.myapp.com (A)-> 174.129.7.113 (ttl:60, id:\d+)
43
+ """
44
+
26
45
 
27
46
 
@@ -23,6 +23,7 @@ module EngineYard
23
23
  method_option :verbose, :aliases => ["-V"], :desc => "Display more output"
24
24
  method_option :environment, :aliases => ["-e"], :desc => "Environment in which to deploy this application", :type => :string
25
25
  method_option :account, :aliases => ["-c"], :desc => "Name of the account you want to deploy in"
26
+ method_option :override, :aliases => ["-o"], :type => :boolean, :desc => "Override DNSimple records if they already exist"
26
27
  def assign(domain)
27
28
  say "Fetching AppCloud environment information..."; $stdout.flush
28
29
 
@@ -39,15 +40,12 @@ module EngineYard
39
40
 
40
41
  public_ip = "#{$1}.#{$2}.#{$3}.#{$4}"
41
42
 
42
- say "Found environment #{env_name} on account #{account_name} with IP #{public_ip}"
43
+ say "Found AppCloud environment #{env_name} on account #{account_name} with IP #{public_ip}"
43
44
  $stdout.flush
44
45
 
45
46
  ::DNSimple::Client.load_credentials_if_necessary
46
-
47
- say "Assigning "; say "#{domain} ", :green; say "--> "; say "#{public_ip} ", :green; say "(#{account_name}/#{env_name})"
48
- ::DNSimple::Commands::CreateRecord.new.execute([domain, "", "A", public_ip, "60"]) # A record for .mydomain.com
49
- say "Assigning "; say "www.#{domain} ", :green; say "--> "; say "#{public_ip} ", :green; say "(#{account_name}/#{env_name})"
50
- ::DNSimple::Commands::CreateRecord.new.execute([domain, "www", "A", public_ip, "60"]) # A record for www.mydomain.com
47
+ assign_dns(account_name, env_name, domain, public_ip, "", options[:override])
48
+ assign_dns(account_name, env_name, domain, public_ip, "www", options[:override])
51
49
 
52
50
  say "Complete!", :green
53
51
 
@@ -94,6 +92,34 @@ module EngineYard
94
92
  end
95
93
  end
96
94
  end
95
+
96
+ def assign_dns(account_name, env_name, domain, public_ip, name = "", override = false)
97
+ records = ::DNSimple::Record.all(domain)
98
+ if record = records.find { |record| record.name == name && record.domain.name == domain }
99
+ if override || ask_override_dns?(domain, name)
100
+ ::DNSimple::Commands::DeleteRecord.new.execute([domain, record.id]) # A record for .mydomain.com
101
+ else
102
+ error "Cannot replace existing #{domain_name domain, name} DNS"
103
+ end
104
+ end
105
+ say "Assigning "; say "#{domain_name domain, name} ", :green; say "--> "; say "#{public_ip} ", :green; say "(#{account_name}/#{env_name})"
106
+ $stdout.flush
107
+
108
+ ::DNSimple::Commands::CreateRecord.new.execute([domain, name, "A", public_ip, "60"]) # A record for .mydomain.com
109
+ end
110
+
111
+ def ask_override_dns?(domain, name)
112
+ ui = EY::CLI::UI::Prompter.backend
113
+ ui.agree("Replace #{domain_name domain, name}: ", "y")
114
+ end
115
+
116
+ def domain_name(domain, name = nil)
117
+ if name && name.length > 0
118
+ "#{name}.#{domain}"
119
+ else
120
+ domain
121
+ end
122
+ end
97
123
  end
98
124
  end
99
125
  end
@@ -1,5 +1,5 @@
1
1
  module EngineYard
2
2
  module DNSimple
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engineyard-dnsimple
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dr Nic Williams