gcloud 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +3 -3
  3. data/CHANGELOG.md +92 -0
  4. data/OVERVIEW.md +3 -3
  5. data/lib/gcloud.rb +75 -25
  6. data/lib/gcloud/backoff.rb +5 -1
  7. data/lib/gcloud/bigquery.rb +25 -43
  8. data/lib/gcloud/bigquery/copy_job.rb +13 -13
  9. data/lib/gcloud/bigquery/data.rb +20 -16
  10. data/lib/gcloud/bigquery/dataset.rb +202 -177
  11. data/lib/gcloud/bigquery/dataset/access.rb +118 -104
  12. data/lib/gcloud/bigquery/dataset/list.rb +14 -18
  13. data/lib/gcloud/bigquery/extract_job.rb +12 -12
  14. data/lib/gcloud/bigquery/insert_response.rb +12 -14
  15. data/lib/gcloud/bigquery/job.rb +45 -57
  16. data/lib/gcloud/bigquery/job/list.rb +18 -24
  17. data/lib/gcloud/bigquery/load_job.rb +35 -27
  18. data/lib/gcloud/bigquery/project.rb +53 -73
  19. data/lib/gcloud/bigquery/query_data.rb +28 -35
  20. data/lib/gcloud/bigquery/query_job.rb +18 -18
  21. data/lib/gcloud/bigquery/schema.rb +359 -0
  22. data/lib/gcloud/bigquery/service.rb +506 -0
  23. data/lib/gcloud/bigquery/table.rb +185 -266
  24. data/lib/gcloud/bigquery/table/list.rb +15 -19
  25. data/lib/gcloud/bigquery/view.rb +126 -81
  26. data/lib/gcloud/datastore.rb +39 -27
  27. data/lib/gcloud/datastore/commit.rb +2 -2
  28. data/lib/gcloud/datastore/dataset.rb +8 -19
  29. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -4
  30. data/lib/gcloud/datastore/dataset/query_results.rb +0 -2
  31. data/lib/gcloud/datastore/entity.rb +7 -1
  32. data/lib/gcloud/datastore/errors.rb +5 -27
  33. data/lib/gcloud/datastore/grpc_utils.rb +4 -3
  34. data/lib/gcloud/datastore/key.rb +6 -0
  35. data/lib/gcloud/datastore/service.rb +18 -12
  36. data/lib/gcloud/datastore/transaction.rb +0 -10
  37. data/lib/gcloud/dns.rb +29 -19
  38. data/lib/gcloud/dns/change.rb +10 -15
  39. data/lib/gcloud/dns/change/list.rb +4 -4
  40. data/lib/gcloud/dns/importer.rb +1 -1
  41. data/lib/gcloud/dns/project.rb +32 -49
  42. data/lib/gcloud/dns/record.rb +8 -2
  43. data/lib/gcloud/dns/record/list.rb +4 -4
  44. data/lib/gcloud/dns/service.rb +167 -0
  45. data/lib/gcloud/dns/zone.rb +33 -52
  46. data/lib/gcloud/dns/zone/list.rb +12 -16
  47. data/lib/gcloud/errors.rb +31 -19
  48. data/lib/gcloud/logging.rb +50 -39
  49. data/lib/gcloud/logging/entry.rb +197 -24
  50. data/lib/gcloud/logging/entry/list.rb +0 -2
  51. data/lib/gcloud/logging/logger.rb +1 -1
  52. data/lib/gcloud/logging/metric.rb +3 -9
  53. data/lib/gcloud/logging/metric/list.rb +0 -2
  54. data/lib/gcloud/logging/project.rb +58 -54
  55. data/lib/gcloud/logging/resource_descriptor.rb +2 -2
  56. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -2
  57. data/lib/gcloud/logging/service.rb +32 -23
  58. data/lib/gcloud/logging/sink.rb +8 -14
  59. data/lib/gcloud/logging/sink/list.rb +0 -2
  60. data/lib/gcloud/pubsub.rb +21 -16
  61. data/lib/gcloud/pubsub/policy.rb +204 -0
  62. data/lib/gcloud/pubsub/project.rb +26 -38
  63. data/lib/gcloud/pubsub/service.rb +39 -31
  64. data/lib/gcloud/pubsub/subscription.rb +56 -59
  65. data/lib/gcloud/pubsub/subscription/list.rb +4 -4
  66. data/lib/gcloud/pubsub/topic.rb +69 -66
  67. data/lib/gcloud/pubsub/topic/list.rb +0 -2
  68. data/lib/gcloud/pubsub/topic/{batch.rb → publisher.rb} +15 -2
  69. data/lib/gcloud/resource_manager.rb +27 -26
  70. data/lib/gcloud/resource_manager/manager.rb +19 -39
  71. data/lib/gcloud/resource_manager/policy.rb +211 -0
  72. data/lib/gcloud/resource_manager/project.rb +97 -121
  73. data/lib/gcloud/resource_manager/project/list.rb +7 -7
  74. data/lib/gcloud/resource_manager/project/updater.rb +4 -9
  75. data/lib/gcloud/resource_manager/service.rb +127 -0
  76. data/lib/gcloud/storage.rb +24 -42
  77. data/lib/gcloud/storage/bucket.rb +104 -192
  78. data/lib/gcloud/storage/bucket/acl.rb +47 -143
  79. data/lib/gcloud/storage/bucket/cors.rb +55 -11
  80. data/lib/gcloud/storage/bucket/list.rb +14 -14
  81. data/lib/gcloud/storage/errors.rb +3 -43
  82. data/lib/gcloud/storage/file.rb +114 -111
  83. data/lib/gcloud/storage/file/acl.rb +27 -113
  84. data/lib/gcloud/storage/file/list.rb +21 -21
  85. data/lib/gcloud/storage/project.rb +49 -59
  86. data/lib/gcloud/storage/service.rb +347 -0
  87. data/lib/gcloud/translate.rb +24 -14
  88. data/lib/gcloud/translate/api.rb +12 -21
  89. data/lib/gcloud/translate/detection.rb +5 -5
  90. data/lib/gcloud/translate/language.rb +1 -1
  91. data/lib/gcloud/translate/service.rb +80 -0
  92. data/lib/gcloud/translate/translation.rb +6 -6
  93. data/lib/gcloud/version.rb +1 -1
  94. data/lib/gcloud/vision.rb +24 -15
  95. data/lib/gcloud/vision/annotate.rb +24 -21
  96. data/lib/gcloud/vision/annotation.rb +9 -9
  97. data/lib/gcloud/vision/annotation/entity.rb +11 -11
  98. data/lib/gcloud/vision/annotation/face.rb +25 -25
  99. data/lib/gcloud/vision/annotation/properties.rb +8 -8
  100. data/lib/gcloud/vision/annotation/safe_search.rb +4 -4
  101. data/lib/gcloud/vision/annotation/text.rb +7 -7
  102. data/lib/gcloud/vision/annotation/vertex.rb +1 -1
  103. data/lib/gcloud/vision/image.rb +11 -11
  104. data/lib/gcloud/vision/location.rb +5 -2
  105. data/lib/gcloud/vision/project.rb +14 -16
  106. data/lib/gcloud/vision/service.rb +66 -0
  107. data/lib/google/api_client.rb +0 -0
  108. metadata +27 -24
  109. data/lib/gcloud/bigquery/connection.rb +0 -624
  110. data/lib/gcloud/bigquery/errors.rb +0 -68
  111. data/lib/gcloud/bigquery/table/schema.rb +0 -234
  112. data/lib/gcloud/dns/connection.rb +0 -173
  113. data/lib/gcloud/dns/errors.rb +0 -68
  114. data/lib/gcloud/resource_manager/connection.rb +0 -134
  115. data/lib/gcloud/resource_manager/errors.rb +0 -68
  116. data/lib/gcloud/storage/connection.rb +0 -444
  117. data/lib/gcloud/translate/connection.rb +0 -85
  118. data/lib/gcloud/translate/errors.rb +0 -68
  119. data/lib/gcloud/upload.rb +0 -95
  120. data/lib/gcloud/vision/connection.rb +0 -63
  121. data/lib/gcloud/vision/errors.rb +0 -69
