Class: Dynamic53
- Inherits:
-
Object
- Object
- Dynamic53
- Defined in:
- lib/dynamic_53.rb,
lib/dynamic_53/version.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- DEFAULT_TTL =
1 hour
3600- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
Instance Method Summary collapse
-
#initialize(zone, hostname, options = {}) ⇒ Dynamic53
constructor
Initializes an object for updating the Route 53 hostname with the machine’s current public IP address.
-
#ip_address ⇒ Object
fetch the current machine’s public IP address.
-
#record_set ⇒ Object
Fetch a record set object for the given hostname in the Route 53 zone specified.
-
#route_53_client ⇒ Object
A client for making Route 53 API requests.
-
#update ⇒ Object
perform the Route 53 update, returning the AWS SDK changelist object for the change.
-
#zone_id ⇒ Object
Fetches the AWS Route53 zone id for the specified zone.
Constructor Details
#initialize(zone, hostname, options = {}) ⇒ Dynamic53
Initializes an object for updating the Route 53 hostname with the machine’s current public IP address.
15 16 17 18 19 |
# File 'lib/dynamic_53.rb', line 15 def initialize(zone, hostname, ={}) @zone = zone @hostname = hostname @options = end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
10 11 12 |
# File 'lib/dynamic_53.rb', line 10 def hostname @hostname end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/dynamic_53.rb', line 11 def @options end |
#zone ⇒ Object (readonly)
Returns the value of attribute zone.
9 10 11 |
# File 'lib/dynamic_53.rb', line 9 def zone @zone end |
Instance Method Details
#ip_address ⇒ Object
fetch the current machine’s public IP address.
31 32 33 34 35 36 37 38 |
# File 'lib/dynamic_53.rb', line 31 def ip_address @ip_address ||= begin ip_address = Net::HTTP.get("bot.whatismyipaddress.com", "/") $stdout.puts "Public IP Address: #{ip_address}" if [:verbose] ip_address end end |
#record_set ⇒ Object
Fetch a record set object for the given hostname in the Route 53 zone specified.
51 52 53 |
# File 'lib/dynamic_53.rb', line 51 def record_set @record_set ||= AWS::Route53::HostedZone.new(zone_id).rrsets[hostname, 'A'] end |
#route_53_client ⇒ Object
A client for making Route 53 API requests.
56 57 58 |
# File 'lib/dynamic_53.rb', line 56 def route_53_client @route_53_client ||= AWS::Route53.new.client end |
#update ⇒ Object
perform the Route 53 update, returning the AWS SDK changelist object for the change.
22 23 24 25 26 27 28 |
# File 'lib/dynamic_53.rb', line 22 def update record_set.ttl = [:ttl] || DEFAULT_TTL record_set.resource_records = [{:value => ip_address}] result = record_set.update $stdout.puts "Record updated" if [:verbose] result end |
#zone_id ⇒ Object
Fetches the AWS Route53 zone id for the specified zone.
41 42 43 44 45 46 47 48 |
# File 'lib/dynamic_53.rb', line 41 def zone_id route_53_client. list_hosted_zones[:hosted_zones]. each. select { |z| z[:name] == zone }. map {|z| z[:id] }. first end |