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 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
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dynacord.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dynacord (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.5.0)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 2.0)
16
+ dynacord!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 2.0.2
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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
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,8 @@
1
+ require 'dynacord/version'
2
+ require 'dynacord/address'
3
+ require 'dynacord/provider'
4
+
5
+ module Dynacord
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+ end
@@ -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,6 @@
1
+ require 'dynacord/provider/gandi'
2
+
3
+ module Dynacord
4
+ module Provider
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'dynacord/provider/gandi/livedns'
2
+
3
+ module Dynacord
4
+ module Provider
5
+ module Gandi
6
+ end
7
+ end
8
+ 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
+
@@ -0,0 +1,3 @@
1
+ module Dynacord
2
+ VERSION = '0.1.1'
3
+ end
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: []