dennis-client 1.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/VERSION +1 -0
- data/lib/dennis/client.rb +70 -0
- data/lib/dennis/error.rb +11 -0
- data/lib/dennis/group.rb +121 -0
- data/lib/dennis/group_not_found_error.rb +8 -0
- data/lib/dennis/nameserver.rb +84 -0
- data/lib/dennis/paginated_array.rb +22 -0
- data/lib/dennis/pagination.rb +31 -0
- data/lib/dennis/record.rb +178 -0
- data/lib/dennis/record_type.rb +89 -0
- data/lib/dennis/validation_error.rb +21 -0
- data/lib/dennis/validation_error_detail.rb +23 -0
- data/lib/dennis/version.rb +12 -0
- data/lib/dennis/zone.rb +214 -0
- data/lib/dennis/zone_not_found_error.rb +8 -0
- data/lib/dennis-client.rb +5 -0
- data/lib/dennis.rb +15 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a1f20fe7792d9b35ebd46ef5534abce7aa58e95e0c6d426b8999d88a39d9080
|
4
|
+
data.tar.gz: 26fb26887882aed7c9572e508267a48f9cf62179e3bfbe2c5d26a834f54d3ac8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 94e51088eb391d0cbe4d0837fe95da4eafb601c9fd42ff0fa2db58727927094868dcab1bdaaa17b68f9f025a1fc5e0b043ca5b12d0d21933a45ce05181957544
|
7
|
+
data.tar.gz: e28bc9ea027f5d667ba87a786b0a986595a20d31c064ccb12c6e870f009c51facbffa445b5fb65f911cab473af29fbd6cdff5521eba6356b4265cb9c531c095f
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.1
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'apia_client'
|
4
|
+
require 'dennis/group'
|
5
|
+
require 'dennis/zone'
|
6
|
+
require 'dennis/nameserver'
|
7
|
+
require 'dennis/record'
|
8
|
+
require 'dennis/record_type'
|
9
|
+
|
10
|
+
module Dennis
|
11
|
+
class Client
|
12
|
+
|
13
|
+
attr_reader :hostname
|
14
|
+
attr_reader :api_key
|
15
|
+
attr_reader :api
|
16
|
+
|
17
|
+
def initialize(hostname, api_key, **options)
|
18
|
+
@hostname = hostname
|
19
|
+
@api_key = api_key
|
20
|
+
|
21
|
+
@api = ApiaClient.load(hostname, namespace: 'api/v1', **options)
|
22
|
+
@api.headers['Authorization'] = "Bearer #{api_key}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def record_types
|
26
|
+
RecordType.all(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def groups(**opts)
|
30
|
+
Group.all(self, **opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
def group(id, field: :id)
|
34
|
+
Group.find_by(self, field, id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_group(**opts)
|
38
|
+
Group.create(self, **opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
def zones(**opts)
|
42
|
+
Zone.all(self, **opts)
|
43
|
+
end
|
44
|
+
|
45
|
+
def zone(id, field: :id)
|
46
|
+
Zone.find_by(self, field, id)
|
47
|
+
end
|
48
|
+
|
49
|
+
def record(id, field: :id)
|
50
|
+
Record.find_by(self, field, id)
|
51
|
+
end
|
52
|
+
|
53
|
+
def tagged_records(tags, group: nil)
|
54
|
+
Record.all_by_tag(self, tags, group: group)
|
55
|
+
end
|
56
|
+
|
57
|
+
def nameservers
|
58
|
+
Nameserver.all(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
def nameserver(id, field: :id)
|
62
|
+
Nameserver.find_by(self, field, id)
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_nameserver(**opts)
|
66
|
+
Nameserver.create(self, **opts)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
data/lib/dennis/error.rb
ADDED
data/lib/dennis/group.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dennis/nameserver'
|
4
|
+
require 'dennis/validation_error'
|
5
|
+
|
6
|
+
module Dennis
|
7
|
+
class Group
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def all(client, page: nil, per_page: nil)
|
12
|
+
request = client.api.create_request(:get, 'groups')
|
13
|
+
request.arguments[:page] = page if page
|
14
|
+
request.arguments[:per_page] = per_page if per_page
|
15
|
+
PaginatedArray.create(request.perform.hash, 'groups') do |hash|
|
16
|
+
new(client, hash)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_by(client, field, value)
|
21
|
+
request = client.api.create_request(:get, 'groups/:group')
|
22
|
+
request.arguments[:group] = { field => value }
|
23
|
+
Group.new(client, request.perform.hash['group'])
|
24
|
+
rescue ApiaClient::RequestError => e
|
25
|
+
e.code == 'group_not_found' ? nil : raise
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(client, name:, external_reference: nil)
|
29
|
+
request = client.api.create_request(:post, 'groups')
|
30
|
+
request.arguments[:properties] = { name: name, external_reference: external_reference }
|
31
|
+
Group.new(client, request.perform.hash['group'])
|
32
|
+
rescue ApiaClient::RequestError => e
|
33
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
34
|
+
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(client, hash)
|
41
|
+
@client = client
|
42
|
+
@hash = hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def id
|
46
|
+
@hash['id']
|
47
|
+
end
|
48
|
+
|
49
|
+
def name
|
50
|
+
@hash['name']
|
51
|
+
end
|
52
|
+
|
53
|
+
def external_reference
|
54
|
+
@hash['external_reference']
|
55
|
+
end
|
56
|
+
|
57
|
+
def created_at
|
58
|
+
return nil if @hash['created_at'].nil?
|
59
|
+
return @hash['created_at'] if @hash['created_at'].is_a?(Time)
|
60
|
+
|
61
|
+
Time.at(@hash['created_at'])
|
62
|
+
end
|
63
|
+
|
64
|
+
def updated_at
|
65
|
+
return nil if @hash['updated_at'].nil?
|
66
|
+
return @hash['updated_at'] if @hash['updated_at'].is_a?(Time)
|
67
|
+
|
68
|
+
Time.at(@hash['updated_at'])
|
69
|
+
end
|
70
|
+
|
71
|
+
def nameservers
|
72
|
+
@nameservers ||= @hash['nameservers'].map do |hash|
|
73
|
+
Nameserver.new(@client, hash)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_zone(**properties)
|
78
|
+
Zone.create(@client, group: { id: id }, **properties)
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_or_update_zone(**properties)
|
82
|
+
Zone.create_or_update(@client, group: { id: id }, **properties)
|
83
|
+
end
|
84
|
+
|
85
|
+
def zones(**options)
|
86
|
+
Zone.all_for_group(@client, { id: id }, **options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def zone(id, field: :id)
|
90
|
+
zone = Zone.find_by(@client, field, id)
|
91
|
+
return nil if zone.nil?
|
92
|
+
return nil if zone.group.id != self.id
|
93
|
+
|
94
|
+
zone
|
95
|
+
end
|
96
|
+
|
97
|
+
def tagged_records(tags)
|
98
|
+
Record.all_by_tag(@client, tags, group: { id: id })
|
99
|
+
end
|
100
|
+
|
101
|
+
def update(properties)
|
102
|
+
req = @client.api.create_request(:patch, 'groups/:group')
|
103
|
+
req.arguments['group'] = { id: id }
|
104
|
+
req.arguments['properties'] = properties
|
105
|
+
@hash = req.perform.hash['group']
|
106
|
+
true
|
107
|
+
rescue ApiaClient::RequestError => e
|
108
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
109
|
+
|
110
|
+
raise
|
111
|
+
end
|
112
|
+
|
113
|
+
def delete
|
114
|
+
req = @client.api.create_request(:delete, 'groups/:group')
|
115
|
+
req.arguments['group'] = { id: id }
|
116
|
+
req.perform
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dennis
|
4
|
+
class Nameserver
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def all(client)
|
9
|
+
nameservers = client.api.perform(:get, 'nameservers')
|
10
|
+
nameservers.hash['nameservers'].map { |hash| new(client, hash) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_by(client, field, value)
|
14
|
+
request = client.api.create_request(:get, 'nameservers/:nameserver')
|
15
|
+
request.arguments[:nameserver] = { field => value }
|
16
|
+
new(client, request.perform.hash['nameserver'])
|
17
|
+
rescue ApiaClient::RequestError => e
|
18
|
+
e.code == 'nameserver_not_found' ? nil : raise
|
19
|
+
end
|
20
|
+
|
21
|
+
def create(client, name:, server: nil)
|
22
|
+
request = client.api.create_request(:post, 'nameservers')
|
23
|
+
request.arguments[:properties] = { name: name, server: server }
|
24
|
+
new(client, request.perform.hash['nameserver'])
|
25
|
+
rescue ApiaClient::RequestError => e
|
26
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
27
|
+
|
28
|
+
raise
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(client, hash)
|
34
|
+
@client = client
|
35
|
+
@hash = hash
|
36
|
+
end
|
37
|
+
|
38
|
+
def id
|
39
|
+
@hash['id']
|
40
|
+
end
|
41
|
+
|
42
|
+
def name
|
43
|
+
@hash['name']
|
44
|
+
end
|
45
|
+
|
46
|
+
def server
|
47
|
+
@hash['server']
|
48
|
+
end
|
49
|
+
|
50
|
+
def created_at
|
51
|
+
return nil if @hash['created_at'].nil?
|
52
|
+
return @hash['created_at'] if @hash['created_at'].is_a?(Time)
|
53
|
+
|
54
|
+
Time.at(@hash['created_at'])
|
55
|
+
end
|
56
|
+
|
57
|
+
def updated_at
|
58
|
+
return nil if @hash['updated_at'].nil?
|
59
|
+
return @hash['updated_at'] if @hash['updated_at'].is_a?(Time)
|
60
|
+
|
61
|
+
Time.at(@hash['updated_at'])
|
62
|
+
end
|
63
|
+
|
64
|
+
def update(properties)
|
65
|
+
req = @client.api.create_request(:patch, 'nameservers/:nameserver')
|
66
|
+
req.arguments['nameserver'] = { id: id }
|
67
|
+
req.arguments['properties'] = properties
|
68
|
+
@hash = req.perform.hash['nameserver']
|
69
|
+
true
|
70
|
+
rescue ApiaClient::RequestError => e
|
71
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
72
|
+
|
73
|
+
raise
|
74
|
+
end
|
75
|
+
|
76
|
+
def delete
|
77
|
+
req = @client.api.create_request(:delete, 'nameservers/:nameserver')
|
78
|
+
req.arguments['nameserver'] = { id: id }
|
79
|
+
req.perform
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dennis/pagination'
|
4
|
+
|
5
|
+
module Dennis
|
6
|
+
class PaginatedArray < Array
|
7
|
+
|
8
|
+
attr_accessor :pagination
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def create(result, key, &block)
|
13
|
+
result_hash = result[key]
|
14
|
+
array = new(result_hash.map(&block))
|
15
|
+
array.pagination = Pagination.new(result['pagination'])
|
16
|
+
array
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dennis
|
4
|
+
class Pagination
|
5
|
+
|
6
|
+
def initialize(hash)
|
7
|
+
@hash = hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_page
|
11
|
+
@hash['current_page']
|
12
|
+
end
|
13
|
+
|
14
|
+
def total_pages
|
15
|
+
@hash['total_pages']
|
16
|
+
end
|
17
|
+
|
18
|
+
def total
|
19
|
+
@hash['total']
|
20
|
+
end
|
21
|
+
|
22
|
+
def per_page
|
23
|
+
@hash['per_page']
|
24
|
+
end
|
25
|
+
|
26
|
+
def large_set?
|
27
|
+
@hash['large_set']
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dennis/error'
|
4
|
+
require 'dennis/validation_error'
|
5
|
+
require 'dennis/zone_not_found_error'
|
6
|
+
|
7
|
+
module Dennis
|
8
|
+
class Record
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def all(client, zone, **options)
|
13
|
+
request = client.api.create_request(:get, 'zones/:zone/records')
|
14
|
+
request.arguments[:zone] = zone
|
15
|
+
options.each do |field, value|
|
16
|
+
request.arguments[field] = value
|
17
|
+
end
|
18
|
+
request.perform.hash['records'].map { |hash| new(client, hash) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def all_by_tag(client, tags, group: nil)
|
22
|
+
request = client.api.create_request(:get, 'records/tagged')
|
23
|
+
request.arguments[:tags] = tags
|
24
|
+
request.arguments[:group] = group if group
|
25
|
+
request.perform.hash['records'].map { |hash| new(client, hash) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_by(client, field, value)
|
29
|
+
request = client.api.create_request(:get, 'records/:record')
|
30
|
+
request.arguments[:record] = { field => value }
|
31
|
+
new(client, request.perform.hash['record'])
|
32
|
+
rescue ApiaClient::RequestError => e
|
33
|
+
e.code == 'record_not_found' ? nil : raise
|
34
|
+
end
|
35
|
+
|
36
|
+
def create(client, zone:, **properties)
|
37
|
+
request = client.api.create_request(:post, 'records')
|
38
|
+
request.arguments[:zone] = zone
|
39
|
+
request.arguments[:properties] = properties_to_argument(properties)
|
40
|
+
new(client, request.perform.hash['record'])
|
41
|
+
rescue ApiaClient::RequestError => e
|
42
|
+
raise ZoneNotFoundError if e.code == 'zone_not_found'
|
43
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
44
|
+
|
45
|
+
raise
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_or_update(client, zone_id, **properties)
|
49
|
+
if properties[:external_reference].nil?
|
50
|
+
raise Dennis::ExternalReferenceRequiredError, 'An external_reference must be provided to use create_or_update'
|
51
|
+
end
|
52
|
+
|
53
|
+
record = find_by(client, :external_reference, properties[:external_reference])
|
54
|
+
if record.nil?
|
55
|
+
create(client, zone: { id: zone_id }, **properties)
|
56
|
+
else
|
57
|
+
record.update(properties)
|
58
|
+
record
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def properties_to_argument(hash, type: nil)
|
63
|
+
arguments = {}
|
64
|
+
[:name, :type, :ttl, :priority, :external_reference, :tags].each do |field_name|
|
65
|
+
arguments[field_name] = hash[field_name] if hash.key?(field_name)
|
66
|
+
|
67
|
+
type = hash[field_name] if field_name == :type && hash.key?(field_name)
|
68
|
+
end
|
69
|
+
|
70
|
+
if hash.key?(:content)
|
71
|
+
if type.nil?
|
72
|
+
raise Error, 'Cannot generate record properties without a type'
|
73
|
+
end
|
74
|
+
|
75
|
+
arguments[:content] = { type.to_s.upcase => hash[:content] }
|
76
|
+
end
|
77
|
+
arguments
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def initialize(client, hash)
|
83
|
+
@client = client
|
84
|
+
@hash = hash
|
85
|
+
end
|
86
|
+
|
87
|
+
def id
|
88
|
+
@hash['id']
|
89
|
+
end
|
90
|
+
|
91
|
+
def name
|
92
|
+
@hash['name']
|
93
|
+
end
|
94
|
+
|
95
|
+
def full_name
|
96
|
+
@hash['full_name']
|
97
|
+
end
|
98
|
+
|
99
|
+
def type
|
100
|
+
@hash['type']
|
101
|
+
end
|
102
|
+
|
103
|
+
def ttl
|
104
|
+
@hash['ttl']
|
105
|
+
end
|
106
|
+
|
107
|
+
def priority
|
108
|
+
@hash['priority']
|
109
|
+
end
|
110
|
+
|
111
|
+
def external_reference
|
112
|
+
@hash['external_reference']
|
113
|
+
end
|
114
|
+
|
115
|
+
def managed?
|
116
|
+
@hash['managed']
|
117
|
+
end
|
118
|
+
|
119
|
+
def tags
|
120
|
+
@hash['tags']
|
121
|
+
end
|
122
|
+
|
123
|
+
def created_at
|
124
|
+
return nil if @hash['created_at'].nil?
|
125
|
+
return @hash['created_at'] if @hash['created_at'].is_a?(Time)
|
126
|
+
|
127
|
+
Time.at(@hash['created_at'])
|
128
|
+
end
|
129
|
+
|
130
|
+
def updated_at
|
131
|
+
return nil if @hash['updated_at'].nil?
|
132
|
+
return @hash['updated_at'] if @hash['updated_at'].is_a?(Time)
|
133
|
+
|
134
|
+
Time.at(@hash['updated_at'])
|
135
|
+
end
|
136
|
+
|
137
|
+
def zone
|
138
|
+
return @zone if @zone
|
139
|
+
return nil unless @hash['zone']
|
140
|
+
|
141
|
+
@zone = Zone.new(@client, @hash['zone'])
|
142
|
+
end
|
143
|
+
|
144
|
+
def raw_content
|
145
|
+
@hash['raw_content']
|
146
|
+
end
|
147
|
+
|
148
|
+
def display_content
|
149
|
+
@hash['display_content']
|
150
|
+
end
|
151
|
+
|
152
|
+
def content
|
153
|
+
return nil if type.nil?
|
154
|
+
|
155
|
+
@hash.dig('content', type.to_s.upcase)&.transform_keys(&:to_sym)
|
156
|
+
end
|
157
|
+
|
158
|
+
def update(properties)
|
159
|
+
req = @client.api.create_request(:patch, 'records/:record')
|
160
|
+
req.arguments['record'] = { id: id }
|
161
|
+
req.arguments['properties'] = self.class.properties_to_argument(properties, type: type)
|
162
|
+
@hash = req.perform.hash['record']
|
163
|
+
true
|
164
|
+
rescue ApiaClient::RequestError => e
|
165
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
166
|
+
|
167
|
+
raise
|
168
|
+
end
|
169
|
+
|
170
|
+
def delete
|
171
|
+
req = @client.api.create_request(:delete, 'records/:record')
|
172
|
+
req.arguments['record'] = { id: id }
|
173
|
+
req.perform
|
174
|
+
true
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dennis
|
4
|
+
class RecordType
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def all(client)
|
9
|
+
request = client.api.create_request(:get, 'record_types')
|
10
|
+
request.perform.hash['record_types'].each_with_object({}) do |rt, hash|
|
11
|
+
type = new(rt)
|
12
|
+
hash[type.name] = type
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(hash)
|
19
|
+
@hash = hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@hash['name']
|
24
|
+
end
|
25
|
+
|
26
|
+
def requires_priority?
|
27
|
+
@hash['requires_priority'] == true
|
28
|
+
end
|
29
|
+
|
30
|
+
def managed_only?
|
31
|
+
@hash['managed_only'] == true
|
32
|
+
end
|
33
|
+
|
34
|
+
def exposed?
|
35
|
+
@hash['exposed'] == true
|
36
|
+
end
|
37
|
+
|
38
|
+
def content_attributes
|
39
|
+
@hash['content_attributes'].map do |hash|
|
40
|
+
ContentAttribute.new(hash)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class ContentAttribute
|
45
|
+
|
46
|
+
def initialize(hash)
|
47
|
+
@hash = hash
|
48
|
+
end
|
49
|
+
|
50
|
+
def name
|
51
|
+
@hash['name']
|
52
|
+
end
|
53
|
+
|
54
|
+
def label
|
55
|
+
@hash['label']
|
56
|
+
end
|
57
|
+
|
58
|
+
def type
|
59
|
+
@hash['type']
|
60
|
+
end
|
61
|
+
|
62
|
+
def options
|
63
|
+
return [] if @hash['options'].nil?
|
64
|
+
|
65
|
+
@hash['options'].map do |hash|
|
66
|
+
ContentAttributeOption.new(hash)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
class ContentAttributeOption
|
73
|
+
|
74
|
+
def initialize(hash)
|
75
|
+
@hash = hash
|
76
|
+
end
|
77
|
+
|
78
|
+
def label
|
79
|
+
@hash['label']
|
80
|
+
end
|
81
|
+
|
82
|
+
def value
|
83
|
+
@hash['value']
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dennis/error'
|
4
|
+
require 'dennis/validation_error_detail'
|
5
|
+
|
6
|
+
module Dennis
|
7
|
+
class ValidationError < Error
|
8
|
+
|
9
|
+
attr_reader :errors
|
10
|
+
|
11
|
+
def initialize(errors)
|
12
|
+
super
|
13
|
+
@errors = errors.map { |e| ValidationErrorDetail.new(e) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"Validation error: #{errors.map(&:message).join(', ')}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dennis
|
4
|
+
class ValidationErrorDetail
|
5
|
+
|
6
|
+
def initialize(hash)
|
7
|
+
@hash = hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def attribute
|
11
|
+
@hash['attribute']
|
12
|
+
end
|
13
|
+
|
14
|
+
def type
|
15
|
+
@hash['type']
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
@hash['message']
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dennis
|
4
|
+
|
5
|
+
VERSION_FILE_ROOT = File.expand_path('../../VERSION', __dir__)
|
6
|
+
if File.file?(VERSION_FILE_ROOT)
|
7
|
+
VERSION = File.read(VERSION_FILE_ROOT).strip.sub(/\Av/, '')
|
8
|
+
else
|
9
|
+
VERSION = '0.0.0.dev'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/lib/dennis/zone.rb
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dennis/validation_error'
|
4
|
+
require 'dennis/group_not_found_error'
|
5
|
+
require 'dennis/record'
|
6
|
+
require 'dennis/paginated_array'
|
7
|
+
|
8
|
+
module Dennis
|
9
|
+
class Zone
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def all(client, query: nil, view: nil, tags: nil, page: nil, per_page: nil)
|
14
|
+
request = client.api.create_request(:get, 'zones')
|
15
|
+
request.arguments[:query] = query if query
|
16
|
+
request.arguments[:view] = view if view
|
17
|
+
request.arguments[:tags] = tags if tags
|
18
|
+
request.arguments[:page] = page if page
|
19
|
+
request.arguments[:per_page] = per_page if per_page
|
20
|
+
PaginatedArray.create(request.perform.hash, 'zones') do |hash|
|
21
|
+
new(client, hash)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def all_for_group(client, group, query: nil, view: nil, tags: nil, page: nil, per_page: nil)
|
26
|
+
request = client.api.create_request(:get, 'groups/:group/zones')
|
27
|
+
request.arguments[:group] = group
|
28
|
+
request.arguments[:query] = query if query
|
29
|
+
request.arguments[:view] = view if view
|
30
|
+
request.arguments[:tags] = tags if tags
|
31
|
+
request.arguments[:page] = page if page
|
32
|
+
request.arguments[:per_page] = per_page if per_page
|
33
|
+
PaginatedArray.create(request.perform.hash, 'zones') do |hash|
|
34
|
+
new(client, hash)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_by(client, field, value)
|
39
|
+
request = client.api.create_request(:get, 'zones/:zone')
|
40
|
+
request.arguments[:zone] = { field => value }
|
41
|
+
new(client, request.perform.hash['zone'])
|
42
|
+
rescue ApiaClient::RequestError => e
|
43
|
+
e.code == 'zone_not_found' ? nil : raise
|
44
|
+
end
|
45
|
+
|
46
|
+
def create(client,
|
47
|
+
group:,
|
48
|
+
allow_sub_domains_of_zones_in_other_groups: nil,
|
49
|
+
**properties)
|
50
|
+
request = client.api.create_request(:post, 'zones')
|
51
|
+
request.arguments[:group] = group
|
52
|
+
request.arguments[:properties] = properties
|
53
|
+
unless allow_sub_domains_of_zones_in_other_groups.nil?
|
54
|
+
request.arguments[:allow_sub_domains_of_zones_in_other_groups] = allow_sub_domains_of_zones_in_other_groups
|
55
|
+
end
|
56
|
+
new(client, request.perform.hash['zone'])
|
57
|
+
rescue ApiaClient::RequestError => e
|
58
|
+
raise GroupNotFoundError if e.code == 'group_not_found'
|
59
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
60
|
+
|
61
|
+
raise
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_or_update(client, group:, **properties)
|
65
|
+
if properties[:external_reference].nil?
|
66
|
+
raise Dennis::ExternalReferenceRequiredError, 'An external_reference must be provided to use create_or_update'
|
67
|
+
end
|
68
|
+
|
69
|
+
zone = find_by(client, :external_reference, properties[:external_reference])
|
70
|
+
if zone.nil?
|
71
|
+
create(client, group: group, **properties)
|
72
|
+
else
|
73
|
+
zone.update(properties)
|
74
|
+
zone
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def initialize(client, hash)
|
81
|
+
@client = client
|
82
|
+
@hash = hash
|
83
|
+
end
|
84
|
+
|
85
|
+
def id
|
86
|
+
@hash['id']
|
87
|
+
end
|
88
|
+
|
89
|
+
def name
|
90
|
+
@hash['name']
|
91
|
+
end
|
92
|
+
|
93
|
+
def external_reference
|
94
|
+
@hash['external_reference']
|
95
|
+
end
|
96
|
+
|
97
|
+
def nameservers_verified_at
|
98
|
+
parse_time(@hash['nameservers_verified_at'])
|
99
|
+
end
|
100
|
+
|
101
|
+
def nameservers_checked_at
|
102
|
+
parse_time(@hash['nameservers_checked_at'])
|
103
|
+
end
|
104
|
+
|
105
|
+
def nameservers_verified?
|
106
|
+
@hash['nameservers_verified']
|
107
|
+
end
|
108
|
+
|
109
|
+
def verified?
|
110
|
+
@hash['verified']
|
111
|
+
end
|
112
|
+
|
113
|
+
def always_verified?
|
114
|
+
@hash['always_verified']
|
115
|
+
end
|
116
|
+
|
117
|
+
def reverse_dns?
|
118
|
+
@hash['reverse_dns']
|
119
|
+
end
|
120
|
+
|
121
|
+
def stale_verification?
|
122
|
+
@hash['stale_verification']
|
123
|
+
end
|
124
|
+
|
125
|
+
def default_ttl
|
126
|
+
@hash['default_ttl']
|
127
|
+
end
|
128
|
+
|
129
|
+
def tags
|
130
|
+
@hash['tags']
|
131
|
+
end
|
132
|
+
|
133
|
+
def group
|
134
|
+
return @group if @group
|
135
|
+
return nil unless @hash['group']
|
136
|
+
|
137
|
+
@group = Group.new(@client, @hash['group'])
|
138
|
+
end
|
139
|
+
|
140
|
+
def created_at
|
141
|
+
return nil if @hash['created_at'].nil?
|
142
|
+
return @hash['created_at'] if @hash['created_at'].is_a?(Time)
|
143
|
+
|
144
|
+
Time.at(@hash['created_at'])
|
145
|
+
end
|
146
|
+
|
147
|
+
def updated_at
|
148
|
+
return nil if @hash['updated_at'].nil?
|
149
|
+
return @hash['updated_at'] if @hash['updated_at'].is_a?(Time)
|
150
|
+
|
151
|
+
Time.at(@hash['updated_at'])
|
152
|
+
end
|
153
|
+
|
154
|
+
def create_record(**properties)
|
155
|
+
Record.create(@client, zone: { id: id }, **properties)
|
156
|
+
end
|
157
|
+
|
158
|
+
def create_or_update_record(**properties)
|
159
|
+
Record.create_or_update(@client, id, **properties)
|
160
|
+
end
|
161
|
+
|
162
|
+
def records(**options)
|
163
|
+
Record.all(@client, { id: id }, **options)
|
164
|
+
end
|
165
|
+
|
166
|
+
def record(value, field: :id)
|
167
|
+
record = Record.find_by(@client, field, value)
|
168
|
+
return nil if record.nil?
|
169
|
+
return nil if record.zone.id != id
|
170
|
+
|
171
|
+
record
|
172
|
+
end
|
173
|
+
|
174
|
+
def update(properties)
|
175
|
+
req = @client.api.create_request(:patch, 'zones/:zone')
|
176
|
+
req.arguments['zone'] = { id: id }
|
177
|
+
req.arguments['properties'] = properties
|
178
|
+
@hash = req.perform.hash['zone']
|
179
|
+
true
|
180
|
+
rescue ApiaClient::RequestError => e
|
181
|
+
raise ValidationError, e.detail['errors'] if e.code == 'validation_error'
|
182
|
+
|
183
|
+
raise
|
184
|
+
end
|
185
|
+
|
186
|
+
def delete
|
187
|
+
req = @client.api.create_request(:delete, 'zones/:zone')
|
188
|
+
req.arguments['zone'] = { id: id }
|
189
|
+
req.perform
|
190
|
+
true
|
191
|
+
end
|
192
|
+
|
193
|
+
def verify_nameservers
|
194
|
+
req = @client.api.create_request(:post, 'zones/:zone/verify_nameservers')
|
195
|
+
req.arguments['zone'] = { id: id }
|
196
|
+
@hash = req.perform.hash['zone']
|
197
|
+
verified?
|
198
|
+
rescue ApiaClient::RequestError => e
|
199
|
+
raise unless e.code == 'nameservers_already_verified'
|
200
|
+
|
201
|
+
true
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
|
206
|
+
def parse_time(time)
|
207
|
+
return nil if time.nil?
|
208
|
+
return time if time.is_a?(Time)
|
209
|
+
|
210
|
+
Time.at(time.to_i)
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
end
|
data/lib/dennis.rb
ADDED
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dennis-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Cooke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: apia-client
|
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
|
+
description: A client library for talking to the Dennis DNS API.
|
28
|
+
email:
|
29
|
+
- adam@krystal.uk
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- VERSION
|
35
|
+
- lib/dennis-client.rb
|
36
|
+
- lib/dennis.rb
|
37
|
+
- lib/dennis/client.rb
|
38
|
+
- lib/dennis/error.rb
|
39
|
+
- lib/dennis/group.rb
|
40
|
+
- lib/dennis/group_not_found_error.rb
|
41
|
+
- lib/dennis/nameserver.rb
|
42
|
+
- lib/dennis/paginated_array.rb
|
43
|
+
- lib/dennis/pagination.rb
|
44
|
+
- lib/dennis/record.rb
|
45
|
+
- lib/dennis/record_type.rb
|
46
|
+
- lib/dennis/validation_error.rb
|
47
|
+
- lib/dennis/validation_error_detail.rb
|
48
|
+
- lib/dennis/version.rb
|
49
|
+
- lib/dennis/zone.rb
|
50
|
+
- lib/dennis/zone_not_found_error.rb
|
51
|
+
homepage: https://github.com/krystal/dennis-client
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.5'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.1.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: A client library for talking to the Dennis DNS API.
|
74
|
+
test_files: []
|