gcloud 0.3.1 → 0.4.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.
@@ -0,0 +1,75 @@
1
+ #--
2
+ # Copyright 2015 Google Inc. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Gcloud
17
+ module Dns
18
+ class Zone
19
+ ##
20
+ # Zone::List is a special case Array with additional values.
21
+ class List < DelegateClass(::Array)
22
+ ##
23
+ # If not empty, indicates that there are more records that match
24
+ # the request and this value should be passed to continue.
25
+ attr_accessor :token
26
+
27
+ ##
28
+ # Create a new Zone::List with an array of Zone instances.
29
+ def initialize arr = []
30
+ super arr
31
+ end
32
+
33
+ ##
34
+ # Whether there a next page of zones.
35
+ def next?
36
+ !token.nil?
37
+ end
38
+
39
+ ##
40
+ # Retrieve the next page of zones.
41
+ def next
42
+ return nil unless next?
43
+ ensure_connection!
44
+ resp = @connection.list_zones token: token
45
+ if resp.success?
46
+ Zone::List.from_response resp, @connection
47
+ else
48
+ fail ApiError.from_response(resp)
49
+ end
50
+ end
51
+
52
+ ##
53
+ # New Zones::List from a response object.
54
+ def self.from_response resp, conn #:nodoc:
55
+ zones = new(Array(resp.data["managedZones"]).map do |gapi_object|
56
+ Zone.from_gapi gapi_object, conn
57
+ end)
58
+ zones.instance_eval do
59
+ @token = resp.data["nextPageToken"]
60
+ @connection = conn
61
+ end
62
+ zones
63
+ end
64
+
65
+ protected
66
+
67
+ ##
68
+ # Raise an error unless an active connection is available.
69
+ def ensure_connection!
70
+ fail "Must have active connection" unless @connection
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,192 @@
1
+ #--
2
+ # Copyright 2015 Google Inc. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ module Gcloud
17
+ module Dns
18
+ class Zone
19
+ ##
20
+ # = DNS Zone Transaction
21
+ #
22
+ # This object is used by Zone#update when passed a block. These methods
23
+ # are used to update the records that are sent to the Google Cloud DNS
24
+ # API.
25
+ #
26
+ # require "gcloud"
27
+ #
28
+ # gcloud = Gcloud.new
29
+ # dns = gcloud.dns
30
+ # zone = dns.zone "example-com"
31
+ # zone.update do |tx|
32
+ # tx.add "example.com.", "A", 86400, "1.2.3.4"
33
+ # tx.remove "example.com.", "TXT"
34
+ # tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
35
+ # "20 mail2.example.com."]
36
+ # tx.modify "www.example.com.", "CNAME" do |cname|
37
+ # cname.ttl = 86400 # only change the TTL
38
+ # end
39
+ # end
40
+ #
41
+ class Transaction
42
+ attr_reader :additions, :deletions #:nodoc:
43
+
44
+ ##
45
+ # Creates a new transaction.
46
+ def initialize zone #:nodoc:
47
+ @zone = zone
48
+ @additions = []
49
+ @deletions = []
50
+ end
51
+
52
+ ##
53
+ # Adds a record to the Zone.
54
+ #
55
+ # === Parameters
56
+ #
57
+ # +name+::
58
+ # The owner of the record. For example: +example.com.+. (+String+)
59
+ # +type+::
60
+ # 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+. (+String+)
63
+ # +ttl+::
64
+ # The number of seconds that the record can be cached by resolvers.
65
+ # (+Integer+)
66
+ # +data+::
67
+ # The resource record data, as determined by +type+ and defined in
68
+ # {RFC 1035 (section 5)}[http://tools.ietf.org/html/rfc1035#section-5]
69
+ # and {RFC 1034 (section
70
+ # 3.6.1)}[http://tools.ietf.org/html/rfc1034#section-3.6.1]. For
71
+ # example: +192.0.2.1+ or +example.com.+. (+String+ or +Array+ of
72
+ # +String+)
73
+ #
74
+ # === Example
75
+ #
76
+ # require "gcloud"
77
+ #
78
+ # gcloud = Gcloud.new
79
+ # dns = gcloud.dns
80
+ # zone = dns.zone "example-com"
81
+ # zone.update do |tx|
82
+ # tx.add "example.com.", "A", 86400, "1.2.3.4"
83
+ # end
84
+ #
85
+ def add name, type, ttl, data
86
+ @additions += Array(@zone.record(name, type, ttl, data))
87
+ end
88
+
89
+ ##
90
+ # Removes records from the Zone. The records are looked up before they
91
+ # are removed.
92
+ #
93
+ # === Parameters
94
+ #
95
+ # +name+::
96
+ # The owner of the record. For example: +example.com.+. (+String+)
97
+ # +type+::
98
+ # The identifier of a {supported record
99
+ # type}[https://cloud.google.com/dns/what-is-cloud-dns].
100
+ # For example: +A+, +AAAA+, +CNAME+, +MX+, or +TXT+. (+String+)
101
+ #
102
+ # === Example
103
+ #
104
+ # require "gcloud"
105
+ #
106
+ # gcloud = Gcloud.new
107
+ # dns = gcloud.dns
108
+ # zone = dns.zone "example-com"
109
+ # zone.update do |tx|
110
+ # tx.remove "example.com.", "TXT"
111
+ # end
112
+ #
113
+ def remove name, type
114
+ @deletions += @zone.records(name: name, type: type).all
115
+ end
116
+
117
+ ##
118
+ # Replaces existing records on the Zone. Records matching the +name+ and
119
+ # +type+ are replaced.
120
+ #
121
+ # === Parameters
122
+ #
123
+ # +name+::
124
+ # The owner of the record. For example: +example.com.+. (+String+)
125
+ # +type+::
126
+ # The identifier of a {supported record
127
+ # type}[https://cloud.google.com/dns/what-is-cloud-dns].
128
+ # For example: +A+, +AAAA+, +CNAME+, +MX+, or +TXT+. (+String+)
129
+ # +ttl+::
130
+ # The number of seconds that the record can be cached by resolvers.
131
+ # (+Integer+)
132
+ # +data+::
133
+ # The resource record data, as determined by +type+ and defined in
134
+ # {RFC 1035 (section 5)}[http://tools.ietf.org/html/rfc1035#section-5]
135
+ # and {RFC 1034 (section
136
+ # 3.6.1)}[http://tools.ietf.org/html/rfc1034#section-3.6.1]. For
137
+ # example: +192.0.2.1+ or +example.com.+. (+String+ or +Array+ of
138
+ # +String+)
139
+ #
140
+ # === Example
141
+ #
142
+ # require "gcloud"
143
+ #
144
+ # gcloud = Gcloud.new
145
+ # dns = gcloud.dns
146
+ # zone = dns.zone "example-com"
147
+ # zone.update do |tx|
148
+ # tx.replace "example.com.", "MX", 86400, ["10 mail1.example.com.",
149
+ # "20 mail2.example.com."]
150
+ # end
151
+ #
152
+ def replace name, type, ttl, data
153
+ remove name, type
154
+ add name, type, ttl, data
155
+ end
156
+
157
+ ##
158
+ # Modifies records on the Zone. Records matching the +name+ and +type+
159
+ # are yielded to the block where they can be modified.
160
+ #
161
+ # === Parameters
162
+ #
163
+ # +name+::
164
+ # The owner of the record. For example: +example.com.+. (+String+)
165
+ # +type+::
166
+ # The identifier of a {supported record
167
+ # type}[https://cloud.google.com/dns/what-is-cloud-dns].
168
+ # For example: +A+, +AAAA+, +CNAME+, +MX+, or +TXT+. (+String+)
169
+ #
170
+ # === Example
171
+ #
172
+ # require "gcloud"
173
+ #
174
+ # gcloud = Gcloud.new
175
+ # dns = gcloud.dns
176
+ # zone.update do |tx|
177
+ # tx.modify "www.example.com.", "CNAME" do |cname|
178
+ # cname.ttl = 86400 # only change the TTL
179
+ # end
180
+ # end
181
+ #
182
+ def modify name, type
183
+ existing = @zone.records(name: name, type: type).all.to_a
184
+ updated = existing.map(&:dup)
185
+ updated.each { |r| yield r }
186
+ @additions += updated
187
+ @deletions += existing
188
+ end
189
+ end
190
+ end
191
+ end
192
+ end
@@ -229,19 +229,28 @@ module Gcloud
229
229
  #
