dozens-alias 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/dozens-alias +5 -0
- data/dozens-alias.gemspec +26 -0
- data/lib/dozens/alias/version.rb +5 -0
- data/lib/dozens/alias.rb +52 -0
- data/lib/dozens/api.rb +36 -0
- data/lib/dozens/cli.rb +17 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 807cdf1406343bb8ebfd2004758eff9586aae6cd
|
4
|
+
data.tar.gz: 2b9115c48b399b210c45bcf8e9575d36111b2b60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3c9983e35e613490517110984bcc1fbaf376f427f7a512de95fd6f04ddbfd7765d8fad8188962ab81c139aa583767d8dcb0d4737db32ed6977a03c9066c01ad
|
7
|
+
data.tar.gz: 968a84fef566ac7bd4dce1f7847cd8092a69f6b6daa3b5499f56c43353d6ecbdb2169f01236e82cc0fbd5984eca7c5d06b30fd9d3f378f3a205e1bacdb2a54c2
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Keitaroh Kobayashi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Dozens::Alias
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dozens-alias'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dozens-alias
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/dozens-alias/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/dozens-alias
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dozens/alias/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dozens-alias"
|
8
|
+
spec.version = Dozens::Alias::VERSION
|
9
|
+
spec.authors = ["Keitaroh Kobayashi"]
|
10
|
+
spec.email = ["keita@kkob.us"]
|
11
|
+
spec.summary = %q{A simple tool to enable ALIAS record types on Dozens}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "GPLv3"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'httparty'
|
22
|
+
spec.add_dependency 'thor'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
data/lib/dozens/alias.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "dozens/alias/version"
|
2
|
+
require "dozens/api"
|
3
|
+
|
4
|
+
module Dozens
|
5
|
+
class Alias
|
6
|
+
|
7
|
+
def initialize zone, hostname, target
|
8
|
+
@zone = zone
|
9
|
+
@hostname = hostname
|
10
|
+
@target = target
|
11
|
+
|
12
|
+
@general_resolv = Resolv::DNS.new
|
13
|
+
@target_resolv = Resolv::DNS.new nameserver: authoritative_nameservers
|
14
|
+
end
|
15
|
+
|
16
|
+
def update!
|
17
|
+
correct_ips = target_ips.sort_by { |x| x }
|
18
|
+
|
19
|
+
api = API.new ENV['DOZENS_USER'], ENV['DOZENS_KEY']
|
20
|
+
|
21
|
+
record_list = api \
|
22
|
+
.get_record_list(@zone)['record'] \
|
23
|
+
.select { |x| x['type'] == 'A' and x['name'] == @hostname } \
|
24
|
+
.sort_by { |x| x['content'] }
|
25
|
+
|
26
|
+
record_list.each_with_index do |r, i|
|
27
|
+
if r['content'] != correct_ips[i]
|
28
|
+
api.update_record r['id'], correct_ips[i]
|
29
|
+
print "=> Updated #{r['content']} to #{correct_ips[i]}\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def authoritative_nameservers(for_domain=nil)
|
37
|
+
domain = for_domain || @target
|
38
|
+
ns = @general_resolv.getresources domain, Resolv::DNS::Resource::IN::NS
|
39
|
+
if ns.count == 0
|
40
|
+
next_domain = domain.split('.')[1..-1].join('.')
|
41
|
+
authoritative_nameservers next_domain
|
42
|
+
else
|
43
|
+
ns.map { |e| e.name.to_s }.first
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def target_ips
|
48
|
+
@target_resolv.getaddresses(@target).map { |e| e.to_s }
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/dozens/api.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Dozens
|
4
|
+
class API
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
format :json
|
8
|
+
|
9
|
+
base_uri 'http://dozens.jp/api'
|
10
|
+
headers 'Content-Type' => 'application/json'
|
11
|
+
headers 'Accept' => 'application/json'
|
12
|
+
|
13
|
+
def initialize(user, key)
|
14
|
+
@user = user
|
15
|
+
@key = key
|
16
|
+
|
17
|
+
r = self.class.get("/authorize.json", :headers => { "X-Auth-User" => @user, "X-Auth-Key" => @key })
|
18
|
+
@token = r['auth_token']
|
19
|
+
end
|
20
|
+
|
21
|
+
def update_record(record_id, new_value, ttl=60)
|
22
|
+
options = { :body => { "content" => new_value, "ttl" => ttl }.to_json, :headers => authorization_headers }
|
23
|
+
self.class.post("/record/update/#{ record_id }.json", options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_record_list(zone_name)
|
27
|
+
self.class.get("/record/#{ zone_name }.json", { :headers => authorization_headers })
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def authorization_headers
|
33
|
+
{ "X-Auth-Token" => @token }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/dozens/cli.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'dozens/alias'
|
3
|
+
|
4
|
+
module Dozens
|
5
|
+
class CLI < Thor
|
6
|
+
|
7
|
+
desc "update", "Updates a record to match another hostname."
|
8
|
+
method_option :zone, :required => true, :desc => 'The zone of the record to update'
|
9
|
+
method_option :hostname, :required => true, :desc => 'The hostname of the record to update'
|
10
|
+
method_option :target, :required => true, :desc => 'The target record to ALIAS'
|
11
|
+
def update
|
12
|
+
d = Dozens::Alias.new options[:zone], options[:hostname], options[:target]
|
13
|
+
d.update!
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dozens-alias
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keitaroh Kobayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- keita@kkob.us
|
72
|
+
executables:
|
73
|
+
- dozens-alias
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/dozens-alias
|
83
|
+
- dozens-alias.gemspec
|
84
|
+
- lib/dozens/alias.rb
|
85
|
+
- lib/dozens/alias/version.rb
|
86
|
+
- lib/dozens/api.rb
|
87
|
+
- lib/dozens/cli.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- GPLv3
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A simple tool to enable ALIAS record types on Dozens
|
112
|
+
test_files: []
|