google-cloud-dns 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,170 @@
1
+ # Copyright 2015 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "delegate"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Dns
21
+ class Zone
22
+ ##
23
+ # Zone::List is a special case Array with additional values.
24
+ class List < DelegateClass(::Array)
25
+ ##
26
+ # If not empty, indicates that there are more zones that match
27
+ # the request and this value should be passed to continue.
28
+ attr_accessor :token
29
+
30
+ ##
31
+ # @private Create a new Zone::List with an array of Zone instances.
32
+ def initialize arr = []
33
+ super arr
34
+ end
35
+
36
+ ##
37
+ # Whether there a next page of zones.
38
+ #
39
+ # @return [Boolean]
40
+ #
41
+ # @example
42
+ # require "google/cloud"
43
+ #
44
+ # gcloud = Google::Cloud.new
45
+ # dns = gcloud.dns
46
+ #
47
+ # zones = dns.zones
48
+ # if zones.next?
49
+ # next_zones = zones.next
50
+ # end
51
+ #
52
+ def next?
53
+ !token.nil?
54
+ end
55
+
56
+ ##
57
+ # Retrieve the next page of zones.
58
+ #
59
+ # @return [Zone::List]
60
+ #
61
+ # @example
62
+ # require "google/cloud"
63
+ #
64
+ # gcloud = Google::Cloud.new
65
+ # dns = gcloud.dns
66
+ #
67
+ # zones = dns.zones
68
+ # if zones.next?
69
+ # next_zones = zones.next
70
+ # end
71
+ #
72
+ def next
73
+ return nil unless next?
74
+ ensure_service!
75
+ gapi = @service.list_zones token: token, max: @max
76
+ Zone::List.from_gapi gapi, @service, @max
77
+ end
78
+
79
+ ##
80
+ # Retrieves all zones by repeatedly loading {#next} until {#next?}
81
+ # returns `false`. Calls the given block once for each zone, which is
82
+ # passed as the parameter.
83
+ #
84
+ # An Enumerator is returned if no block is given.
85
+ #
86
+ # This method may make several API calls until all zones are
87
+ # retrieved. Be sure to use as narrow a search criteria as possible.
88
+ # Please use with caution.
89
+ #
90
+ # @param [Integer] request_limit The upper limit of API requests to
91
+ # make to load all zones. Default is no limit.
92
+ # @yield [zone] The block for accessing each zone.
93
+ # @yieldparam [Zone] zone The zone object.
94
+ #
95
+ # @return [Enumerator]
96
+ #
97
+ # @example Iterating each zone by passing a block:
98
+ # require "google/cloud"
99
+ #
100
+ # gcloud = Google::Cloud.new
101
+ # dns = gcloud.dns
102
+ # zones = dns.zones
103
+ #
104
+ # zones.all do |zone|
105
+ # puts zone.name
106
+ # end
107
+ #
108
+ # @example Using the enumerator by not passing a block:
109
+ # require "google/cloud"
110
+ #
111
+ # gcloud = Google::Cloud.new
112
+ # dns = gcloud.dns
113
+ # zones = dns.zones
114
+ #
115
+ # all_names = zones.all.map do |zone|
116
+ # zone.name
117
+ # end
118
+ #
119
+ # @example Limit the number of API calls made:
120
+ # require "google/cloud"
121
+ #
122
+ # gcloud = Google::Cloud.new
123
+ # dns = gcloud.dns
124
+ # zones = dns.zones
125
+ #
126
+ # zones.all(request_limit: 10) do |zone|
127
+ # puts zone.name
128
+ # end
129
+ #
130
+ def all request_limit: nil
131
+ request_limit = request_limit.to_i if request_limit
132
+ unless block_given?
133
+ return enum_for(:all, request_limit: request_limit)
134
+ end
135
+ results = self
136
+ loop do
137
+ results.each { |r| yield r }
138
+ if request_limit
139
+ request_limit -= 1
140
+ break if request_limit < 0
141
+ end
142
+ break unless results.next?
143
+ results = results.next
144
+ end
145
+ end
146
+
147
+ ##
148
+ # @private New Zones::List from a ListManagedZonesResponse object.
149
+ def self.from_gapi gapi, conn, max = nil
150
+ zones = new(Array(gapi.managed_zones).map do |g|
151
+ Zone.from_gapi g, conn
152
+ end)
153
+ zones.instance_variable_set "@token", gapi.next_page_token
154
+ zones.instance_variable_set "@service", conn
155
+ zones.instance_variable_set "@max", max
156
+ zones
157
+ end
158
+
159
+ protected
160
+
161
+ ##
162
+ # Raise an error unless an active connection is available.
163
+ def ensure_service!
164
+ fail "Must have active connection" unless @service
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,180 @@
1
+ # Copyright 2015 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Cloud
18
+ module Dns
19
+ class Zone
20
+ ##
21
+ # # DNS Zone Transaction
22
+ #
23
+ # This object is used by {Zone#update} when passed a block. These
24
+ # methods are used to update the records that are sent to the Google
25
+ # Cloud DNS API.
26
+ #
27
+ # @example
28
+ # require "google/cloud"
29
+ #
30
+ # gcloud = Google::Cloud.new
31
+ # dns = gcloud.dns
32
+ # zone = dns.zone "example-com"
33
+ # zone.update do |tx|
34
+ # tx.add "example.com.", "A", 86400, "1.2.3.4"
35
+ # tx.remove "example.com.", "TXT"
36
+ # tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
37
+ # "20 mail2.example.com."]
38
+ # tx.modify "www.example.com.", "CNAME" do |cname|
39
+ # cname.ttl = 86400 # only change the TTL
40
+ # end
41
+ # end
42
+ #
43
+ class Transaction
44
+ # @private
45
+ attr_reader :additions, :deletions
46
+
47
+ ##
48
+ # @private Creates a new transaction.
49
+ def initialize zone
50
+ @zone = zone
51
+ @additions = []
52
+ @deletions = []
53
+ end
54
+
55
+ ##
56
+ # Adds a record to the Zone.
57
+ #
58
+ # @param [String] name The owner of the record. For example:
59
+ # `example.com.`.
60
+ # @param [String] type The identifier of a [supported record
61
+ # type](https://cloud.google.com/dns/what-is-cloud-dns).
62
+ # For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
63
+ # @param [Integer] ttl The number of seconds that the record can be
64
+ # cached by resolvers.
65
+ # @param [String, Array<String>] data The resource record data, as
66
+ # determined by `type` and defined in [RFC 1035 (section
67
+ # 5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034
68
+ # (section
69
+ # 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For
70
+ # example: `192.0.2.1` or `example.com.`.
71
+ #
72
+ # @example
73
+ # require "google/cloud"
74
+ #
75
+ # gcloud = Google::Cloud.new
76
+ # dns = gcloud.dns
77
+ # zone = dns.zone "example-com"
78
+ # zone.update do |tx|
79
+ # tx.add "example.com.", "A", 86400, "1.2.3.4"
80
+ # end
81
+ #
82
+ def add name, type, ttl, data
83
+ @additions += Array(@zone.record(name, type, ttl, data))
84
+ end
85
+
86
+ ##
87
+ # Removes records from the Zone. The records are looked up before they
88
+ # are removed.
89
+ #
90
+ # @param [String] name The owner of the record. For example:
91
+ # `example.com.`.
92
+ # @param [String] type The identifier of a [supported record
93
+ # type](https://cloud.google.com/dns/what-is-cloud-dns).
94
+ # For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
95
+ #
96
+ # @example
97
+ # require "google/cloud"
98
+ #
99
+ # gcloud = Google::Cloud.new
100
+ # dns = gcloud.dns
101
+ # zone = dns.zone "example-com"
102
+ # zone.update do |tx|
103
+ # tx.remove "example.com.", "TXT"
104
+ # end
105
+ #
106
+ def remove name, type
107
+ @deletions += @zone.records(name, type).all.to_a
108
+ end
109
+
110
+ ##
111
+ # Replaces existing records on the Zone. Records matching the `name`
112
+ # and `type` are replaced.
113
+ #
114
+ # @param [String] name The owner of the record. For example:
115
+ # `example.com.`.
116
+ # @param [String] type The identifier of a [supported record
117
+ # type](https://cloud.google.com/dns/what-is-cloud-dns).
118
+ # For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
119
+ # @param [Integer] ttl The number of seconds that the record can be
120
+ # cached by resolvers.
121
+ # @param [String, Array<String>] data The resource record data, as
122
+ # determined by `type` and defined in [RFC 1035 (section
123
+ # 5)](http://tools.ietf.org/html/rfc1035#section-5) and [RFC 1034
124
+ # (section
125
+ # 3.6.1)](http://tools.ietf.org/html/rfc1034#section-3.6.1). For
126
+ # example: `192.0.2.1` or `example.com.`.
127
+ #
128
+ # @example
129
+ # require "google/cloud"
130
+ #
131
+ # gcloud = Google::Cloud.new
132
+ # dns = gcloud.dns
133
+ # zone = dns.zone "example-com"
134
+ # zone.update do |tx|
135
+ # tx.replace "example.com.",
136
+ # "MX", 86400,
137
+ # ["10 mail1.example.com.",
138
+ # "20 mail2.example.com."]
139
+ # end
140
+ #
141
+ def replace name, type, ttl, data
142
+ remove name, type
143
+ add name, type, ttl, data
144
+ end
145
+
146
+ ##
147
+ # Modifies records on the Zone. Records matching the `name` and `type`
148
+ # are yielded to the block where they can be modified.
149
+ #
150
+ # @param [String] name The owner of the record. For example:
151
+ # `example.com.`.
152
+ # @param [String] type The identifier of a [supported record
153
+ # type](https://cloud.google.com/dns/what-is-cloud-dns).
154
+ # For example: `A`, `AAAA`, `CNAME`, `MX`, or `TXT`.
155
+ # @yield [record] a block yielding each matching record
156
+ # @yieldparam [Record] record the record to be modified
157
+ #
158
+ # @example
159
+ # require "google/cloud"
160
+ #
161
+ # gcloud = Google::Cloud.new
162
+ # dns = gcloud.dns
163
+ # zone.update do |tx|
164
+ # tx.modify "www.example.com.", "CNAME" do |cname|
165
+ # cname.ttl = 86400 # only change the TTL
166
+ # end
167
+ # end
168
+ #
169
+ def modify name, type
170
+ existing = @zone.records(name, type).all.to_a
171
+ updated = existing.map(&:dup)
172
+ updated.each { |r| yield r }
173
+ @additions += updated
174
+ @deletions += existing
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-cloud-dns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.20.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Moore
8
+ - Chris Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-08-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: google-cloud-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.20.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.20.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: google-api-client
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.9.11
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.9.11
42
+ - !ruby/object:Gem::Dependency
43
+ name: zonefile
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.04'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.04'
56
+ - !ruby/object:Gem::Dependency
57
+ name: minitest
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '5.9'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '5.9'
70
+ - !ruby/object:Gem::Dependency
71
+ name: minitest-autotest
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: minitest-focus
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.1'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.1'
98
+ - !ruby/object:Gem::Dependency
99
+ name: minitest-rg
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '5.2'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '5.2'
112
+ - !ruby/object:Gem::Dependency
113
+ name: autotest-suffix
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.1'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.1'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "<="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.35.1
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "<="
138
+ - !ruby/object:Gem::Version
139
+ version: 0.35.1
140
+ - !ruby/object:Gem::Dependency
141
+ name: simplecov
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '0.9'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '0.9'
154
+ - !ruby/object:Gem::Dependency
155
+ name: yard
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '0.9'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0.9'
168
+ description: google-cloud-dns is the official library for Google Cloud DNS.
169
+ email:
170
+ - mike@blowmage.com
171
+ - quartzmo@gmail.com
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - lib/google-cloud-dns.rb
177
+ - lib/google/cloud/dns.rb
178
+ - lib/google/cloud/dns/change.rb
179
+ - lib/google/cloud/dns/change/list.rb
180
+ - lib/google/cloud/dns/credentials.rb
181
+ - lib/google/cloud/dns/importer.rb
182
+ - lib/google/cloud/dns/project.rb
183
+ - lib/google/cloud/dns/record.rb
184
+ - lib/google/cloud/dns/record/list.rb
185
+ - lib/google/cloud/dns/service.rb
186
+ - lib/google/cloud/dns/version.rb
187
+ - lib/google/cloud/dns/zone.rb
188
+ - lib/google/cloud/dns/zone/list.rb
189
+ - lib/google/cloud/dns/zone/transaction.rb
190
+ homepage: http://googlecloudplatform.github.io/google-cloud-ruby/
191
+ licenses:
192
+ - Apache-2.0
193
+ metadata: {}
194
+ post_install_message:
195
+ rdoc_options: []
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: 2.0.0
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ requirements: []
209
+ rubyforge_project:
210
+ rubygems_version: 2.6.4
211
+ signing_key:
212
+ specification_version: 4
213
+ summary: API Client library for Google Cloud DNS
214
+ test_files: []