dynacord 0.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dynacord.gemspec +32 -0
- data/lib/dynacord.rb +8 -0
- data/lib/dynacord/address.rb +20 -0
- data/lib/dynacord/provider.rb +6 -0
- data/lib/dynacord/provider/gandi.rb +8 -0
- data/lib/dynacord/provider/gandi/livedns.rb +51 -0
- data/lib/dynacord/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d803c615cec598e71405c9a4adaadbacfd18e6fa7645326843299e03d5fcaef0
|
|
4
|
+
data.tar.gz: 31a58809597437a3de9ca74c0568359639998b7ef0a74d1cb989e7c92e7290e9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e7b21e17d88f9aad38d0f42f5fa8fd729719828e72ab6d950ea0599e7085217518da49eb8c74202e2c51a8ec139ff49fc2f1b3aec6078dc33aed095df0fec200
|
|
7
|
+
data.tar.gz: d7432e73cc0bb31e8d5794cc749c56e7a9d6128441cd611db1da588bee80b111c2ea6fa5405077116bce4f458e936e6c4075debd71f8ed1436fcfb68dff5d465
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Stephen Dunne
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Dynacord
|
|
2
|
+
|
|
3
|
+
Dynacord is a Ruby gem, designed to give you an easy interface to updating an A record based on the public IP address from where it's used. It is designed in a way to work with multiple DNS providers, and to be easily expanded.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'dynacord'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install dynacord
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
To get the current public IP address (from the host where the call is made):
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
require 'dynacord'
|
|
27
|
+
ipaddr = Dynacord::Address.get
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This method also accepts a single parameter as the host to use for determining the IP address:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
require 'dynacord'
|
|
34
|
+
ipaddr = Dynacord::Address.get('http://myiplookup.example.com')
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The mechanism for updating an A record with this IP address varies, based on the provider that you're using for DNS.
|
|
38
|
+
|
|
39
|
+
## Providers
|
|
40
|
+
|
|
41
|
+
Providers are DNS providers, that Dynacord can use to update an A record. Each provider has different requirements, so see the class for the provider you're using to get more specific details.
|
|
42
|
+
|
|
43
|
+
## Contributing
|
|
44
|
+
|
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sedunne/dynacord.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
50
|
+
|
|
51
|
+
## Todo
|
|
52
|
+
|
|
53
|
+
* Add more providers
|
|
54
|
+
* Add provider-independent interface for common values (domain, apikey, record, etc)
|
|
55
|
+
* Tests
|
|
56
|
+
* Refactor address.rb to use net/http
|
|
57
|
+
* ???
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "dynacord"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dynacord.gemspec
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "dynacord/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "dynacord"
|
|
7
|
+
spec.version = Dynacord::VERSION
|
|
8
|
+
spec.authors = ["Stephen Dunne"]
|
|
9
|
+
spec.email = ["stephen@icanhazmail.net"]
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Dynamically update DNS A records'
|
|
12
|
+
spec.description = 'Update DNS A records based on current public IP address.'
|
|
13
|
+
spec.homepage = 'https://github.com/sedunne/dynacord'
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
|
17
|
+
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["source_code_uri"] = 'https://github.com/sedunne/dynacord'
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = "exe"
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
|
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
32
|
+
end
|
data/lib/dynacord.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Dynacord
|
|
2
|
+
class Address
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
|
|
5
|
+
def initialize(server)
|
|
6
|
+
@server = server
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
## default since it's the only decent minimal public-facing source I know
|
|
10
|
+
def self.get(remote = 'http://ipv4.icanhazip.com')
|
|
11
|
+
begin
|
|
12
|
+
res = open(remote).read
|
|
13
|
+
rescue StandardError => e
|
|
14
|
+
puts "error fetching address: #{e.class} -> #{e.message}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
res.strip
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module Dynacord
|
|
5
|
+
module Provider
|
|
6
|
+
module Gandi
|
|
7
|
+
class LiveDNS
|
|
8
|
+
def initialize(apikey:)
|
|
9
|
+
@apikey = apikey
|
|
10
|
+
@api = Net::HTTP.new('dns.api.gandi.net', 443)
|
|
11
|
+
@api.use_ssl = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
## get the LiveDNS zones and their UUIDs
|
|
15
|
+
def zone_uuids()
|
|
16
|
+
q = Net::HTTP::Get.new('/api/v5/zones')
|
|
17
|
+
q['X-Api-Key'] = @apikey
|
|
18
|
+
r = @api.request(q)
|
|
19
|
+
return r.code, r.body
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
## get the uuid for a given domain
|
|
23
|
+
def uuid_from_domain(domain:)
|
|
24
|
+
zones = zone_uuids()
|
|
25
|
+
uuid = nil
|
|
26
|
+
JSON.parse(zones[1]).each do |zone|
|
|
27
|
+
if zone['name'] == domain
|
|
28
|
+
uuid = zone['uuid']
|
|
29
|
+
break
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
return uuid
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
## update a given A record in a provided zone
|
|
36
|
+
def update_record(record:, zone:, ipaddr:, ttl: 300)
|
|
37
|
+
uri = "/api/v5/zones/#{zone}/records/#{record}/A"
|
|
38
|
+
data = {'rrset_ttl' => ttl.to_i, 'rrset_values' => [ipaddr]}.to_json
|
|
39
|
+
q = Net::HTTP::Put.new(uri)
|
|
40
|
+
q['X-Api-Key'] = @apikey
|
|
41
|
+
q["Content-Type"] = "application/json"
|
|
42
|
+
q.body = data
|
|
43
|
+
r = @api.request(q)
|
|
44
|
+
return r.code, r.body
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: dynacord
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Stephen Dunne
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-09-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: Update DNS A records based on current public IP address.
|
|
42
|
+
email:
|
|
43
|
+
- stephen@icanhazmail.net
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- Gemfile
|
|
50
|
+
- Gemfile.lock
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- bin/console
|
|
55
|
+
- bin/setup
|
|
56
|
+
- dynacord.gemspec
|
|
57
|
+
- lib/dynacord.rb
|
|
58
|
+
- lib/dynacord/address.rb
|
|
59
|
+
- lib/dynacord/provider.rb
|
|
60
|
+
- lib/dynacord/provider/gandi.rb
|
|
61
|
+
- lib/dynacord/provider/gandi/livedns.rb
|
|
62
|
+
- lib/dynacord/version.rb
|
|
63
|
+
homepage: https://github.com/sedunne/dynacord
|
|
64
|
+
licenses:
|
|
65
|
+
- MIT
|
|
66
|
+
metadata:
|
|
67
|
+
allowed_push_host: https://rubygems.org
|
|
68
|
+
homepage_uri: https://github.com/sedunne/dynacord
|
|
69
|
+
source_code_uri: https://github.com/sedunne/dynacord
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubyforge_project:
|
|
86
|
+
rubygems_version: 2.7.6.2
|
|
87
|
+
signing_key:
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Dynamically update DNS A records
|
|
90
|
+
test_files: []
|