@@ -1,68 +0,0 @@
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 "gcloud/errors"
17
-
18
- module Gcloud
19
- module Bigquery
20
- ##
21
- # Base BigQuery exception class.
22
- class Error < Gcloud::Error
23
- end
24
-
25
- ##
26
- # Raised when an API call is not successful.
27
- class ApiError < Error
28
- ##
29
- # The code of the error.
30
- attr_reader :code
31
-
32
- ##
33
- # The errors encountered.
34
- attr_reader :errors
35
-
36
- # @private
37
- def initialize message, code, errors = []
38
- super message
39
- @code = code
40
- @errors = errors
41
- end
42
-
43
- # @private
44
- def self.from_response resp
45
- if resp.data? && resp.data["error"]
46
- from_response_data resp.data["error"]
47
- else
48
- from_response_status resp
49
- end
50
- end
51
-
52
- # @private
53
- def self.from_response_data error
54
- new error["message"], error["code"], error["errors"]
55
- end
56
-
57
- # @private
58
- def self.from_response_status resp
59
- if resp.status == 404
60
- new "#{resp.error_message}: #{resp.request.uri.request_uri}",
61
- resp.status
62
- else
63
- new resp.error_message, resp.status
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,234 +0,0 @@
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 Gcloud
17
- module Bigquery
18
- class Table
19
- ##
20
- # # Table Schema
21
- #
22
- # A builder for BigQuery table schemas, passed to block arguments to
23
- # {Dataset#create_table} and {Table#schema}. Supports nested and
24
- # repeated fields via a nested block.
25
- #
26
- # @see https://cloud.google.com/bigquery/preparing-data-for-bigquery
27
- # Preparing Data for BigQuery
28
- #
29
- # @example
30
- # require "gcloud"
31
- #
32
- # gcloud = Gcloud.new
33
- # bigquery = gcloud.bigquery
34
- # dataset = bigquery.dataset "my_dataset"
35
- # table = dataset.create_table "my_table"
36
- #
37
- # table.schema do |schema|
38
- # schema.string "first_name", mode: :required
39
- # schema.record "cities_lived", mode: :repeated do |cities_lived|
40
- # cities_lived.string "place", mode: :required
41
- # cities_lived.integer "number_of_years", mode: :required
42
- # end
43
- # end
44
- #
45
- class Schema
46
- # @private
47
- MODES = %w( NULLABLE REQUIRED REPEATED )
48
-
49
- # @private
50
- TYPES = %w( STRING INTEGER FLOAT BOOLEAN TIMESTAMP RECORD )
51
-
52
- # @private
53
- attr_reader :fields
54
-
55
- ##
56
- # @private Initializes a new schema object with an existing schema.
57
- def initialize schema = nil, nested = false
58
- fields = (schema && schema["fields"]) || []
59
- @original_fields = fields.dup
60
- @fields = fields.dup
61
- @nested = nested
62
- end
63
-
64
- # @private
65
- def changed?
66
- @original_fields != @fields
67
- end
68
-
69
- ##
70
- # @private
71
- # Returns the schema as hash containing the keys and values specified by
72
- # the Google Cloud BigQuery [Rest API
73
- # ](https://cloud.google.com/bigquery/docs/reference/v2/tables#resource)
74
- # .
75
- def schema
76
- {
77
- "fields" => @fields
78
- }
79
- end
80
-
81
- ##
82
- # Adds a string field to the schema.
83
- #
84
- # @param [String] name The field name. The name must contain only
85
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
86
- # start with a letter or underscore. The maximum length is 128
87
- # characters.
88
- # @param [String] description A description of the field.
89
- # @param [Symbol] mode The field's mode. The possible values are
90
- # `:nullable`, `:required`, and `:repeated`. The default value is
91
- # `:nullable`.
92
- def string name, description: nil, mode: nil
93
- add_field name, :string, nil, description: description, mode: mode
94
- end
95
-
96
- ##
97
- # Adds an integer field to the schema.
98
- #
99
- # @param [String] name The field name. The name must contain only
100
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
101
- # start with a letter or underscore. The maximum length is 128
102
- # characters.
103
- # @param [String] description A description of the field.
104
- # @param [Symbol] mode The field's mode. The possible values are
105
- # `:nullable`, `:required`, and `:repeated`. The default value is
106
- # `:nullable`.
107
- def integer name, description: nil, mode: nil
108
- add_field name, :integer, nil, description: description, mode: mode
109
- end
110
-
111
- ##
112
- # Adds a floating-point number field to the schema.
113
- #
114
- # @param [String] name The field name. The name must contain only
115
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
116
- # start with a letter or underscore. The maximum length is 128
117
- # characters.
118
- # @param [String] description A description of the field.
119
- # @param [Symbol] mode The field's mode. The possible values are
120
- # `:nullable`, `:required`, and `:repeated`. The default value is
121
- # `:nullable`.
122
- def float name, description: nil, mode: nil
123
- add_field name, :float, nil, description: description, mode: mode
124
- end
125
-
126
- ##
127
- # Adds a boolean field to the schema.
128
- #
129
- # @param [String] name The field name. The name must contain only
130
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
131
- # start with a letter or underscore. The maximum length is 128
132
- # characters.
133
- # @param [String] description A description of the field.
134
- # @param [Symbol] mode The field's mode. The possible values are
135
- # `:nullable`, `:required`, and `:repeated`. The default value is
136
- # `:nullable`.
137
- def boolean name, description: nil, mode: nil
138
- add_field name, :boolean, nil, description: description, mode: mode
139
- end
140
-
141
- ##
142
- # Adds a timestamp field to the schema.
143
- #
144
- # @param [String] name The field name. The name must contain only
145
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
146
- # start with a letter or underscore. The maximum length is 128
147
- # characters.
148
- # @param [String] description A description of the field.
149
- # @param [Symbol] mode The field's mode. The possible values are
150
- # `:nullable`, `:required`, and `:repeated`. The default value is
151
- # `:nullable`.
152
- def timestamp name, description: nil, mode: nil
153
- add_field name, :timestamp, nil, description: description, mode: mode
154
- end
155
-
156
- ##
157
- # Adds a record field to the schema. A block must be passed describing
158
- # the nested fields of the record. For more information about nested
159
- # and repeated records, see [Preparing Data for BigQuery
160
- # ](https://cloud.google.com/bigquery/preparing-data-for-bigquery).
161
- #
162
- # @param [String] name The field name. The name must contain only
163
- # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
164
- # start with a letter or underscore. The maximum length is 128
165
- # characters.
166
- # @param [String] description A description of the field.
167
- # @param [Symbol] mode The field's mode. The possible values are
168
- # `:nullable`, `:required`, and `:repeated`. The default value is
169
- # `:nullable`.
170
- # @yield [nested_schema] a block for setting the nested schema
171
- # @yieldparam [Table::Schema] nested_schema the object accepting the
172
- # nested schema
173
- #
174
- # @example
175
- # require "gcloud"
176
- #
177
- # gcloud = Gcloud.new
178
- # bigquery = gcloud.bigquery
179
- # dataset = bigquery.dataset "my_dataset"
180
- # table = dataset.create_table "my_table"
181
- #
182
- # table.schema do |schema|
183
- # schema.string "first_name", mode: :required
184
- # schema.record "cities_lived", mode: :repeated do |cities_lived|
185
- # cities_lived.string "place", mode: :required
186
- # cities_lived.integer "number_of_years", mode: :required
187
- # end
188
- # end
189
- #
190
- def record name, description: nil, mode: nil
191
- fail ArgumentError, "nested RECORD type is not permitted" if @nested
192
- fail ArgumentError, "a block is required" unless block_given?
193
- nested_schema = self.class.new nil, true
194
- yield nested_schema
195
- add_field name, :record, nested_schema.fields,
196
- description: description, mode: mode
197
- end
198
-
199
- protected
200
-
201
- def upcase_type type
202
- upcase_type = type.to_s.upcase
203
- unless TYPES.include? upcase_type
204
- fail ArgumentError,
205
- "Type '#{upcase_type}' not found in #{TYPES.inspect}"
206
- end
207
- upcase_type
208
- end
209
-
210
- def upcase_mode mode
211
- upcase_mode = mode.to_s.upcase
212
- unless MODES.include? upcase_mode
213
- fail ArgumentError "Unable to determine mode for '#{mode}'"
214
- end
215
- upcase_mode
216
- end
217
-
218
- def add_field name, type, nested_fields, description: nil,
219
- mode: :nullable
220
- # Remove any existing field of this name
221
- @fields.reject! { |h| h["name"] == name }
222
- field = {
223
- "name" => name,
224
- "type" => upcase_type(type)
225
- }
226
- field["fields"] = nested_fields if nested_fields
227
- field["description"] = description if description
228
- field["mode"] = upcase_mode(mode) if mode
229
- @fields << field
230
- end
231
- end
232
- end
233
- end
234
- end
@@ -1,173 +0,0 @@
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 "gcloud/version"
17
- require "gcloud/backoff"
18
- require "google/api_client"
19
-
20
- module Gcloud
21
- module Dns
22
- ##
23
- # @private Represents the connection to DNS, as well as expose the API calls
24
- class Connection
25
- API_VERSION = "v1"
26
-
27
- attr_accessor :project
28
- attr_accessor :credentials
29
-
30
- ##
31
- # Creates a new Connection instance.
32
- def initialize project, credentials
33
- @project = project
34
- @credentials = credentials
35
- @client = Google::APIClient.new application_name: "gcloud-ruby",
36
- application_version: Gcloud::VERSION
37
- @client.authorization = @credentials.client
38
- @dns = @client.discovered_api "dns", API_VERSION
39
- end
40
-
41
- def get_project project_id = @project
42
- execute(
43
- api_method: @dns.projects.get,
44
- parameters: { project: project_id }
45
- )
46
- end
47
-
48
- def get_zone zone_id
49
- execute(
50
- api_method: @dns.managed_zones.get,
51
- parameters: { project: @project, managedZone: zone_id }
52
- )
53
- end
54
-
55
- def list_zones token: nil, max: nil
56
- params = { project: @project,
57
- pageToken: token,
58
- maxResults: max
59
- }.delete_if { |_, v| v.nil? }
60
-
61
- execute(
62
- api_method: @dns.managed_zones.list,
63
- parameters: params
64
- )
65
- end
66
-
67
- def create_zone zone_name, zone_dns, description: nil,
68
- name_server_set: nil
69
- body = { kind: "dns#managedZone",
70
- name: zone_name, dnsName: zone_dns,
71
- description: (description || ""),
72
- nameServerSet: name_server_set
73
- }.delete_if { |_, v| v.nil? }
74
-
75
- execute(
76
- api_method: @dns.managed_zones.create,
77
- parameters: { project: @project },
78
- body_object: body
79
- )
80
- end
81
-
82
- def delete_zone zone_id
83
- execute(
84
- api_method: @dns.managed_zones.delete,
85
- parameters: { project: @project, managedZone: zone_id }
86
- )
87
- end
88
-
89
- def get_change zone_id, change_id
90
- execute(
91
- api_method: @dns.changes.get,
92
- parameters: { project: @project, managedZone: zone_id,
93
- changeId: change_id }
94
- )
95
- end
96
-
97
- def list_changes zone_id, token: nil, max: nil, order: nil, sort: nil
98
- params = { project: @project, managedZone: zone_id,
99
- pageToken: token,
100
- maxResults: max,
101
- sortBy: sort,
102
- sortOrder: order
103
- }.delete_if { |_, v| v.nil? }
104
-
105
- execute(
106
- api_method: @dns.changes.list,
107
- parameters: params
108
- )
109
- end
110
-
111
- def create_change zone_id, additions, deletions
112
- change = { "kind" => "dns#change",
113
- "additions" => Array(additions),
114
- "deletions" => Array(deletions) }
115
-
116
- execute(
117
- api_method: @dns.changes.create,
118
- parameters: { project: @project, managedZone: zone_id },
119
- body_object: change
120
- )
121
- end
122
-
123
- def list_records zone_id, name = nil, type = nil, token: nil, max: nil
124
- params = { project: @project, managedZone: zone_id,
125
- pageToken: token,
126
- maxResults: max,
127
- name: name,
128
- type: type
129
- }.delete_if { |_, v| v.nil? }
130
-
131
- execute(
132
- api_method: @dns.resource_record_sets.list,
133
- parameters: params
134
- )
135
- end
136
-
137
- ##
138
- # Fully Qualified Domain Name
139
- def self.fqdn name, origin_dns
140
- name = name.to_s.strip
141
- return name if self.ip_addr? name
142
- name = origin_dns if name.empty?
143
- name = origin_dns if name == "@"
144
- name = "#{name}.#{origin_dns}" unless name.include? "."
145
- name = "#{name}." unless name.end_with? "."
146
- name
147
- end
148
-
149
- require "ipaddr"
150
- # Fix to make ip_addr? work on ruby 1.9
151
- IPAddr::Error = ArgumentError unless defined? IPAddr::Error
152
-
153
- def self.ip_addr? name
154
- IPAddr.new name
155
- true
156
- rescue IPAddr::Error
157
- false
158
- end
159
-
160
- def inspect
161
- "#{self.class}(#{@project})"
162
- end
163
-
164
- protected
165
-
166
- def execute options
167
- Gcloud::Backoff.new.execute_gapi do
168
- @client.execute options
169
- end
170
- end
171
- end
172
- end
173
- end