vagrant-dns-updater 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7ef5c73334c69ae4235f6f3841150d1b3e5c74b
4
+ data.tar.gz: 57ee1101f50bf05c3cc3a2e66b44ef728f5b8cfa
5
+ SHA512:
6
+ metadata.gz: 08cd9b3ff18bb1ce92c569b796ad788d3a17dc2b89fa7f12631c38f93f0016e8092206097ac7cd0fff3b34bd6acfcc18ec95d897e4fe53f77a1901ab7ac03574
7
+ data.tar.gz: 4008f0c232ee5a39a2c7a738f405023f855cef6ebca1f96bb8572f1e5b99f40397cc4be57fad837ed3470a9c590425325f6221a139f639600fa783ce2e153a70
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+ /Vagrantfile
12
+ /.vagrant/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ gem "vagrant-dns-updater", path: "."
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nassim Kacha
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,82 @@
1
+ # vagrant-dns-updater
2
+
3
+ `vagrant-dns-updater` allows you to automatically configure a subdomain with the ip of your vagrant instance using your registrar API.
4
+
5
+ ## Important
6
+ - This plugin is currently only compatible with Linux guests.
7
+ - Only OVH registrar is supported for the moment.
8
+
9
+ ## Installation
10
+
11
+ $ vagrant plugin install vagrant-dns-updater
12
+
13
+ ## Usage
14
+
15
+ Configuration example for OVH:
16
+
17
+ ```ruby
18
+ Vagrant.configure(2) do |config|
19
+ # for the moment only "ovh" is supported
20
+ config.dnsupdater.registrar = "ovh"
21
+
22
+ # API credentials, specific to OVH
23
+ # for more information read the OVH section below
24
+ config.dnsupdater.appkey = "XXXXXXXX"
25
+ config.dnsupdater.appsecret = "YYYYYYYYYYYYYYYYYY"
26
+ config.dnsupdater.consumerkey = "ZZZZZZZZZZZZZZZZZZZ"
27
+
28
+ # domain settings, test.mydomain.com in our example
29
+ config.dnsupdater.zone = "mydomain.com"
30
+ config.dnsupdater.subdomain = "test"
31
+
32
+ # the network interface on which retreive the ip
33
+ config.dnsupdater.interface = "eth2"
34
+
35
+ # ttl is optional, default value is set to 60 seconds
36
+ config.dnsupdater.ttl = "120"
37
+ end
38
+ ```
39
+
40
+ ## Registrars
41
+ ### OVH
42
+
43
+ First you need an `appkey` and an `appsecret` which can be obtained [here](https://www.ovh.com/fr/cgi-bin/api/createApplication.cgi).
44
+
45
+ You will also need a `consumerkey`, you can get it using the `ovh-consumer-key` command provided by this plugin:
46
+
47
+ ```
48
+ vagrant ovh-consumer-key <appkey>
49
+ ```
50
+
51
+ This command will display a `consumerkey` and a `validationUrl`, the `consumerkey` need a validation before use, this
52
+ can be done by following the `validationUrl` and entering your credentials.
53
+
54
+ Finally you can add the following parameters to your Vagrantfile.
55
+
56
+ ```ruby
57
+ Vagrant.configure(2) do |config|
58
+ config.dnsupdater.registrar = "ovh"
59
+ config.dnsupdater.appkey = "XXXXXXXX"
60
+ config.dnsupdater.appsecret = "YYYYYYYYYYYYYYYYYY"
61
+ config.dnsupdater.consumerkey = "ZZZZZZZZZZZZZZZZZZZ"
62
+ config.dnsupdater.zone = "mydomain.com"
63
+ config.dnsupdater.subdomain = "test"
64
+ config.dnsupdater.interface = "eth2"
65
+ end
66
+ ```
67
+
68
+ ## ToDo
69
+
70
+ - Improve error handling.
71
+ - Support additional registrars : gandi, ultradns, ...
72
+ - Write tests.
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at https://github.com/blueicefield/vagrant-dns-updater.
77
+
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vagrant/dns/updater"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module DnsUpdater
3
+ module Action
4
+ class RemoveDnsRecord
5
+
6
+ def initialize(app, env)
7
+ @app = app
8
+ @machine = env[:machine]
9
+ end
10
+
11
+ def call(env)
12
+ config = @machine.config.dnsupdater
13
+ registrar = Registrar::Registrar.load config
14
+ registrar.remove_dns_record
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module VagrantPlugins
2
+ module DnsUpdater
3
+ module Action
4
+ class SetDnsRecord
5
+
6
+ def initialize(app, env)
7
+ @app = app
8
+ @machine = env[:machine]
9
+ end
10
+
11
+ def call(env)
12
+ config = @machine.config.dnsupdater
13
+ interface = config.interface
14
+ registrar = Registrar::Registrar.load config
15
+ @machine.communicate.execute("ip addr show #{interface} | awk '/inet/ && /#{interface}/{sub(/\\/.*$/,\"\",$2); print $2}'") do |type, output|
16
+ raise Vagrant::Errors::VagrantError.new, output if type.to_s == 'stderr'
17
+ ip = output
18
+ @machine.ui.info("Pointing #{config.subdomain}.#{config.zone} to #{ip}")
19
+ registrar.set_dns_record ip
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'action/set_dns_record'
2
+ require_relative 'action/remove_dns_record'
3
+
4
+ module VagrantPlugins
5
+ module DnsUpdater
6
+ module Action
7
+ include Vagrant::Action::Builtin
8
+
9
+ def self.set_dns_record
10
+ Vagrant::Action::Builder.new.tap do |builder|
11
+ builder.use ConfigValidate
12
+ builder.use SetDnsRecord
13
+ end
14
+ end
15
+
16
+ def self.remove_dns_record
17
+ Vagrant::Action::Builder.new.tap do |builder|
18
+ builder.use ConfigValidate
19
+ builder.use RemoveDnsRecord
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ require 'ovh/rest'
2
+
3
+ module VagrantPlugins
4
+ module DnsUpdater
5
+ class Command < Vagrant.plugin('2', :command)
6
+
7
+ def self.synopsis
8
+ 'Get OVH consumer key'
9
+ end
10
+
11
+ def execute
12
+ access = {
13
+ "accessRules" => [
14
+ { "method" => "GET", "path" => "/domain/*" },
15
+ { "method" => "POST", "path" => "/domain/*" },
16
+ { "method" => "PUT", "path" => "/domain/*" },
17
+ { "method" => "DELETE", "path" => "/domain/*" },
18
+ ]
19
+ }
20
+
21
+ argv = parse_args
22
+
23
+ result = OVH::REST.generate_consumer_key(argv, access)
24
+
25
+ raise Vagrant::Errors::VagrantError.new, result['message'] if result['message'] == 'Invalid application key'
26
+
27
+ puts <<-EOF
28
+ validationUrl: #{result['validationUrl']}
29
+ consumerkey: #{result['consumerKey']}
30
+ EOF
31
+
32
+ end
33
+
34
+
35
+ private
36
+
37
+
38
+ def parse_args
39
+ opts = OptionParser.new do |o|
40
+ o.banner = 'Usage: vagrant ovh-consumer-key [options] <appkey>'
41
+ o.separator ''
42
+
43
+ o.on('-h', '--help', 'Print this help') do
44
+ safe_puts(opts.help)
45
+ end
46
+ end
47
+
48
+ args = parse_options(opts)
49
+
50
+ if args.length != 1
51
+ safe_puts(opts.help)
52
+ exit 1
53
+ end
54
+
55
+ args[0]
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,54 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module DnsUpdater
5
+ class Config < Vagrant.plugin(2, :config)
6
+ attr_accessor :registrar
7
+ attr_accessor :appkey
8
+ attr_accessor :appsecret
9
+ attr_accessor :consumerkey
10
+ attr_accessor :zone
11
+ attr_accessor :subdomain
12
+ attr_accessor :interface
13
+ attr_accessor :ttl
14
+
15
+
16
+ def initialize
17
+ @registrar = UNSET_VALUE
18
+ @appkey = UNSET_VALUE
19
+ @appsecret = UNSET_VALUE
20
+ @consumerkey = UNSET_VALUE
21
+ @zone = UNSET_VALUE
22
+ @subdomain = UNSET_VALUE
23
+ @interface = UNSET_VALUE
24
+ @ttl = UNSET_VALUE
25
+ end
26
+
27
+ def finalize!
28
+ @registrar = nil if @registrar == UNSET_VALUE
29
+ @appkey = nil if @appkey == UNSET_VALUE
30
+ @appsecret = nil if @appsecret == UNSET_VALUE
31
+ @consumerkey = nil if @consumerkey == UNSET_VALUE
32
+ @zone = nil if @zone == UNSET_VALUE
33
+ @subdomain = nil if @subdomain == UNSET_VALUE
34
+ @interface = nil if @interface == UNSET_VALUE
35
+ @ttl = 60 if @ttl == UNSET_VALUE
36
+ end
37
+
38
+ def validate(machine)
39
+ finalize!
40
+ errors = []
41
+ errors << 'registrar parameter is required with a valid value' if @registrar.nil?
42
+ errors << 'appkey parameter is required' if @appkey.nil? && @registrar == 'ovh'
43
+ errors << 'appsecret parameter is required' if @appsecret.nil? && @registrar == 'ovh'
44
+ errors << 'consumerkey parameter is required' if @consumerkey.nil? && @registrar == 'ovh'
45
+ errors << 'zone parameter is required' if @zone.nil?
46
+ errors << 'subdomain parameter is required' if @subdomain.nil?
47
+ errors << 'interface parameter is required' if @interface.nil?
48
+
49
+ { "DnsUpdater" => errors }
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,41 @@
1
+ require 'vagrant'
2
+ require_relative 'action'
3
+ require_relative 'registrar'
4
+
5
+ module VagrantPlugins
6
+ module DnsUpdater
7
+ class Plugin < Vagrant.plugin('2')
8
+ Vagrant.require_version('>= 1.5.1')
9
+
10
+ name 'dns-updater'
11
+
12
+ description <<-DESC
13
+ This plugin allows you to automatically configure a subdomain
14
+ with the ip of your vagrant instance using your registrar API.
15
+ DESC
16
+
17
+
18
+ command "ovh-consumer-key" do
19
+ require_relative "command"
20
+ Command
21
+ end
22
+
23
+
24
+ config "dnsupdater" do
25
+ require_relative "config"
26
+ Config
27
+ end
28
+
29
+ %w{up provision}.each do |action|
30
+ action_hook :dnsupdater, "machine_action_#{action}".to_sym do |hook|
31
+ hook.append Action.set_dns_record
32
+ end
33
+ end
34
+
35
+ action_hook :dnsupdater, "machine_action_destroy".to_sym do |hook|
36
+ hook.append Action.remove_dns_record
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,63 @@
1
+ require 'ovh/rest'
2
+
3
+ module VagrantPlugins
4
+ module DnsUpdater
5
+ module Registrar
6
+ class Ovh < Registrar
7
+
8
+ register_registrar 'ovh'
9
+
10
+ def initialize(config)
11
+ @zone = config.zone
12
+ @subdomain = config.subdomain
13
+ @ttl = config.ttl
14
+ @api = OVH::REST.new config.appkey, config.appsecret, config.consumerkey
15
+ end
16
+
17
+ def set_dns_record(ip)
18
+ begin
19
+ record_id = get_record_id
20
+ if record_id.nil?
21
+ @api.post("/domain/zone/#{@zone}/record", {
22
+ 'fieldType' => 'A',
23
+ 'target' => ip,
24
+ 'subDomain' => @subdomain,
25
+ 'ttl' => @ttl})
26
+ else
27
+ @api.put("/domain/zone/#{@zone}/record/#{record_id}", {
28
+ 'target' => ip,
29
+ 'subDomain' => @subdomain,
30
+ 'ttl' => @ttl})
31
+ end
32
+
33
+ @api.post("/domain/zone/#{@zone}/refresh")
34
+ rescue OVH::RESTError => error
35
+ raise Vagrant::Errors::VagrantError.new, "DnsUpdater: #{error}"
36
+ end
37
+ end
38
+
39
+ def remove_dns_record
40
+ begin
41
+ record_id = get_record_id
42
+ @api.delete("/domain/zone/#{@zone}/record/#{record_id}") unless record_id.nil?
43
+ rescue OVH::RESTError => error
44
+ raise Vagrant::Errors::VagrantError.new, "DnsUpdater: #{error}"
45
+ end
46
+ end
47
+
48
+
49
+ private
50
+
51
+ def get_record_id
52
+ records = @api.get("/domain/zone/#{@zone}/record")
53
+ records.each do |r|
54
+ record = @api.get("/domain/zone/#{@zone}/record/#{r}")
55
+ return r if record['subDomain'] == @subdomain
56
+ end
57
+ nil
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,25 @@
1
+ module VagrantPlugins
2
+ module DnsUpdater
3
+ module Registrar
4
+ class Registrar
5
+
6
+ @@registrars = {}
7
+
8
+ def self.load(config)
9
+ registrar = @@registrars[config.registrar]
10
+ if registrar
11
+ registrar.new config
12
+ else
13
+ raise Vagrant::Errors::VagrantError.new,
14
+ "DnsUpdater: The registrar \"#{config.registrar}\" is not supported."
15
+ end
16
+ end
17
+
18
+ def self.register_registrar(name)
19
+ @@registrars[name] = self
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module DnsUpdater
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'pathname'
2
+ require 'vagrant-dns-updater/plugin'
3
+
4
+ module VagrantPlugins
5
+ module DnsUpdater
6
+ lib_root = File.dirname(File.absolute_path(__FILE__))
7
+ Dir.glob(lib_root + '/vagrant-dns-updater/registrar/*') {|file| require file}
8
+
9
+ def self.source_root
10
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-dns-updater/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vagrant-dns-updater"
8
+ spec.version = VagrantPlugins::DnsUpdater::VERSION
9
+ spec.authors = ["Nassim Kacha"]
10
+ spec.email = ["nassim.kacha@blueicefield.com"]
11
+
12
+ spec.description = 'A Vagrant plugin that allows you to automatically configure a subdomain' \
13
+ ' with the ip of your vagrant instance using your registrar API.'
14
+ spec.summary = spec.description
15
+ spec.homepage = "https://github.com/blueicefield/vagrant-dns-updater"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'ovh-rest', '~> 0.0.5'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-dns-updater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nassim Kacha
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ovh-rest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A Vagrant plugin that allows you to automatically configure a subdomain
56
+ with the ip of your vagrant instance using your registrar API.
57
+ email:
58
+ - nassim.kacha@blueicefield.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".ruby-version"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/vagrant-dns-updater.rb
72
+ - lib/vagrant-dns-updater/action.rb
73
+ - lib/vagrant-dns-updater/action/remove_dns_record.rb
74
+ - lib/vagrant-dns-updater/action/set_dns_record.rb
75
+ - lib/vagrant-dns-updater/command.rb
76
+ - lib/vagrant-dns-updater/config.rb
77
+ - lib/vagrant-dns-updater/plugin.rb
78
+ - lib/vagrant-dns-updater/registrar.rb
79
+ - lib/vagrant-dns-updater/registrar/ovh.rb
80
+ - lib/vagrant-dns-updater/version.rb
81
+ - vagrant-dns-updater.gemspec
82
+ homepage: https://github.com/blueicefield/vagrant-dns-updater
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.5
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: A Vagrant plugin that allows you to automatically configure a subdomain with
106
+ the ip of your vagrant instance using your registrar API.
107
+ test_files: []