230
230
  # === A note about large uploads
231
231
  #
232
- # You may encounter a broken pipe error while attempting to upload large
233
- # files. To avoid this problem, add
234
- # {httpclient}[https://rubygems.org/gems/httpclient] as a dependency to your
235
- # project, and configure {Faraday}[https://rubygems.org/gems/faraday] to use
236
- # it, after requiring Gcloud, but before initiating your Gcloud connection.
232
+ # You may encounter a Broken pipe (Errno::EPIPE) error when attempting to
233
+ # upload large files. To avoid this problem, add the
234
+ # {httpclient}[https://rubygems.org/gems/httpclient] gem to your project, and
235
+ # the line (or lines) of configuration shown below. These lines must execute
236
+ # after you require gcloud but before you make your first gcloud connection.
237
+ # The first statement configures {Faraday}[https://rubygems.org/gems/faraday]
238
+ # to use httpclient. The second statement, which should only be added if you
239
+ # are using a version of Faraday at or above 0.9.2, is a workaround for {this
240
+ # gzip issue}[https://github.com/GoogleCloudPlatform/gcloud-ruby/issues/367].
237
241
  #
238
242
  # require "gcloud"
239
243
  #
244
+ # # Use httpclient to avoid broken pipe errors with large uploads
240
245
  # Faraday.default_adapter = :httpclient
