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,211 +0,0 @@
|
|
1
|
-
# Copyright 2016 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
|
-
require "google/apis/cloudresourcemanager_v1"
|
18
|
-
|
19
|
-
module Gcloud
|
20
|
-
module ResourceManager
|
21
|
-
##
|
22
|
-
# # Policy
|
23
|
-
#
|
24
|
-
# Represents a Cloud IAM Policy for the Resource Manager service.
|
25
|
-
#
|
26
|
-
# A common pattern for updating a resource's metadata, such as its Policy,
|
27
|
-
# is to read the current data from the service, update the data locally, and
|
28
|
-
# then send the modified data for writing. This pattern may result in a
|
29
|
-
# conflict if two or more processes attempt the sequence simultaneously. IAM
|
30
|
-
# solves this problem with the {Gcloud::ResourceManager::Policy#etag}
|
31
|
-
# property, which is used to verify whether the policy has changed since the
|
32
|
-
# last request. When you make a request to with an `etag` value, Cloud IAM
|
33
|
-
# compares the `etag` value in the request with the existing `etag` value
|
34
|
-
# associated with the policy. It writes the policy only if the `etag` values
|
35
|
-
# match.
|
36
|
-
#
|
37
|
-
# When you update a policy, first read the policy (and its current `etag`)
|
38
|
-
# from the service, then modify the policy locally, and then write the
|
39
|
-
# modified policy to the service. See
|
40
|
-
# {Gcloud::ResourceManager::Project#policy} and
|
41
|
-
# {Gcloud::ResourceManager::Project#policy=}.
|
42
|
-
#
|
43
|
-
# @see https://cloud.google.com/iam/docs/managing-policies Managing policies
|
44
|
-
# @see https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/setIamPolicy
|
45
|
-
# projects.setIamPolicy
|
46
|
-
#
|
47
|
-
# @attr [String] etag Used to verify whether the policy has changed since
|
48
|
-
# the last request. The policy will be written only if the `etag` values
|
49
|
-
# match.
|
50
|
-
# @attr [Hash{String => Array<String>}] roles The bindings that associate
|
51
|
-
# roles with an array of members. See [Understanding
|
52
|
-
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
53
|
-
# listing of primitive and curated roles.
|
54
|
-
# See [Binding](https://cloud.google.com/resource-manager/reference/rpc/google.iam.v1#binding)
|
55
|
-
# for a listing of values and patterns for members.
|
56
|
-
#
|
57
|
-
# @example
|
58
|
-
# require "gcloud"
|
59
|
-
#
|
60
|
-
# gcloud = Gcloud.new
|
61
|
-
# resource_manager = gcloud.resource_manager
|
62
|
-
# project = resource_manager.project "tokyo-rain-123"
|
63
|
-
#
|
64
|
-
# policy = project.policy # API call
|
65
|
-
#
|
66
|
-
# policy.remove "roles/owner", "user:owner@example.com" # Local call
|
67
|
-
# policy.add "roles/owner", "user:newowner@example.com" # Local call
|
68
|
-
# policy.roles["roles/viewer"] = ["allUsers"] # Local call
|
69
|
-
#
|
70
|
-
# project.policy = policy # API call
|
71
|
-
#
|
72
|
-
class Policy
|
73
|
-
##
|
74
|
-
# Alias to the Google Client API module
|
75
|
-
API = Google::Apis::CloudresourcemanagerV1
|
76
|
-
|
77
|
-
attr_reader :etag, :roles
|
78
|
-
|
79
|
-
##
|
80
|
-
# @private Creates a Policy object.
|
81
|
-
def initialize etag, roles
|
82
|
-
@etag = etag
|
83
|
-
@roles = roles
|
84
|
-
end
|
85
|
-
|
86
|
-
##
|
87
|
-
# Convenience method for adding a member to a binding on this policy.
|
88
|
-
# See [Understanding
|
89
|
-
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
90
|
-
# listing of primitive and curated roles.
|
91
|
-
# See [Binding](https://cloud.google.com/resource-manager/reference/rpc/google.iam.v1#binding)
|
92
|
-
# for a listing of values and patterns for members.
|
93
|
-
#
|
94
|
-
# @param [String] role_name A Cloud IAM role, such as `"roles/owner"`.
|
95
|
-
# @param [String] member A Cloud IAM identity, such as
|
96
|
-
# `"user:owner@example.com"`.
|
97
|
-
#
|
98
|
-
# @example
|
99
|
-
# require "gcloud"
|
100
|
-
#
|
101
|
-
# gcloud = Gcloud.new
|
102
|
-
# resource_manager = gcloud.resource_manager
|
103
|
-
# project = resource_manager.project "tokyo-rain-123"
|
104
|
-
#
|
105
|
-
# policy = project.policy # API call
|
106
|
-
#
|
107
|
-
# policy.add "roles/owner", "user:newowner@example.com" # Local call
|
108
|
-
#
|
109
|
-
# project.policy = policy # API call
|
110
|
-
#
|
111
|
-
def add role_name, member
|
112
|
-
role(role_name) << member
|
113
|
-
end
|
114
|
-
|
115
|
-
##
|
116
|
-
# Convenience method for removing a member from a binding on this policy.
|
117
|
-
# See [Understanding
|
118
|
-
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
119
|
-
# listing of primitive and curated roles.
|
120
|
-
# See [Binding](https://cloud.google.com/resource-manager/reference/rpc/google.iam.v1#binding)
|
121
|
-
# for a listing of values and patterns for members.
|
122
|
-
#
|
123
|
-
# @param [String] role_name A Cloud IAM role, such as `"roles/owner"`.
|
124
|
-
# @param [String] member A Cloud IAM identity, such as
|
125
|
-
# `"user:owner@example.com"`.
|
126
|
-
#
|
127
|
-
# @example
|
128
|
-
# require "gcloud"
|
129
|
-
#
|
130
|
-
# gcloud = Gcloud.new
|
131
|
-
# resource_manager = gcloud.resource_manager
|
132
|
-
# project = resource_manager.project "tokyo-rain-123"
|
133
|
-
#
|
134
|
-
# policy = project.policy # API call
|
135
|
-
#
|
136
|
-
# policy.remove "roles/owner", "user:owner@example.com" # Local call
|
137
|
-
#
|
138
|
-
# project.policy = policy # API call
|
139
|
-
#
|
140
|
-
def remove role_name, member
|
141
|
-
role(role_name).delete member
|
142
|
-
end
|
143
|
-
|
144
|
-
##
|
145
|
-
# Convenience method returning the array of members bound to a role in
|
146
|
-
# this policy, or an empty array if no value is present for the role in
|
147
|
-
# {#roles}. See [Understanding
|
148
|
-
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
149
|
-
# listing of primitive and curated roles. See
|
150
|
-
# [Binding](https://cloud.google.com/resource-manager/reference/rpc/google.iam.v1#binding)
|
151
|
-
# for a listing of values and patterns for members.
|
152
|
-
#
|
153
|
-
# @return [Array<String>] The members strings, or an empty array.
|
154
|
-
#
|
155
|
-
# @example
|
156
|
-
# require "gcloud"
|
157
|
-
#
|
158
|
-
# gcloud = Gcloud.new
|
159
|
-
# resource_manager = gcloud.resource_manager
|
160
|
-
# project = resource_manager.project "tokyo-rain-123"
|
161
|
-
#
|
162
|
-
# policy = project.policy
|
163
|
-
#
|
164
|
-
# policy.role("roles/viewer") << "user:viewer@example.com"
|
165
|
-
#
|
166
|
-
def role role_name
|
167
|
-
roles[role_name] ||= []
|
168
|
-
end
|
169
|
-
|
170
|
-
##
|
171
|
-
# Returns a deep copy of the policy.
|
172
|
-
#
|
173
|
-
# @return [Policy]
|
174
|
-
#
|
175
|
-
def deep_dup
|
176
|
-
dup.tap do |p|
|
177
|
-
roles_dup = p.roles.each_with_object({}) do |(k, v), memo|
|
178
|
-
memo[k] = v.dup rescue value
|
179
|
-
end
|
180
|
-
p.instance_variable_set "@roles", roles_dup
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
##
|
185
|
-
# @private Convert the Policy to a
|
186
|
-
# Google::Apis::CloudresourcemanagerV1::Policy.
|
187
|
-
def to_gapi
|
188
|
-
API::Policy.new(
|
189
|
-
etag: etag,
|
190
|
-
bindings: roles.keys.map do |role_name|
|
191
|
-
next if roles[role_name].empty?
|
192
|
-
API::Binding.new(
|
193
|
-
role: role_name,
|
194
|
-
members: roles[role_name]
|
195
|
-
)
|
196
|
-
end
|
197
|
-
)
|
198
|
-
end
|
199
|
-
|
200
|
-
##
|
201
|
-
# @private New Policy from a
|
202
|
-
# Google::Apis::CloudresourcemanagerV1::Policy object.
|
203
|
-
def self.from_gapi gapi
|
204
|
-
roles = gapi.bindings.each_with_object({}) do |binding, memo|
|
205
|
-
memo[binding.role] = binding.members.to_a
|
206
|
-
end
|
207
|
-
new gapi.etag, roles
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
@@ -1,484 +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 "time"
|
17
|
-
require "gcloud/resource_manager/project/list"
|
18
|
-
require "gcloud/resource_manager/project/updater"
|
19
|
-
require "gcloud/resource_manager/policy"
|
20
|
-
|
21
|
-
module Gcloud
|
22
|
-
module ResourceManager
|
23
|
-
##
|
24
|
-
# # Project
|
25
|
-
#
|
26
|
-
# Project is a high-level Google Cloud Platform entity. It is a container
|
27
|
-
# for ACLs, APIs, AppEngine Apps, VMs, and other Google Cloud Platform
|
28
|
-
# resources.
|
29
|
-
#
|
30
|
-
# @example
|
31
|
-
# require "gcloud"
|
32
|
-
#
|
33
|
-
# gcloud = Gcloud.new
|
34
|
-
# resource_manager = gcloud.resource_manager
|
35
|
-
# project = resource_manager.project "tokyo-rain-123"
|
36
|
-
# project.update do |p|
|
37
|
-
# p.name = "My Project"
|
38
|
-
# p.labels["env"] = "production"
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
class Project
|
42
|
-
##
|
43
|
-
# @private The Service object.
|
44
|
-
attr_accessor :service
|
45
|
-
|
46
|
-
##
|
47
|
-
# @private The Google API Client object.
|
48
|
-
attr_accessor :gapi
|
49
|
-
|
50
|
-
##
|
51
|
-
# @private Create an empty Project object.
|
52
|
-
def initialize
|
53
|
-
@service = nil
|
54
|
-
@gapi = Gcloud::ResourceManager::Service::API::Project.new
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
# The unique, user-assigned ID of the project. It must be 6 to 30
|
59
|
-
# lowercase letters, digits, or hyphens. It must start with a letter.
|
60
|
-
# Trailing hyphens are prohibited. e.g. tokyo-rain-123
|
61
|
-
#
|
62
|
-
def project_id
|
63
|
-
@gapi.project_id
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# The number uniquely identifying the project. e.g. 415104041262
|
68
|
-
#
|
69
|
-
def project_number
|
70
|
-
@gapi.project_number
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
# The user-assigned name of the project.
|
75
|
-
#
|
76
|
-
def name
|
77
|
-
@gapi.name
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Updates the user-assigned name of the project. This field is optional
|
82
|
-
# and can remain unset.
|
83
|
-
#
|
84
|
-
# Allowed characters are: lowercase and uppercase letters, numbers,
|
85
|
-
# hyphen, single-quote, double-quote, space, and exclamation point.
|
86
|
-
#
|
87
|
-
# @example
|
88
|
-
# require "gcloud"
|
89
|
-
#
|
90
|
-
# gcloud = Gcloud.new
|
91
|
-
# resource_manager = gcloud.resource_manager
|
92
|
-
# project = resource_manager.project "tokyo-rain-123"
|
93
|
-
# project.name = "My Project"
|
94
|
-
#
|
95
|
-
def name= new_name
|
96
|
-
ensure_service!
|
97
|
-
@gapi.name = new_name
|
98
|
-
@gapi = service.update_project @gapi
|
99
|
-
end
|
100
|
-
|
101
|
-
##
|
102
|
-
# The labels associated with this project.
|
103
|
-
#
|
104
|
-
# Label keys must be between 1 and 63 characters long and must conform to
|
105
|
-
# the regular expression <code>[a-z]([-a-z0-9]*[a-z0-9])?</code>.
|
106
|
-
#
|
107
|
-
# Label values must be between 0 and 63 characters long and must conform
|
108
|
-
# to the regular expression <code>([a-z]([-a-z0-9]*[a-z0-9])?)?</code>.
|
109
|
-
#
|
110
|
-
# No more than 256 labels can be associated with a given resource.
|
111
|
-
# (`Hash`)
|
112
|
-
#
|
113
|
-
# @yield [labels] a block for setting labels
|
114
|
-
# @yieldparam [Hash] labels the hash accepting labels
|
115
|
-
#
|
116
|
-
# @example Labels are read-only and cannot be changed:
|
117
|
-
# require "gcloud"
|
118
|
-
#
|
119
|
-
# gcloud = Gcloud.new
|
120
|
-
# resource_manager = gcloud.resource_manager
|
121
|
-
# project = resource_manager.project "tokyo-rain-123"
|
122
|
-
# project.labels["env"] #=> "dev" # read only
|
123
|
-
# project.labels["env"] = "production" # raises error
|
124
|
-
#
|
125
|
-
# @example Labels can be updated by passing a block, or with {#labels=}:
|
126
|
-
# require "gcloud"
|
127
|
-
#
|
128
|
-
# gcloud = Gcloud.new
|
129
|
-
# resource_manager = gcloud.resource_manager
|
130
|
-
# project = resource_manager.project "tokyo-rain-123"
|
131
|
-
# project.labels do |labels|
|
132
|
-
# labels["env"] = "production"
|
133
|
-
# end
|
134
|
-
#
|
135
|
-
def labels
|
136
|
-
labels = @gapi.labels.to_h
|
137
|
-
if block_given?
|
138
|
-
yielded_labels = labels.dup
|
139
|
-
yield yielded_labels
|
140
|
-
self.labels = yielded_labels if yielded_labels != labels # changed
|
141
|
-
else
|
142
|
-
labels.freeze
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
##
|
147
|
-
# Updates the labels associated with this project.
|
148
|
-
#
|
149
|
-
# Label keys must be between 1 and 63 characters long and must conform to
|
150
|
-
# the regular expression <code>[a-z]([-a-z0-9]*[a-z0-9])?</code>.
|
151
|
-
#
|
152
|
-
# Label values must be between 0 and 63 characters long and must conform
|
153
|
-
# to the regular expression <code>([a-z]([-a-z0-9]*[a-z0-9])?)?</code>.
|
154
|
-
#
|
155
|
-
# No more than 256 labels can be associated with a given resource.
|
156
|
-
# (`Hash`)
|
157
|
-
#
|
158
|
-
# @example
|
159
|
-
# require "gcloud"
|
160
|
-
#
|
161
|
-
# gcloud = Gcloud.new
|
162
|
-
# resource_manager = gcloud.resource_manager
|
163
|
-
# project = resource_manager.project "tokyo-rain-123"
|
164
|
-
# project.labels = { "env" => "production" }
|
165
|
-
#
|
166
|
-
def labels= new_labels
|
167
|
-
ensure_service!
|
168
|
-
@gapi.labels = new_labels
|
169
|
-
@gapi = service.update_project @gapi
|
170
|
-
end
|
171
|
-
|
172
|
-
##
|
173
|
-
# The time that this project was created.
|
174
|
-
#
|
175
|
-
def created_at
|
176
|
-
Time.parse @gapi.create_time
|
177
|
-
rescue
|
178
|
-
nil
|
179
|
-
end
|
180
|
-
|
181
|
-
##
|
182
|
-
# The project lifecycle state.
|
183
|
-
#
|
184
|
-
# Possible values are:
|
185
|
-
# * `ACTIVE` - The normal and active state.
|
186
|
-
# * `DELETE_REQUESTED` - The project has been marked for deletion by the
|
187
|
-
# user (by invoking ##delete) or by the system (Google Cloud
|
188
|
-
# Platform). This can generally be reversed by invoking {#undelete}.
|
189
|
-
# * `DELETE_IN_PROGRESS` - The process of deleting the project has begun.
|
190
|
-
# Reversing the deletion is no longer possible.
|
191
|
-
# * `LIFECYCLE_STATE_UNSPECIFIED` - Unspecified state. This is only
|
192
|
-
# used/useful for distinguishing unset values.
|
193
|
-
#
|
194
|
-
def state
|
195
|
-
@gapi.lifecycle_state
|
196
|
-
end
|
197
|
-
|
198
|
-
##
|
199
|
-
# Checks if the state is `ACTIVE`.
|
200
|
-
def active?
|
201
|
-
return false if state.nil?
|
202
|
-
"ACTIVE".casecmp(state).zero?
|
203
|
-
end
|
204
|
-
|
205
|
-
##
|
206
|
-
# Checks if the state is `LIFECYCLE_STATE_UNSPECIFIED`.
|
207
|
-
def unspecified?
|
208
|
-
return false if state.nil?
|
209
|
-
"LIFECYCLE_STATE_UNSPECIFIED".casecmp(state).zero?
|
210
|
-
end
|
211
|
-
|
212
|
-
##
|
213
|
-
# Checks if the state is `DELETE_REQUESTED`.
|
214
|
-
def delete_requested?
|
215
|
-
return false if state.nil?
|
216
|
-
"DELETE_REQUESTED".casecmp(state).zero?
|
217
|
-
end
|
218
|
-
|
219
|
-
##
|
220
|
-
# Checks if the state is `DELETE_IN_PROGRESS`.
|
221
|
-
def delete_in_progress?
|
222
|
-
return false if state.nil?
|
223
|
-
"DELETE_IN_PROGRESS".casecmp(state).zero?
|
224
|
-
end
|
225
|
-
|
226
|
-
##
|
227
|
-
# Updates the project in a single API call. See {Project::Updater}
|
228
|
-
#
|
229
|
-
# @yield [project] a block yielding a project delegate
|
230
|
-
# @yieldparam [Project::Updater] project the delegate object for updating
|
231
|
-
# the project
|
232
|
-
#
|
233
|
-
# @example
|
234
|
-
# require "gcloud"
|
235
|
-
#
|
236
|
-
# gcloud = Gcloud.new
|
237
|
-
# resource_manager = gcloud.resource_manager
|
238
|
-
# project = resource_manager.project "tokyo-rain-123"
|
239
|
-
# project.update do |p|
|
240
|
-
# p.name = "My Project"
|
241
|
-
# p.labels["env"] = "production"
|
242
|
-
# end
|
243
|
-
#
|
244
|
-
def update
|
245
|
-
updater = Updater.from_project self
|
246
|
-
yield updater
|
247
|
-
if updater.gapi.to_h != @gapi.to_h # changed
|
248
|
-
@gapi = service.update_project updater.gapi
|
249
|
-
end
|
250
|
-
self
|
251
|
-
end
|
252
|
-
|
253
|
-
##
|
254
|
-
# Reloads the project (with updated state) from the Google Cloud Resource
|
255
|
-
# Manager service.
|
256
|
-
#
|
257
|
-
# @example
|
258
|
-
# require "gcloud"
|
259
|
-
#
|
260
|
-
# gcloud = Gcloud.new
|
261
|
-
# resource_manager = gcloud.resource_manager
|
262
|
-
# project = resource_manager.project "tokyo-rain-123"
|
263
|
-
# project.reload!
|
264
|
-
#
|
265
|
-
def reload!
|
266
|
-
@gapi = service.get_project project_id
|
267
|
-
end
|
268
|
-
alias_method :refresh!, :reload!
|
269
|
-
|
270
|
-
##
|
271
|
-
# Marks the project for deletion. This method will only affect the project
|
272
|
-
# if the following criteria are met:
|
273
|
-
#
|
274
|
-
# * The project does not have a billing account associated with it.
|
275
|
-
# * The project has a lifecycle state of `ACTIVE`.
|
276
|
-
# * This method changes the project's lifecycle state from `ACTIVE` to
|
277
|
-
# `DELETE_REQUESTED`. The deletion starts at an unspecified time, at
|
278
|
-
# which point the lifecycle state changes to `DELETE_IN_PROGRESS`.
|
279
|
-
#
|
280
|
-
# Until the deletion completes, you can check the lifecycle state by
|
281
|
-
# calling #reload!, or by retrieving the project with Manager#project. The
|
282
|
-
# project remains visible to Manager#project and Manager#projects, but
|
283
|
-
# cannot be updated.
|
284
|
-
#
|
285
|
-
# After the deletion completes, the project is not retrievable by the
|
286
|
-
# Manager#project and Manager#projects methods.
|
287
|
-
#
|
288
|
-
# The caller must have modify permissions for this project.
|
289
|
-
#
|
290
|
-
# @example
|
291
|
-
# require "gcloud"
|
292
|
-
#
|
293
|
-
# gcloud = Gcloud.new
|
294
|
-
# resource_manager = gcloud.resource_manager
|
295
|
-
# project = resource_manager.project "tokyo-rain-123"
|
296
|
-
# project.active? #=> true
|
297
|
-
# project.delete
|
298
|
-
# project.active? #=> false
|
299
|
-
# project.delete_requested? #=> true
|
300
|
-
#
|
301
|
-
def delete
|
302
|
-
service.delete_project project_id
|
303
|
-
reload!
|
304
|
-
true
|
305
|
-
end
|
306
|
-
|
307
|
-
##
|
308
|
-
# Restores the project. You can only use this method for a project that
|
309
|
-
# has a lifecycle state of `DELETE_REQUESTED`. After deletion starts, as
|
310
|
-
# indicated by a lifecycle state of `DELETE_IN_PROGRESS`, the project
|
311
|
-
# cannot be restored.
|
312
|
-
#
|
313
|
-
# The caller must have modify permissions for this project.
|
314
|
-
#
|
315
|
-
# @example
|
316
|
-
# require "gcloud"
|
317
|
-
#
|
318
|
-
# gcloud = Gcloud.new
|
319
|
-
# resource_manager = gcloud.resource_manager
|
320
|
-
# project = resource_manager.project "tokyo-rain-123"
|
321
|
-
# project.delete_requested? #=> true
|
322
|
-
# project.undelete
|
323
|
-
# project.delete_requested? #=> false
|
324
|
-
# project.active? #=> true
|
325
|
-
#
|
326
|
-
def undelete
|
327
|
-
service.undelete_project project_id
|
328
|
-
reload!
|
329
|
-
true
|
330
|
-
end
|
331
|
-
|
332
|
-
##
|
333
|
-
# Gets and updates the [Cloud IAM](https://cloud.google.com/iam/) access
|
334
|
-
# control policy for this project.
|
335
|
-
#
|
336
|
-
# @see https://cloud.google.com/iam/docs/managing-policies Managing
|
337
|
-
# Policies
|
338
|
-
# @see https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/setIamPolicy
|
339
|
-
# projects.setIamPolicy
|
340
|
-
#
|
341
|
-
# @param [Boolean] force Force load the latest policy when `true`.
|
342
|
-
# Otherwise the policy will be memoized to reduce the number of API
|
343
|
-
# calls made. The default is `false`.
|
344
|
-
#
|
345
|
-
# @yield [policy] A block for updating the policy. The latest policy will
|
346
|
-
# be read from the service and passed to the block. After the block
|
347
|
-
# completes, the modified policy will be written to the service.
|
348
|
-
# @yieldparam [Policy] policy the current Cloud IAM Policy for this
|
349
|
-
# project
|
350
|
-
#
|
351
|
-
# @return [Policy] the current Cloud IAM Policy for this project
|
352
|
-
#
|
353
|
-
# @example Policy values are memoized to reduce the number of API calls:
|
354
|
-
# require "gcloud"
|
355
|
-
#
|
356
|
-
# gcloud = Gcloud.new
|
357
|
-
# resource_manager = gcloud.resource_manager
|
358
|
-
# project = resource_manager.project "tokyo-rain-123"
|
359
|
-
#
|
360
|
-
# policy = project.policy # API call
|
361
|
-
# policy_2 = project.policy # No API call
|
362
|
-
#
|
363
|
-
# @example Use `force` to retrieve the latest policy from the service:
|
364
|
-
# require "gcloud"
|
365
|
-
#
|
366
|
-
# gcloud = Gcloud.new
|
367
|
-
# resource_manager = gcloud.resource_manager
|
368
|
-
# project = resource_manager.project "tokyo-rain-123"
|
369
|
-
#
|
370
|
-
# policy = project.policy force: true # API call
|
371
|
-
# policy_2 = project.policy force: true # API call
|
372
|
-
#
|
373
|
-
# @example Update the policy by passing a block:
|
374
|
-
# require "gcloud"
|
375
|
-
#
|
376
|
-
# gcloud = Gcloud.new
|
377
|
-
# resource_manager = gcloud.resource_manager
|
378
|
-
# project = resource_manager.project "tokyo-rain-123"
|
379
|
-
#
|
380
|
-
# policy = project.policy do |p|
|
381
|
-
# p.add "roles/owner", "user:owner@example.com"
|
382
|
-
# end # 2 API calls
|
383
|
-
#
|
384
|
-
def policy force: false
|
385
|
-
@policy = nil if force || block_given?
|
386
|
-
@policy ||= begin
|
387
|
-
ensure_service!
|
388
|
-
gapi = service.get_policy project_id
|
389
|
-
Policy.from_gapi gapi
|
390
|
-
end
|
391
|
-
return @policy unless block_given?
|
392
|
-
p = @policy.deep_dup
|
393
|
-
yield p
|
394
|
-
self.policy = p
|
395
|
-
end
|
396
|
-
|
397
|
-
##
|
398
|
-
# Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
|
399
|
-
# policy for this project. The policy should be read from {#policy}.
|
400
|
-
# See {Gcloud::ResourceManager::Policy} for an explanation of the policy
|
401
|
-
# `etag` property and how to modify policies.
|
402
|
-
#
|
403
|
-
# You can also update the policy by passing a block to {#policy}, which
|
404
|
-
# will call this method internally after the block completes.
|
405
|
-
#
|
406
|
-
# @see https://cloud.google.com/iam/docs/managing-policies Managing
|
407
|
-
# Policies
|
408
|
-
# @see https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/setIamPolicy
|
409
|
-
# projects.setIamPolicy
|
410
|
-
#
|
411
|
-
# @param [Policy] new_policy a new or modified Cloud IAM Policy for this
|
412
|
-
# project
|
413
|
-
#
|
414
|
-
# @example
|
415
|
-
# require "gcloud"
|
416
|
-
#
|
417
|
-
# gcloud = Gcloud.new
|
418
|
-
# resource_manager = gcloud.resource_manager
|
419
|
-
# project = resource_manager.project "tokyo-rain-123"
|
420
|
-
#
|
421
|
-
# policy = project.policy # API call
|
422
|
-
#
|
423
|
-
# policy.add "roles/owner", "user:owner@example.com"
|
424
|
-
#
|
425
|
-
# project.policy = policy # API call
|
426
|
-
#
|
427
|
-
def policy= new_policy
|
428
|
-
ensure_service!
|
429
|
-
gapi = service.set_policy project_id, new_policy.to_gapi
|
430
|
-
# Convert symbols to strings for backwards compatibility.
|
431
|
-
# This will go away when we add a ResourceManager::Policy class.
|
432
|
-
@policy = Policy.from_gapi gapi
|
433
|
-
end
|
434
|
-
|
435
|
-
##
|
436
|
-
# Tests the specified permissions against the [Cloud
|
437
|
-
# IAM](https://cloud.google.com/iam/) access control policy.
|
438
|
-
#
|
439
|
-
# @see https://cloud.google.com/iam/docs/managing-policies Managing
|
440
|
-
# Policies
|
441
|
-
#
|
442
|
-
# @param [String, Array<String>] permissions The set of permissions to
|
443
|
-
# check access for. Permissions with wildcards (such as `*` or
|
444
|
-
# `storage.*`) are not allowed.
|
445
|
-
#
|
446
|
-
# @return [Array<String>] The permissions that have access
|
447
|
-
#
|
448
|
-
# @example
|
449
|
-
# require "gcloud"
|
450
|
-
#
|
451
|
-
# gcloud = Gcloud.new
|
452
|
-
# resource_manager = gcloud.resource_manager
|
453
|
-
# project = resource_manager.project "tokyo-rain-123"
|
454
|
-
# perms = project.test_permissions "resourcemanager.projects.get",
|
455
|
-
# "resourcemanager.projects.delete"
|
456
|
-
# perms.include? "resourcemanager.projects.get" #=> true
|
457
|
-
# perms.include? "resourcemanager.projects.delete" #=> false
|
458
|
-
#
|
459
|
-
def test_permissions *permissions
|
460
|
-
permissions = Array(permissions).flatten
|
461
|
-
ensure_service!
|
462
|
-
gapi = service.test_permissions project_id, permissions
|
463
|
-
gapi.permissions
|
464
|
-
end
|
465
|
-
|
466
|
-
##
|
467
|
-
# @private New Change from a Google API Client object.
|
468
|
-
def self.from_gapi gapi, service
|
469
|
-
new.tap do |p|
|
470
|
-
p.gapi = gapi
|
471
|
-
p.service = service
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
protected
|
476
|
-
|
477
|
-
##
|
478
|
-
# Raise an error unless an active service is available.
|
479
|
-
def ensure_service!
|
480
|
-
fail "Must have active connection" unless service
|
481
|
-
end
|
482
|
-
end
|
483
|
-
end
|
484
|
-
end
|