globodns_client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/globodns_client.gemspec +2 -1
- data/lib/globodns_client/connection.rb +50 -30
- data/lib/globodns_client/version.rb +1 -1
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7300f512dc21e6fe0fbffe785909a011052f5f5b
|
4
|
+
data.tar.gz: 93251bb520a97c317a7094bcc8ca8f8f7ae0e6dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 017d974ca203a02c4156c1b14c94309f54c482db8fa503084dbf917de7b6a961c1b13e64fa2153d288c47cda017e6babe481ffe3a43a48733e000c4ab06d6e6a
|
7
|
+
data.tar.gz: 20e968a171d48e194bcc9e9fb77ffc5be5b1269da3311b1382f9e9c2e55d93e11de141c94b4e97682962c8fb4c4c2333dba85a3d99745841b96d382cedd337b6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.2.1](https://github.com/globocom/globodns-client-ruby/releases/tag/v0.2.1) (21/08/17)
|
4
|
+
##### - Enhancements
|
5
|
+
* Added CNAME records operations (get and create)
|
6
|
+
* Function to get a domain (from a record (record + domain) name of any type or only the domain name)
|
7
|
+
|
3
8
|
## [0.2.0](https://github.com/globocom/globodns-client-ruby/releases/tag/v0.2.0) (25/01/17)
|
4
9
|
##### - Enhancements
|
5
10
|
* Authenticantion using bearer_token
|
@@ -9,4 +14,4 @@
|
|
9
14
|
|
10
15
|
|
11
16
|
## [0.1.x]
|
12
|
-
* Authentication using auth_token
|
17
|
+
* Authentication using auth_token
|
data/globodns_client.gemspec
CHANGED
@@ -29,8 +29,9 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_dependency "rest-client"
|
31
31
|
|
32
|
-
spec.add_development_dependency "bundler"
|
32
|
+
spec.add_development_dependency "bundler"
|
33
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
34
34
|
spec.add_development_dependency "mocha"
|
35
35
|
spec.add_development_dependency "test-unit"
|
36
|
+
spec.add_development_dependency "byebug"
|
36
37
|
end
|
@@ -14,6 +14,21 @@ module GlobodnsClient
|
|
14
14
|
@bearer_token = token
|
15
15
|
end
|
16
16
|
|
17
|
+
def get_domain(key)
|
18
|
+
domain = key.dup
|
19
|
+
domain.chomp!('.')
|
20
|
+
res = {}
|
21
|
+
while domain.count('.') >= 1
|
22
|
+
res = request('get','domain', domain)
|
23
|
+
if !res.empty?
|
24
|
+
domain = ""
|
25
|
+
else
|
26
|
+
domain.gsub!(/^([a-zA-Z0-9\-_]*.)/,'')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
res unless res.empty?
|
30
|
+
end
|
31
|
+
|
17
32
|
def get_zone(key, kind = 'A')
|
18
33
|
res = request('get','domain', key, nil, kind)
|
19
34
|
if kind.eql?('A') && !res.empty?
|
@@ -24,7 +39,7 @@ module GlobodnsClient
|
|
24
39
|
end
|
25
40
|
|
26
41
|
def get_zone_recursive(key, kind = 'A')
|
27
|
-
if kind.eql?('A')
|
42
|
+
if kind.eql?('A') or kind.eql?('CNAME')
|
28
43
|
domain = key.split('.', 2).last
|
29
44
|
elsif kind.eql?('PTR')
|
30
45
|
if key.include?('in-addr.arpa')
|
@@ -38,7 +53,7 @@ module GlobodnsClient
|
|
38
53
|
end
|
39
54
|
res = request('get','domain', domain, nil, kind)
|
40
55
|
if res.empty?
|
41
|
-
if domain.count('.') > 1 && kind == 'A' || domain.count('.') > 2 && kind == 'PTR'
|
56
|
+
if domain.count('.') > 1 && (kind == 'A' or kind == 'CNAME') || domain.count('.') > 2 && kind == 'PTR'
|
42
57
|
res = get_zone_recursive(domain, kind)
|
43
58
|
else
|
44
59
|
raise GlobodnsClient::NotFound, "Couldn't find a proper zone for '#{key}'"
|
@@ -47,27 +62,32 @@ module GlobodnsClient
|
|
47
62
|
res
|
48
63
|
end
|
49
64
|
|
50
|
-
def get_record(key, kind,
|
51
|
-
|
65
|
+
def get_record(key, kind, zone)
|
66
|
+
zone.flatten!
|
52
67
|
res = []
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
res << r[kind.downcase] unless r[kind.downcase].nil?
|
59
|
-
end
|
68
|
+
zone = get_zone(key, kind) if zone.nil?
|
69
|
+
host = get_host(key, zone, kind)
|
70
|
+
response = request('get', 'record', host, zone[0][:domain][:id], kind)
|
71
|
+
response.each do |r|
|
72
|
+
res << r[kind.downcase.to_sym] unless r[kind.downcase.to_sym].nil?
|
60
73
|
end
|
61
74
|
res.empty? ? false : res
|
62
75
|
end
|
63
76
|
|
64
77
|
def new_record(key, kind, value)
|
65
|
-
zone =
|
66
|
-
|
67
|
-
|
68
|
-
|
78
|
+
zone = get_domain key
|
79
|
+
unless zone.nil?
|
80
|
+
a_records = get_record(key, 'A', zone)
|
81
|
+
case kind
|
82
|
+
when 'A'
|
83
|
+
raise GlobodnsClient::AlreadyExists, "Item (#{key}) already exists with reference (#{a_records[0][:content]})" if a_records.collect{|r| r[:content]}.include? value
|
84
|
+
when 'CNAME'
|
85
|
+
cname_records = get_record(key, 'CNAME', zone)
|
86
|
+
raise GlobodnsClient::AlreadyExists, "Item (#{key}) already exists" if a_records or cname_records
|
87
|
+
end
|
88
|
+
|
69
89
|
host = get_host(key, zone, kind)
|
70
|
-
response = request('post', 'record', host, zone[
|
90
|
+
response = request('post', 'record', host, zone[0][:domain][:id], kind, value)
|
71
91
|
end
|
72
92
|
begin
|
73
93
|
schedule_export
|
@@ -78,30 +98,28 @@ module GlobodnsClient
|
|
78
98
|
|
79
99
|
def delete_record(key, kind)
|
80
100
|
zone = get_zone(key, kind)
|
81
|
-
unless
|
101
|
+
unless records = get_record(key, kind, zone)
|
82
102
|
raise GlobodnsClient::NotFound, "Record not found for (#{key})"
|
83
103
|
end
|
84
|
-
response
|
104
|
+
response=[]
|
105
|
+
records.each do |record|
|
106
|
+
response << request('delete', 'record', nil, record[:id])
|
107
|
+
end
|
85
108
|
begin
|
86
109
|
schedule_export
|
87
110
|
rescue Exception
|
111
|
+
ensure
|
112
|
+
response
|
88
113
|
end
|
89
|
-
response
|
90
114
|
end
|
91
115
|
|
92
116
|
private
|
93
117
|
|
94
118
|
def get_host(key, zone, kind)
|
95
|
-
if kind.eql?('A')
|
96
|
-
host = key.split('.'+zone[
|
97
|
-
# não sei pq fiz esse bloco em baixo (if/else)
|
98
|
-
# if key == zone['domain']['name']
|
99
|
-
# host = nil
|
100
|
-
# else
|
101
|
-
# host = key.split('.'+zone['domain']['name'])[0]
|
102
|
-
# end
|
119
|
+
if kind.eql?('A') or kind.eql?('CNAME')
|
120
|
+
host = key.split('.'+zone[0][:domain][:name])[0]
|
103
121
|
elsif kind.eql?('PTR')
|
104
|
-
case zone[
|
122
|
+
case zone[0][:domain][:name].count('.')
|
105
123
|
when 4, 5
|
106
124
|
host = key.split('.').last
|
107
125
|
when 3
|
@@ -132,10 +150,12 @@ module GlobodnsClient
|
|
132
150
|
|
133
151
|
case method
|
134
152
|
when 'get'
|
135
|
-
if type.eql?('A')
|
153
|
+
if type.eql?('A') or type.eql?('CNAME')
|
136
154
|
headers[:params] = {query: value}
|
137
155
|
elsif type.eql?('PTR')
|
138
156
|
headers[:params] = {query: value, reverse: true}
|
157
|
+
elsif kind.eql?('domain')
|
158
|
+
headers[:params] = {query: value}
|
139
159
|
else
|
140
160
|
raise "Not implemented"
|
141
161
|
end
|
@@ -159,7 +179,7 @@ module GlobodnsClient
|
|
159
179
|
if response.code < 200 || response.code > 399
|
160
180
|
raise "Couldn't get a response from GloboDNS - code (#{response.code} / message #{response.body})"
|
161
181
|
end
|
162
|
-
method.eql?('delete') ? "" : JSON.parse(response.body)
|
182
|
+
method.eql?('delete') ? "" : JSON.parse(response.body, {:symbolize_names => true, :object_class => Hash})
|
163
183
|
end
|
164
184
|
end
|
165
185
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globodns_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernesto Thorp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Simple client for GloboDNS API.
|
84
98
|
email:
|
85
99
|
- ernesto@corp.globo.com
|
@@ -123,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
137
|
version: '0'
|
124
138
|
requirements: []
|
125
139
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.6.11
|
127
141
|
signing_key:
|
128
142
|
specification_version: 4
|
129
143
|
summary: Simple client for GloboDNS API.
|