241
246
  #
247
+ # # Only add the following statement if using Faraday >= 0.9.2
248
+ # # Override gzip middleware with no-op for httpclient
249
+ # Faraday::Response.register_middleware :gzip =>
250
+ # Faraday::Response::Middleware
251
+ #
242
252
  # gcloud = Gcloud.new
243
253
  # storage = gcloud.storage
244
- # bucket = storage.bucket "my-todo-app"
245
254
  #
246
255
  # == Downloading a File
247
256
  #
@@ -326,20 +326,29 @@ module Gcloud
326
326
  #
327
327
  # ==== A note about large uploads
328
328
  #
329
- # You may encounter a broken pipe error while attempting to upload large
330
- # files. To avoid this problem, add
331
- # {httpclient}[https://rubygems.org/gems/httpclient] as a dependency to
332
- # your project, and configure {Faraday}[https://rubygems.org/gems/faraday]
333
- # to use it, after requiring Gcloud, but before initiating your Gcloud
334
- # connection.
329
+ # You may encounter a Broken pipe (Errno::EPIPE) error when attempting to
330
+ # upload large files. To avoid this problem, add the
331
+ # {httpclient}[https://rubygems.org/gems/httpclient] gem to your project,
332
+ # and the line (or lines) of configuration shown below. These lines must
333
+ # execute after you require gcloud but before you make your first gcloud
334
+ # connection. The first statement configures
335
+ # {Faraday}[https://rubygems.org/gems/faraday] to use httpclient. The
336
+ # second statement, which should only be added if you are using a version
337
+ # of Faraday at or above 0.9.2, is a workaround for {this gzip
338
+ # issue}[https://github.com/GoogleCloudPlatform/gcloud-ruby/issues/367].
335
339
  #
336
340
  # require "gcloud"
337
341
  #
342
+ # # Use httpclient to avoid broken pipe errors with large uploads
338
343
  # Faraday.default_adapter = :httpclient
339
344
  #
345
+ # # Only add the following statement if using Faraday >= 0.9.2
346
+ # # Override gzip middleware with no-op for httpclient
347
+ # Faraday::Response.register_middleware :gzip =>
348
+ # Faraday::Response::Middleware
349
+ #
340
350
  # gcloud = Gcloud.new
341
351
  # storage = gcloud.storage
342
- # bucket = storage.bucket "my-todo-app"
343
352
  #
344
353
  def create_file file, path = nil, options = {}
345
354
  ensure_connection!
@@ -16,5 +16,5 @@
16
16
  #--
17
17
  # Google Cloud Version
18
18
  module Gcloud
19
- VERSION = "0.3.1"
19
+ VERSION = "0.4.0"
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silvano Luciani
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-09 00:00:00.000000000 Z
12
+ date: 2015-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beefcake
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0.4'
70
+ - !ruby/object:Gem::Dependency
71
+ name: zonefile
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.04'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '1.04'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: minitest
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -258,6 +272,19 @@ files:
258
272
  - lib/gcloud/datastore/proto.rb
259
273
  - lib/gcloud/datastore/query.rb
260
274
  - lib/gcloud/datastore/transaction.rb
275
+ - lib/gcloud/dns.rb
276
+ - lib/gcloud/dns/change.rb
277
+ - lib/gcloud/dns/change/list.rb
278
+ - lib/gcloud/dns/connection.rb
279
+ - lib/gcloud/dns/credentials.rb
280
+ - lib/gcloud/dns/errors.rb
281
+ - lib/gcloud/dns/importer.rb
282
+ - lib/gcloud/dns/project.rb
283
+ - lib/gcloud/dns/record.rb
284
+ - lib/gcloud/dns/record/list.rb
285
+ - lib/gcloud/dns/zone.rb
286
+ - lib/gcloud/dns/zone/list.rb
287
+ - lib/gcloud/dns/zone/transaction.rb
261
288
  - lib/gcloud/errors.rb
262
289
  - lib/gcloud/gce.rb
263
290
  - lib/gcloud/proto/datastore_v1.pb.rb