gcloud 0.12.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/gcloud.rb +27 -456
- data/lib/gcloud/bigquery.rb +2 -382
- data/lib/gcloud/datastore.rb +2 -576
- data/lib/gcloud/dns.rb +2 -321
- data/lib/gcloud/logging.rb +1 -322
- data/lib/gcloud/pubsub.rb +2 -476
- data/lib/gcloud/resource_manager.rb +2 -273
- data/lib/gcloud/storage.rb +2 -440
- data/lib/gcloud/translate.rb +1 -250
- data/lib/gcloud/version.rb +2 -2
- data/lib/gcloud/vision.rb +1 -501
- metadata +36 -332
- data/AUTHENTICATION.md +0 -75
- data/CHANGELOG.md +0 -382
- data/OVERVIEW.md +0 -259
- data/lib/gcloud/backoff.rb +0 -150
- data/lib/gcloud/bigquery/copy_job.rb +0 -97
- data/lib/gcloud/bigquery/credentials.rb +0 -29
- data/lib/gcloud/bigquery/data.rb +0 -239
- data/lib/gcloud/bigquery/dataset.rb +0 -753
- data/lib/gcloud/bigquery/dataset/access.rb +0 -507
- data/lib/gcloud/bigquery/dataset/list.rb +0 -169
- data/lib/gcloud/bigquery/extract_job.rb +0 -117
- data/lib/gcloud/bigquery/insert_response.rb +0 -81
- data/lib/gcloud/bigquery/job.rb +0 -299
- data/lib/gcloud/bigquery/job/list.rb +0 -172
- data/lib/gcloud/bigquery/load_job.rb +0 -202
- data/lib/gcloud/bigquery/project.rb +0 -475
- data/lib/gcloud/bigquery/query_data.rb +0 -234
- data/lib/gcloud/bigquery/query_job.rb +0 -137
- data/lib/gcloud/bigquery/schema.rb +0 -359
- data/lib/gcloud/bigquery/service.rb +0 -506
- data/lib/gcloud/bigquery/table.rb +0 -1141
- data/lib/gcloud/bigquery/table/list.rb +0 -180
- data/lib/gcloud/bigquery/view.rb +0 -475
- data/lib/gcloud/credentials.rb +0 -129
- data/lib/gcloud/datastore/commit.rb +0 -148
- data/lib/gcloud/datastore/credentials.rb +0 -35
- data/lib/gcloud/datastore/cursor.rb +0 -76
- data/lib/gcloud/datastore/dataset.rb +0 -660
- data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
- data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
- data/lib/gcloud/datastore/entity.rb +0 -449
- data/lib/gcloud/datastore/errors.rb +0 -41
- data/lib/gcloud/datastore/gql_query.rb +0 -211
- data/lib/gcloud/datastore/grpc_utils.rb +0 -132
- data/lib/gcloud/datastore/key.rb +0 -281
- data/lib/gcloud/datastore/properties.rb +0 -128
- data/lib/gcloud/datastore/query.rb +0 -348
- data/lib/gcloud/datastore/service.rb +0 -167
- data/lib/gcloud/datastore/transaction.rb +0 -362
- data/lib/gcloud/dns/change.rb +0 -158
- data/lib/gcloud/dns/change/list.rb +0 -173
- data/lib/gcloud/dns/credentials.rb +0 -29
- data/lib/gcloud/dns/importer.rb +0 -183
- data/lib/gcloud/dns/project.rb +0 -247
- data/lib/gcloud/dns/record.rb +0 -170
- data/lib/gcloud/dns/record/list.rb +0 -174
- data/lib/gcloud/dns/service.rb +0 -167
- data/lib/gcloud/dns/zone.rb +0 -759
- data/lib/gcloud/dns/zone/list.rb +0 -168
- data/lib/gcloud/dns/zone/transaction.rb +0 -176
- data/lib/gcloud/errors.rb +0 -206
- data/lib/gcloud/gce.rb +0 -56
- data/lib/gcloud/grpc_utils.rb +0 -87
- data/lib/gcloud/logging/credentials.rb +0 -29
- data/lib/gcloud/logging/entry.rb +0 -465
- data/lib/gcloud/logging/entry/http_request.rb +0 -141
- data/lib/gcloud/logging/entry/list.rb +0 -177
- data/lib/gcloud/logging/entry/operation.rb +0 -90
- data/lib/gcloud/logging/logger.rb +0 -307
- data/lib/gcloud/logging/metric.rb +0 -169
- data/lib/gcloud/logging/metric/list.rb +0 -172
- data/lib/gcloud/logging/project.rb +0 -642
- data/lib/gcloud/logging/resource.rb +0 -84
- data/lib/gcloud/logging/resource_descriptor.rb +0 -137
- data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
- data/lib/gcloud/logging/service.rb +0 -267
- data/lib/gcloud/logging/sink.rb +0 -227
- data/lib/gcloud/logging/sink/list.rb +0 -171
- data/lib/gcloud/pubsub/credentials.rb +0 -29
- data/lib/gcloud/pubsub/message.rb +0 -94
- data/lib/gcloud/pubsub/policy.rb +0 -204
- data/lib/gcloud/pubsub/project.rb +0 -482
- data/lib/gcloud/pubsub/received_message.rb +0 -160
- data/lib/gcloud/pubsub/service.rb +0 -334
- data/lib/gcloud/pubsub/subscription.rb +0 -565
- data/lib/gcloud/pubsub/subscription/list.rb +0 -208
- data/lib/gcloud/pubsub/topic.rb +0 -511
- data/lib/gcloud/pubsub/topic/list.rb +0 -174
- data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
- data/lib/gcloud/resource_manager/credentials.rb +0 -30
- data/lib/gcloud/resource_manager/manager.rb +0 -266
- data/lib/gcloud/resource_manager/policy.rb +0 -211
- data/lib/gcloud/resource_manager/project.rb +0 -484
- data/lib/gcloud/resource_manager/project/list.rb +0 -167
- data/lib/gcloud/resource_manager/project/updater.rb +0 -130
- data/lib/gcloud/resource_manager/service.rb +0 -127
- data/lib/gcloud/storage/bucket.rb +0 -775
- data/lib/gcloud/storage/bucket/acl.rb +0 -810
- data/lib/gcloud/storage/bucket/cors.rb +0 -153
- data/lib/gcloud/storage/bucket/list.rb +0 -172
- data/lib/gcloud/storage/credentials.rb +0 -29
- data/lib/gcloud/storage/errors.rb +0 -65
- data/lib/gcloud/storage/file.rb +0 -842
- data/lib/gcloud/storage/file/acl.rb +0 -425
- data/lib/gcloud/storage/file/list.rb +0 -191
- data/lib/gcloud/storage/file/verifier.rb +0 -67
- data/lib/gcloud/storage/project.rb +0 -316
- data/lib/gcloud/storage/service.rb +0 -347
- data/lib/gcloud/translate/api.rb +0 -241
- data/lib/gcloud/translate/detection.rb +0 -137
- data/lib/gcloud/translate/language.rb +0 -69
- data/lib/gcloud/translate/service.rb +0 -80
- data/lib/gcloud/translate/translation.rb +0 -112
- data/lib/gcloud/vision/annotate.rb +0 -224
- data/lib/gcloud/vision/annotation.rb +0 -455
- data/lib/gcloud/vision/annotation/entity.rb +0 -234
- data/lib/gcloud/vision/annotation/face.rb +0 -1750
- data/lib/gcloud/vision/annotation/properties.rb +0 -245
- data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
- data/lib/gcloud/vision/annotation/text.rb +0 -236
- data/lib/gcloud/vision/annotation/vertex.rb +0 -108
- data/lib/gcloud/vision/credentials.rb +0 -29
- data/lib/gcloud/vision/image.rb +0 -590
- data/lib/gcloud/vision/location.rb +0 -115
- data/lib/gcloud/vision/project.rb +0 -278
- data/lib/gcloud/vision/service.rb +0 -66
- data/lib/google/api/annotations.rb +0 -14
- data/lib/google/api/http.rb +0 -30
- data/lib/google/api/label.rb +0 -24
- data/lib/google/api/monitored_resource.rb +0 -25
- data/lib/google/datastore/v1beta3/datastore.rb +0 -115
- data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
- data/lib/google/datastore/v1beta3/entity.rb +0 -63
- data/lib/google/datastore/v1beta3/query.rb +0 -128
- data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
- data/lib/google/example/library/v1/library.rb +0 -91
- data/lib/google/example/library/v1/library_services.rb +0 -40
- data/lib/google/iam/v1/iam_policy.rb +0 -33
- data/lib/google/iam/v1/iam_policy_services.rb +0 -30
- data/lib/google/iam/v1/policy.rb +0 -25
- data/lib/google/logging/type/http_request.rb +0 -28
- data/lib/google/logging/type/log_severity.rb +0 -27
- data/lib/google/logging/v2/log_entry.rb +0 -44
- data/lib/google/logging/v2/logging.rb +0 -56
- data/lib/google/logging/v2/logging_config.rb +0 -59
- data/lib/google/logging/v2/logging_config_services.rb +0 -32
- data/lib/google/logging/v2/logging_metrics.rb +0 -51
- data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
- data/lib/google/logging/v2/logging_services.rb +0 -31
- data/lib/google/longrunning/operations.rb +0 -50
- data/lib/google/longrunning/operations_services.rb +0 -29
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/pubsub/v1/pubsub.rb +0 -129
- data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
- data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
- data/lib/google/rpc/code.rb +0 -32
- data/lib/google/rpc/error_details.rb +0 -61
- data/lib/google/rpc/status.rb +0 -19
- data/lib/google/type/color.rb +0 -20
- data/lib/google/type/date.rb +0 -18
- data/lib/google/type/dayofweek.rb +0 -23
- data/lib/google/type/latlng.rb +0 -17
- data/lib/google/type/money.rb +0 -18
- data/lib/google/type/timeofday.rb +0 -19
@@ -1,67 +0,0 @@
|
|
1
|
-
# Copyright 2014 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 "pathname"
|
17
|
-
require "digest/md5"
|
18
|
-
require "digest/crc32c"
|
19
|
-
require "gcloud/storage/errors"
|
20
|
-
|
21
|
-
module Gcloud
|
22
|
-
module Storage
|
23
|
-
class File
|
24
|
-
##
|
25
|
-
# @private
|
26
|
-
# Verifies downloaded files by creating an MD5 or CRC32c hash digest
|
27
|
-
# and comparing the value to the one from the Storage API.
|
28
|
-
module Verifier
|
29
|
-
def self.verify_md5! gcloud_file, local_file
|
30
|
-
gcloud_digest = gcloud_file.md5
|
31
|
-
local_digest = md5_for local_file
|
32
|
-
if gcloud_digest != local_digest
|
33
|
-
fail FileVerificationError.for_md5(gcloud_digest, local_digest)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.verify_crc32c! gcloud_file, local_file
|
38
|
-
gcloud_digest = gcloud_file.crc32c
|
39
|
-
local_digest = crc32c_for local_file
|
40
|
-
if gcloud_digest != local_digest
|
41
|
-
fail FileVerificationError.for_crc32c(gcloud_digest, local_digest)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.verify_md5 gcloud_file, local_file
|
46
|
-
gcloud_file.md5 == md5_for(local_file)
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.verify_crc32c gcloud_file, local_file
|
50
|
-
gcloud_file.crc32c == crc32c_for(local_file)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.md5_for local_file
|
54
|
-
::File.open(Pathname(local_file).to_path, "rb") do |f|
|
55
|
-
::Digest::MD5.file(f).base64digest
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.crc32c_for local_file
|
60
|
-
::File.open(Pathname(local_file).to_path, "rb") do |f|
|
61
|
-
::Digest::CRC32c.file(f).base64digest
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,316 +0,0 @@
|
|
1
|
-
# Copyright 2014 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/gce"
|
17
|
-
require "gcloud/storage/errors"
|
18
|
-
require "gcloud/storage/service"
|
19
|
-
require "gcloud/storage/credentials"
|
20
|
-
require "gcloud/storage/bucket"
|
21
|
-
require "gcloud/storage/bucket/cors"
|
22
|
-
require "gcloud/storage/file"
|
23
|
-
|
24
|
-
module Gcloud
|
25
|
-
module Storage
|
26
|
-
##
|
27
|
-
# # Project
|
28
|
-
#
|
29
|
-
# Represents the project that storage buckets and files belong to.
|
30
|
-
# All data in Google Cloud Storage belongs inside a project.
|
31
|
-
# A project consists of a set of users, a set of APIs, billing,
|
32
|
-
# authentication, and monitoring settings for those APIs.
|
33
|
-
#
|
34
|
-
# Gcloud::Storage::Project is the main object for interacting with
|
35
|
-
# Google Storage. {Gcloud::Storage::Bucket} objects are created,
|
36
|
-
# read, updated, and deleted by Gcloud::Storage::Project.
|
37
|
-
#
|
38
|
-
# See {Gcloud#storage}
|
39
|
-
#
|
40
|
-
# @example
|
41
|
-
# require "gcloud"
|
42
|
-
#
|
43
|
-
# gcloud = Gcloud.new
|
44
|
-
# storage = gcloud.storage
|
45
|
-
#
|
46
|
-
# bucket = storage.bucket "my-bucket"
|
47
|
-
# file = bucket.file "path/to/my-file.ext"
|
48
|
-
#
|
49
|
-
class Project
|
50
|
-
##
|
51
|
-
# @private The Service object.
|
52
|
-
attr_accessor :service
|
53
|
-
|
54
|
-
##
|
55
|
-
# @private Creates a new Project instance.
|
56
|
-
#
|
57
|
-
# See {Gcloud#storage}
|
58
|
-
def initialize service
|
59
|
-
@service = service
|
60
|
-
end
|
61
|
-
|
62
|
-
##
|
63
|
-
# The Storage project connected to.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# require "gcloud"
|
67
|
-
#
|
68
|
-
# gcloud = Gcloud.new "my-todo-project",
|
69
|
-
# "/path/to/keyfile.json"
|
70
|
-
# storage = gcloud.storage
|
71
|
-
#
|
72
|
-
# storage.project #=> "my-todo-project"
|
73
|
-
#
|
74
|
-
def project
|
75
|
-
service.project
|
76
|
-
end
|
77
|
-
|
78
|
-
##
|
79
|
-
# @private Default project.
|
80
|
-
def self.default_project
|
81
|
-
ENV["STORAGE_PROJECT"] ||
|
82
|
-
ENV["GCLOUD_PROJECT"] ||
|
83
|
-
ENV["GOOGLE_CLOUD_PROJECT"] ||
|
84
|
-
Gcloud::GCE.project_id
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
# Retrieves a list of buckets for the given project.
|
89
|
-
#
|
90
|
-
# @param [String] prefix Filter results to buckets whose names begin with
|
91
|
-
# this prefix.
|
92
|
-
# @param [String] token A previously-returned page token representing part
|
93
|
-
# of the larger set of results to view.
|
94
|
-
# @param [Integer] max Maximum number of buckets to return.
|
95
|
-
#
|
96
|
-
# @return [Array<Gcloud::Storage::Bucket>] (See
|
97
|
-
# {Gcloud::Storage::Bucket::List})
|
98
|
-
#
|
99
|
-
# @example
|
100
|
-
# require "gcloud"
|
101
|
-
#
|
102
|
-
# gcloud = Gcloud.new
|
103
|
-
# storage = gcloud.storage
|
104
|
-
#
|
105
|
-
# buckets = storage.buckets
|
106
|
-
# buckets.each do |bucket|
|
107
|
-
# puts bucket.name
|
108
|
-
# end
|
109
|
-
#
|
110
|
-
# @example Retrieve buckets with names that begin with a given prefix:
|
111
|
-
# require "gcloud"
|
112
|
-
#
|
113
|
-
# gcloud = Gcloud.new
|
114
|
-
# storage = gcloud.storage
|
115
|
-
#
|
116
|
-
# user_buckets = storage.buckets prefix: "user-"
|
117
|
-
# user_buckets.each do |bucket|
|
118
|
-
# puts bucket.name
|
119
|
-
# end
|
120
|
-
#
|
121
|
-
# @example Retrieve all buckets: (See {Bucket::List#all})
|
122
|
-
# require "gcloud"
|
123
|
-
#
|
124
|
-
# gcloud = Gcloud.new
|
125
|
-
# storage = gcloud.storage
|
126
|
-
#
|
127
|
-
# buckets = storage.buckets
|
128
|
-
# buckets.all do |bucket|
|
129
|
-
# puts bucket.name
|
130
|
-
# end
|
131
|
-
#
|
132
|
-
def buckets prefix: nil, token: nil, max: nil
|
133
|
-
options = { prefix: prefix, token: token, max: max }
|
134
|
-
gapi = service.list_buckets options
|
135
|
-
Bucket::List.from_gapi gapi, service, prefix, max
|
136
|
-
end
|
137
|
-
alias_method :find_buckets, :buckets
|
138
|
-
|
139
|
-
##
|
140
|
-
# Retrieves bucket by name.
|
141
|
-
#
|
142
|
-
# @param [String] bucket_name Name of a bucket.
|
143
|
-
#
|
144
|
-
# @return [Gcloud::Storage::Bucket, nil] Returns nil if bucket does not
|
145
|
-
# exist
|
146
|
-
#
|
147
|
-
# @example
|
148
|
-
# require "gcloud"
|
149
|
-
#
|
150
|
-
# gcloud = Gcloud.new
|
151
|
-
# storage = gcloud.storage
|
152
|
-
#
|
153
|
-
# bucket = storage.bucket "my-bucket"
|
154
|
-
# puts bucket.name
|
155
|
-
#
|
156
|
-
def bucket bucket_name
|
157
|
-
gapi = service.get_bucket bucket_name
|
158
|
-
Bucket.from_gapi gapi, service
|
159
|
-
rescue Gcloud::NotFoundError
|
160
|
-
nil
|
161
|
-
end
|
162
|
-
alias_method :find_bucket, :bucket
|
163
|
-
|
164
|
-
##
|
165
|
-
# Creates a new bucket with optional attributes. Also accepts a block for
|
166
|
-
# defining the CORS configuration for a static website served from the
|
167
|
-
# bucket. See {Bucket::Cors} for details.
|
168
|
-
#
|
169
|
-
# The API call to create the bucket may be retried under certain
|
170
|
-
# conditions. See {Gcloud#storage} to control this behavior.
|
171
|
-
#
|
172
|
-
# You can pass [website
|
173
|
-
# settings](https://cloud.google.com/storage/docs/website-configuration)
|
174
|
-
# for the bucket, including a block that defines CORS rule. See
|
175
|
-
# {Bucket::Cors} for details.
|
176
|
-
#
|
177
|
-
# @see https://cloud.google.com/storage/docs/cross-origin Cross-Origin
|
178
|
-
# Resource Sharing (CORS)
|
179
|
-
# @see https://cloud.google.com/storage/docs/website-configuration How to
|
180
|
-
# Host a Static Website
|
181
|
-
#
|
182
|
-
# @param [String] bucket_name Name of a bucket.
|
183
|
-
# @param [String] acl Apply a predefined set of access controls to this
|
184
|
-
# bucket.
|
185
|
-
#
|
186
|
-
# Acceptable values are:
|
187
|
-
#
|
188
|
-
# * `auth`, `auth_read`, `authenticated`, `authenticated_read`,
|
189
|
-
# `authenticatedRead` - Project team owners get OWNER access, and
|
190
|
-
# allAuthenticatedUsers get READER access.
|
191
|
-
# * `private` - Project team owners get OWNER access.
|
192
|
-
# * `project_private`, `projectPrivate` - Project team members get
|
193
|
-
# access according to their roles.
|
194
|
-
# * `public`, `public_read`, `publicRead` - Project team owners get
|
195
|
-
# OWNER access, and allUsers get READER access.
|
196
|
-
# * `public_write`, `publicReadWrite` - Project team owners get OWNER
|
197
|
-
# access, and allUsers get WRITER access.
|
198
|
-
# @param [String] default_acl Apply a predefined set of default object
|
199
|
-
# access controls to this bucket.
|
200
|
-
#
|
201
|
-
# Acceptable values are:
|
202
|
-
#
|
203
|
-
# * `auth`, `auth_read`, `authenticated`, `authenticated_read`,
|
204
|
-
# `authenticatedRead` - File owner gets OWNER access, and
|
205
|
-
# allAuthenticatedUsers get READER access.
|
206
|
-
# * `owner_full`, `bucketOwnerFullControl` - File owner gets OWNER
|
207
|
-
# access, and project team owners get OWNER access.
|
208
|
-
# * `owner_read`, `bucketOwnerRead` - File owner gets OWNER access, and
|
209
|
-
# project team owners get READER access.
|
210
|
-
# * `private` - File owner gets OWNER access.
|
211
|
-
# * `project_private`, `projectPrivate` - File owner gets OWNER access,
|
212
|
-
# and project team members get access according to their roles.
|
213
|
-
# * `public`, `public_read`, `publicRead` - File owner gets OWNER
|
214
|
-
# access, and allUsers get READER access.
|
215
|
-
# @param [String] location The location of the bucket. Object data for
|
216
|
-
# objects in the bucket resides in physical storage within this region.
|
217
|
-
# Possible values include `ASIA`, `EU`, and `US`. (See the [developer's
|
218
|
-
# guide](https://cloud.google.com/storage/docs/bucket-locations) for the
|
219
|
-
# authoritative list. The default value is `US`.
|
220
|
-
# @param [String] logging_bucket The destination bucket for the bucket's
|
221
|
-
# logs. For more information, see [Access
|
222
|
-
# Logs](https://cloud.google.com/storage/docs/access-logs).
|
223
|
-
# @param [String] logging_prefix The prefix used to create log object
|
224
|
-
# names for the bucket. It can be at most 900 characters and must be a
|
225
|
-
# [valid object
|
226
|
-
# name](https://cloud.google.com/storage/docs/bucket-naming#objectnames)
|
227
|
-
# . By default, the object prefix is the name of the bucket for which
|
228
|
-
# the logs are enabled. For more information, see [Access
|
229
|
-
# Logs](https://cloud.google.com/storage/docs/access-logs).
|
230
|
-
# @param [Symbol, String] storage_class Defines how objects in the bucket
|
231
|
-
# are stored and determines the SLA and the cost of storage. Values
|
232
|
-
# include `:standard`, `:nearline`, and `:dra` (Durable Reduced
|
233
|
-
# Availability), as well as the strings returned by
|
234
|
-
# Bucket#storage_class. For more information, see [Storage
|
235
|
-
# Classes](https://cloud.google.com/storage/docs/storage-classes). The
|
236
|
-
# default value is `:standard`.
|
237
|
-
# @param [Boolean] versioning Whether [Object
|
238
|
-
# Versioning](https://cloud.google.com/storage/docs/object-versioning)
|
239
|
-
# is to be enabled for the bucket. The default value is `false`.
|
240
|
-
# @param [String] website_main The index page returned from a static
|
241
|
-
# website served from the bucket when a site visitor requests the top
|
242
|
-
# level directory. For more information, see [How to Host a Static
|
243
|
-
# Website
|
244
|
-
# ](https://cloud.google.com/storage/docs/website-configuration#step4).
|
245
|
-
# @param [String] website_404 The page returned from a static website
|
246
|
-
# served from the bucket when a site visitor requests a resource that
|
247
|
-
# does not exist. For more information, see [How to Host a Static
|
248
|
-
# Website
|
249
|
-
# ](https://cloud.google.com/storage/docs/website-configuration#step4).
|
250
|
-
# @yield [bucket] a block for configuring the bucket before it is created
|
251
|
-
# @yieldparam [Bucket] cors the bucket object to be configured
|
252
|
-
#
|
253
|
-
# @return [Gcloud::Storage::Bucket]
|
254
|
-
#
|
255
|
-
# @example
|
256
|
-
# require "gcloud"
|
257
|
-
#
|
258
|
-
# gcloud = Gcloud.new
|
259
|
-
# storage = gcloud.storage
|
260
|
-
#
|
261
|
-
# bucket = storage.create_bucket "my-bucket"
|
262
|
-
#
|
263
|
-
# @example Configure the bucket in a block:
|
264
|
-
# require "gcloud"
|
265
|
-
#
|
266
|
-
# gcloud = Gcloud.new
|
267
|
-
# storage = gcloud.storage
|
268
|
-
#
|
269
|
-
# bucket = storage.create_bucket "my-bucket" do |b|
|
270
|
-
# b.website_main = "index.html"
|
271
|
-
# b.website_404 = "not_found.html"
|
272
|
-
# b.cors.add_rule ["http://example.org", "https://example.org"],
|
273
|
-
# "*",
|
274
|
-
# response_headers: ["X-My-Custom-Header"],
|
275
|
-
# max_age: 300
|
276
|
-
# end
|
277
|
-
#
|
278
|
-
def create_bucket bucket_name, acl: nil, default_acl: nil,
|
279
|
-
location: nil, storage_class: nil, logging_bucket: nil,
|
280
|
-
logging_prefix: nil, website_main: nil,
|
281
|
-
website_404: nil, versioning: nil
|
282
|
-
new_bucket = Google::Apis::StorageV1::Bucket.new({
|
283
|
-
name: bucket_name,
|
284
|
-
location: location,
|
285
|
-
storage_class: storage_class_for(storage_class)
|
286
|
-
}.delete_if { |_, v| v.nil? })
|
287
|
-
updater = Bucket::Updater.new(new_bucket).tap do |b|
|
288
|
-
b.logging_bucket = logging_bucket unless logging_bucket.nil?
|
289
|
-
b.logging_prefix = logging_prefix unless logging_prefix.nil?
|
290
|
-
b.website_main = website_main unless website_main.nil?
|
291
|
-
b.website_404 = website_404 unless website_404.nil?
|
292
|
-
b.versioning = versioning unless versioning.nil?
|
293
|
-
end
|
294
|
-
yield updater if block_given?
|
295
|
-
updater.check_for_mutable_cors!
|
296
|
-
gapi = service.insert_bucket \
|
297
|
-
new_bucket, acl: acl_rule(acl), default_acl: acl_rule(default_acl)
|
298
|
-
Bucket.from_gapi gapi, service
|
299
|
-
end
|
300
|
-
|
301
|
-
protected
|
302
|
-
|
303
|
-
def acl_rule option_name
|
304
|
-
Bucket::Acl.predefined_rule_for option_name
|
305
|
-
end
|
306
|
-
|
307
|
-
def storage_class_for str
|
308
|
-
{ "durable_reduced_availability" => "DURABLE_REDUCED_AVAILABILITY",
|
309
|
-
"dra" => "DURABLE_REDUCED_AVAILABILITY",
|
310
|
-
"durable" => "DURABLE_REDUCED_AVAILABILITY",
|
311
|
-
"nearline" => "NEARLINE",
|
312
|
-
"standard" => "STANDARD" }[str.to_s.downcase]
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
@@ -1,347 +0,0 @@
|
|
1
|
-
# Copyright 2014 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/apis/storage_v1"
|
19
|
-
require "digest"
|
20
|
-
require "mime/types"
|
21
|
-
require "pathname"
|
22
|
-
|
23
|
-
module Gcloud
|
24
|
-
module Storage
|
25
|
-
##
|
26
|
-
# @private Represents the connection to Storage,
|
27
|
-
# as well as expose the API calls.
|
28
|
-
class Service
|
29
|
-
##
|
30
|
-
# Alias to the Google Client API module
|
31
|
-
API = Google::Apis::StorageV1
|
32
|
-
|
33
|
-
# @private
|
34
|
-
attr_accessor :project
|
35
|
-
|
36
|
-
# @private
|
37
|
-
attr_accessor :credentials
|
38
|
-
|
39
|
-
##
|
40
|
-
# Creates a new Service instance.
|
41
|
-
def initialize project, credentials, retries: nil, timeout: nil
|
42
|
-
@project = project
|
43
|
-
@credentials = credentials
|
44
|
-
@credentials = credentials
|
45
|
-
@service = API::StorageService.new
|
46
|
-
@service.client_options.application_name = "gcloud-ruby"
|
47
|
-
@service.client_options.application_version = Gcloud::VERSION
|
48
|
-
@service.request_options.retries = retries || 3
|
49
|
-
@service.request_options.timeout_sec = timeout if timeout
|
50
|
-
@service.authorization = @credentials.client
|
51
|
-
end
|
52
|
-
|
53
|
-
def service
|
54
|
-
return mocked_service if mocked_service
|
55
|
-
@service
|
56
|
-
end
|
57
|
-
attr_accessor :mocked_service
|
58
|
-
|
59
|
-
##
|
60
|
-
# Retrieves a list of buckets for the given project.
|
61
|
-
def list_buckets prefix: nil, token: nil, max: nil
|
62
|
-
service.list_buckets @project, prefix: prefix, page_token: token,
|
63
|
-
max_results: max
|
64
|
-
rescue Google::Apis::Error => e
|
65
|
-
raise Gcloud::Error.from_error(e)
|
66
|
-
end
|
67
|
-
|
68
|
-
##
|
69
|
-
# Retrieves bucket by name.
|
70
|
-
# Returns Google::Apis::StorageV1::Bucket.
|
71
|
-
def get_bucket bucket_name
|
72
|
-
service.get_bucket bucket_name
|
73
|
-
rescue Google::Apis::Error => e
|
74
|
-
raise Gcloud::Error.from_error(e)
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
# Creates a new bucket.
|
79
|
-
# Returns Google::Apis::StorageV1::Bucket.
|
80
|
-
def insert_bucket bucket_gapi, options = {}
|
81
|
-
service.insert_bucket \
|
82
|
-
@project, bucket_gapi,
|
83
|
-
predefined_acl: options[:acl],
|
84
|
-
predefined_default_object_acl: options[:default_acl]
|
85
|
-
rescue Google::Apis::Error => e
|
86
|
-
raise Gcloud::Error.from_error(e)
|
87
|
-
end
|
88
|
-
|
89
|
-
##
|
90
|
-
# Updates a bucket, including its ACL metadata.
|
91
|
-
def patch_bucket bucket_name, bucket_gapi = nil, predefined_acl: nil,
|
92
|
-
predefined_default_acl: nil
|
93
|
-
bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
|
94
|
-
bucket_gapi.acl = nil if predefined_acl
|
95
|
-
bucket_gapi.default_object_acl = nil if predefined_default_acl
|
96
|
-
|
97
|
-
service.patch_bucket \
|
98
|
-
bucket_name, bucket_gapi,
|
99
|
-
predefined_acl: predefined_acl,
|
100
|
-
predefined_default_object_acl: predefined_default_acl
|
101
|
-
rescue Google::Apis::Error => e
|
102
|
-
raise Gcloud::Error.from_error(e)
|
103
|
-
end
|
104
|
-
|
105
|
-
##
|
106
|
-
# Permanently deletes an empty bucket.
|
107
|
-
def delete_bucket bucket_name
|
108
|
-
service.delete_bucket bucket_name
|
109
|
-
rescue Google::Apis::Error => e
|
110
|
-
raise Gcloud::Error.from_error(e)
|
111
|
-
end
|
112
|
-
|
113
|
-
##
|
114
|
-
# Retrieves a list of ACLs for the given bucket.
|
115
|
-
def list_bucket_acls bucket_name
|
116
|
-
service.list_bucket_access_controls bucket_name
|
117
|
-
rescue Google::Apis::Error => e
|
118
|
-
raise Gcloud::Error.from_error(e)
|
119
|
-
end
|
120
|
-
|
121
|
-
##
|
122
|
-
# Creates a new bucket ACL.
|
123
|
-
def insert_bucket_acl bucket_name, entity, role
|
124
|
-
new_acl = Google::Apis::StorageV1::BucketAccessControl.new \
|
125
|
-
entity: entity, role: role
|
126
|
-
service.insert_bucket_access_control bucket_name, new_acl
|
127
|
-
rescue Google::Apis::Error => e
|
128
|
-
raise Gcloud::Error.from_error(e)
|
129
|
-
end
|
130
|
-
|
131
|
-
##
|
132
|
-
# Permanently deletes a bucket ACL.
|
133
|
-
def delete_bucket_acl bucket_name, entity
|
134
|
-
service.delete_bucket_access_control bucket_name, entity
|
135
|
-
rescue Google::Apis::Error => e
|
136
|
-
raise Gcloud::Error.from_error(e)
|
137
|
-
end
|
138
|
-
|
139
|
-
##
|
140
|
-
# Retrieves a list of default ACLs for the given bucket.
|
141
|
-
def list_default_acls bucket_name
|
142
|
-
service.list_default_object_access_controls bucket_name
|
143
|
-
rescue Google::Apis::Error => e
|
144
|
-
raise Gcloud::Error.from_error(e)
|
145
|
-
end
|
146
|
-
|
147
|
-
##
|
148
|
-
# Creates a new default ACL.
|
149
|
-
def insert_default_acl bucket_name, entity, role
|
150
|
-
new_acl = Google::Apis::StorageV1::ObjectAccessControl.new \
|
151
|
-
entity: entity, role: role
|
152
|
-
service.insert_default_object_access_control bucket_name, new_acl
|
153
|
-
rescue Google::Apis::Error => e
|
154
|
-
raise Gcloud::Error.from_error(e)
|
155
|
-
end
|
156
|
-
|
157
|
-
##
|
158
|
-
# Permanently deletes a default ACL.
|
159
|
-
def delete_default_acl bucket_name, entity
|
160
|
-
service.delete_default_object_access_control bucket_name, entity
|
161
|
-
rescue Google::Apis::Error => e
|
162
|
-
raise Gcloud::Error.from_error(e)
|
163
|
-
end
|
164
|
-
|
165
|
-
##
|
166
|
-
# Retrieves a list of files matching the criteria.
|
167
|
-
def list_files bucket_name, options = {}
|
168
|
-
service.list_objects \
|
169
|
-
bucket_name, delimiter: options[:delimiter],
|
170
|
-
max_results: options[:max], page_token: options[:token],
|
171
|
-
prefix: options[:prefix], versions: options[:versions]
|
172
|
-
rescue Google::Apis::Error => e
|
173
|
-
raise Gcloud::Error.from_error(e)
|
174
|
-
end
|
175
|
-
|
176
|
-
##
|
177
|
-
# Inserts a new file for the given bucket
|
178
|
-
def insert_file bucket_name, source, path = nil, acl: nil,
|
179
|
-
cache_control: nil, content_disposition: nil,
|
180
|
-
content_encoding: nil, content_language: nil,
|
181
|
-
content_type: nil, crc32c: nil, md5: nil, metadata: nil,
|
182
|
-
key: nil, key_sha256: nil
|
183
|
-
file_obj = Google::Apis::StorageV1::Object.new \
|
184
|
-
cache_control: cache_control, content_type: content_type,
|
185
|
-
content_disposition: content_disposition, md5_hash: md5,
|
186
|
-
content_encoding: content_encoding, crc32c: crc32c,
|
187
|
-
content_language: content_language, metadata: metadata
|
188
|
-
content_type ||= mime_type_for(Pathname(source).to_path)
|
189
|
-
service.insert_object \
|
190
|
-
bucket_name, file_obj,
|
191
|
-
name: path, predefined_acl: acl, upload_source: source,
|
192
|
-
content_encoding: content_encoding, content_type: content_type,
|
193
|
-
options: key_options(key: key, key_sha256: key_sha256)
|
194
|
-
rescue Google::Apis::Error => e
|
195
|
-
raise Gcloud::Error.from_error(e)
|
196
|
-
end
|
197
|
-
|
198
|
-
##
|
199
|
-
# Retrieves an object or its metadata.
|
200
|
-
def get_file bucket_name, file_path, generation: nil, key: nil,
|
201
|
-
key_sha256: nil
|
202
|
-
service.get_object \
|
203
|
-
bucket_name, file_path,
|
204
|
-
generation: generation,
|
205
|
-
options: key_options(key: key, key_sha256: key_sha256)
|
206
|
-
rescue Google::Apis::Error => e
|
207
|
-
raise Gcloud::Error.from_error(e)
|
208
|
-
end
|
209
|
-
|
210
|
-
## Copy a file from source bucket/object to a
|
211
|
-
# destination bucket/object.
|
212
|
-
def copy_file source_bucket_name, source_file_path,
|
213
|
-
destination_bucket_name, destination_file_path, options = {}
|
214
|
-
service.copy_object \
|
215
|
-
source_bucket_name, source_file_path,
|
216
|
-
destination_bucket_name, destination_file_path,
|
217
|
-
destination_predefined_acl: options[:acl],
|
218
|
-
source_generation: options[:generation],
|
219
|
-
options: key_options(key: options[:key],
|
220
|
-
key_sha256: options[:key_sha256])
|
221
|
-
rescue Google::Apis::Error => e
|
222
|
-
raise Gcloud::Error.from_error(e)
|
223
|
-
end
|
224
|
-
|
225
|
-
##
|
226
|
-
# Download contents of a file.
|
227
|
-
def download_file bucket_name, file_path, target_path, generation: nil,
|
228
|
-
key: nil, key_sha256: nil
|
229
|
-
service.get_object \
|
230
|
-
bucket_name, file_path,
|
231
|
-
download_dest: target_path, generation: generation,
|
232
|
-
options: key_options(key: key, key_sha256: key_sha256)
|
233
|
-
rescue Google::Apis::Error => e
|
234
|
-
raise Gcloud::Error.from_error(e)
|
235
|
-
end
|
236
|
-
|
237
|
-
##
|
238
|
-
# Updates a file's metadata.
|
239
|
-
def patch_file bucket_name, file_path, file_gapi = nil,
|
240
|
-
predefined_acl: nil
|
241
|
-
file_gapi ||= Google::Apis::StorageV1::Object.new
|
242
|
-
service.patch_object \
|
243
|
-
bucket_name, file_path, file_gapi,
|
244
|
-
predefined_acl: predefined_acl
|
245
|
-
rescue Google::Apis::Error => e
|
246
|
-
raise Gcloud::Error.from_error(e)
|
247
|
-
end
|
248
|
-
|
249
|
-
##
|
250
|
-
# Permanently deletes a file.
|
251
|
-
def delete_file bucket_name, file_path
|
252
|
-
service.delete_object bucket_name, file_path
|
253
|
-
rescue Google::Apis::Error => e
|
254
|
-
raise Gcloud::Error.from_error(e)
|
255
|
-
end
|
256
|
-
|
257
|
-
##
|
258
|
-
# Retrieves a list of ACLs for the given file.
|
259
|
-
def list_file_acls bucket_name, file_name
|
260
|
-
service.list_object_access_controls bucket_name, file_name
|
261
|
-
rescue Google::Apis::Error => e
|
262
|
-
raise Gcloud::Error.from_error(e)
|
263
|
-
end
|
264
|
-
|
265
|
-
##
|
266
|
-
# Creates a new file ACL.
|
267
|
-
def insert_file_acl bucket_name, file_name, entity, role, options = {}
|
268
|
-
new_acl = Google::Apis::StorageV1::ObjectAccessControl.new \
|
269
|
-
entity: entity, role: role
|
270
|
-
service.insert_object_access_control \
|
271
|
-
bucket_name, file_name, new_acl, generation: options[:generation]
|
272
|
-
rescue Google::Apis::Error => e
|
273
|
-
raise Gcloud::Error.from_error(e)
|
274
|
-
end
|
275
|
-
|
276
|
-
##
|
277
|
-
# Permanently deletes a file ACL.
|
278
|
-
def delete_file_acl bucket_name, file_name, entity, options = {}
|
279
|
-
service.delete_object_access_control \
|
280
|
-
bucket_name, file_name, entity, generation: options[:generation]
|
281
|
-
rescue Google::Apis::Error => e
|
282
|
-
raise Gcloud::Error.from_error(e)
|
283
|
-
end
|
284
|
-
|
285
|
-
##
|
286
|
-
# Retrieves the mime-type for a file path.
|
287
|
-
# An empty string is returned if no mime-type can be found.
|
288
|
-
def mime_type_for path
|
289
|
-
MIME::Types.of(path).first.to_s
|
290
|
-
end
|
291
|
-
|
292
|
-
# @private
|
293
|
-
def inspect
|
294
|
-
"#{self.class}(#{@project})"
|
295
|
-
end
|
296
|
-
|
297
|
-
protected
|
298
|
-
|
299
|
-
def key_options key: nil, key_sha256: nil
|
300
|
-
options = {}
|
301
|
-
if key
|
302
|
-
headers = {}
|
303
|
-
headers["x-goog-encryption-algorithm"] = "AES256"
|
304
|
-
headers["x-goog-encryption-key"] = Base64.strict_encode64 key
|
305
|
-
key_sha256 ||= Digest::SHA256.digest key
|
306
|
-
headers["x-goog-encryption-key-sha256"] = \
|
307
|
-
Base64.strict_encode64 key_sha256
|
308
|
-
options[:header] = headers
|
309
|
-
end
|
310
|
-
options
|
311
|
-
end
|
312
|
-
|
313
|
-
def patch_bucket_request options = {}
|
314
|
-
{
|
315
|
-
"cors" => options[:cors],
|
316
|
-
"logging" => logging_config(options),
|
317
|
-
"versioning" => versioning_config(options[:versioning]),
|
318
|
-
"website" => website_config(options),
|
319
|
-
"acl" => options[:acl],
|
320
|
-
"defaultObjectAcl" => options[:default_acl]
|
321
|
-
}.delete_if { |_, v| v.nil? }
|
322
|
-
end
|
323
|
-
|
324
|
-
def versioning_config enabled
|
325
|
-
{ "enabled" => enabled } unless enabled.nil?
|
326
|
-
end
|
327
|
-
|
328
|
-
def logging_config options
|
329
|
-
bucket = options[:logging_bucket]
|
330
|
-
prefix = options[:logging_prefix]
|
331
|
-
{
|
332
|
-
log_bucket: bucket,
|
333
|
-
log_object_prefix: prefix
|
334
|
-
}.delete_if { |_, v| v.nil? } if bucket || prefix
|
335
|
-
end
|
336
|
-
|
337
|
-
def website_config options
|
338
|
-
website_main = options[:website_main]
|
339
|
-
website_404 = options[:website_404]
|
340
|
-
{
|
341
|
-
main_page_suffix: website_main,
|
342
|
-
not_found_page: website_404
|
343
|
-
}.delete_if { |_, v| v.nil? } if website_main || website_404
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
end
|