google-cloud-resource_manager 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/google-cloud-resource_manager.rb +116 -0
- data/lib/google/cloud/resource_manager.rb +248 -0
- data/lib/google/cloud/resource_manager/credentials.rb +32 -0
- data/lib/google/cloud/resource_manager/manager.rb +270 -0
- data/lib/google/cloud/resource_manager/policy.rb +214 -0
- data/lib/google/cloud/resource_manager/project.rb +486 -0
- data/lib/google/cloud/resource_manager/project/list.rb +169 -0
- data/lib/google/cloud/resource_manager/project/updater.rb +134 -0
- data/lib/google/cloud/resource_manager/service.rb +132 -0
- data/lib/google/cloud/resource_manager/version.rb +22 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d88720fc4e202a484570afebd31023cea2ceaa7f
|
4
|
+
data.tar.gz: 15661f51dc41db2875032122a1ac2c238ed516f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 206e8448c64c92417d740ac2d94096bbb95320f5539ee56f31198581a25525d057e0f2b70f920e3a1cd6510972a7f25bb4297de9ebe98aad697321570f31e470
|
7
|
+
data.tar.gz: ee8b81ba5e1ab811831391fa48627ed85fec3717d22fa9009a15628617e762eaa7f37351982fb5a36f4ba05163e525b6d7b74dae3cfc4a6e41d7382127b832c4
|
@@ -0,0 +1,116 @@
|
|
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
|
+
# This file is here to be autorequired by bundler, so that the .bigquery and
|
17
|
+
# #bigquery methods can be available, but the library and all dependencies won't
|
18
|
+
# be loaded until required and used.
|
19
|
+
|
20
|
+
|
21
|
+
gem "google-cloud-core"
|
22
|
+
require "google/cloud"
|
23
|
+
|
24
|
+
module Google
|
25
|
+
module Cloud
|
26
|
+
##
|
27
|
+
# Creates a new object for connecting to the Resource Manager service.
|
28
|
+
# Each call creates a new connection.
|
29
|
+
#
|
30
|
+
# For more information on connecting to Google Cloud see the [Authentication
|
31
|
+
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
32
|
+
#
|
33
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
34
|
+
# set of resources and operations that the connection can access. See
|
35
|
+
# [Using OAuth 2.0 to Access Google
|
36
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
37
|
+
#
|
38
|
+
# The default scope is:
|
39
|
+
#
|
40
|
+
# * `https://www.googleapis.com/auth/cloud-platform`
|
41
|
+
# @param [Integer] retries Number of times to retry requests on server
|
42
|
+
# error. The default value is `3`. Optional.
|
43
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
44
|
+
#
|
45
|
+
# @return [Google::Cloud::ResourceManager::Manager]
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# require "google/cloud"
|
49
|
+
#
|
50
|
+
# gcloud = Google::Cloud.new
|
51
|
+
# resource_manager = gcloud.resource_manager
|
52
|
+
# resource_manager.projects.each do |project|
|
53
|
+
# puts projects.project_id
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# @example The default scope can be overridden with the `scope` option:
|
57
|
+
# require "google/cloud"
|
58
|
+
#
|
59
|
+
# gcloud = Google::Cloud.new
|
60
|
+
# readonly_scope = \
|
61
|
+
# "https://www.googleapis.com/auth/cloudresourcemanager.readonly"
|
62
|
+
# resource_manager = gcloud.resource_manager scope: readonly_scope
|
63
|
+
#
|
64
|
+
def resource_manager scope: nil, retries: nil, timeout: nil
|
65
|
+
Google::Cloud.resource_manager @keyfile, scope: scope,
|
66
|
+
retries: (retries || @retries),
|
67
|
+
timeout: (timeout || @timeout)
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Creates a new `Project` instance connected to the Resource Manager
|
72
|
+
# service. Each call creates a new connection.
|
73
|
+
#
|
74
|
+
# For more information on connecting to Google Cloud see the [Authentication
|
75
|
+
# Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
|
76
|
+
#
|
77
|
+
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
|
78
|
+
# file path the file must be readable.
|
79
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
80
|
+
# set of resources and operations that the connection can access. See
|
81
|
+
# [Using OAuth 2.0 to Access Google
|
82
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
83
|
+
#
|
84
|
+
# The default scope is:
|
85
|
+
#
|
86
|
+
# * `https://www.googleapis.com/auth/cloud-platform`
|
87
|
+
# @param [Integer] retries Number of times to retry requests on server
|
88
|
+
# error. The default value is `3`. Optional.
|
89
|
+
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
90
|
+
#
|
91
|
+
# @return [Google::Cloud::ResourceManager::Manager]
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# require "google/cloud/resource_manager"
|
95
|
+
#
|
96
|
+
# resource_manager = Google::Cloud.resource_manager
|
97
|
+
# resource_manager.projects.each do |project|
|
98
|
+
# puts projects.project_id
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
def self.resource_manager keyfile = nil, scope: nil, retries: nil,
|
102
|
+
timeout: nil
|
103
|
+
require "google/cloud/resource_manager"
|
104
|
+
if keyfile.nil?
|
105
|
+
credentials = Google::Cloud::ResourceManager::Credentials.default(
|
106
|
+
scope: scope)
|
107
|
+
else
|
108
|
+
credentials = Google::Cloud::ResourceManager::Credentials.new(
|
109
|
+
keyfile, scope: scope)
|
110
|
+
end
|
111
|
+
Google::Cloud::ResourceManager::Manager.new(
|
112
|
+
Google::Cloud::ResourceManager::Service.new(
|
113
|
+
credentials, retries: retries, timeout: timeout))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,248 @@
|
|
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 "google-cloud-resource_manager"
|
17
|
+
require "google/cloud/resource_manager/manager"
|
18
|
+
|
19
|
+
module Google
|
20
|
+
module Cloud
|
21
|
+
##
|
22
|
+
# # Google Cloud Resource Manager
|
23
|
+
#
|
24
|
+
# The Resource Manager API provides methods that you can use to
|
25
|
+
# programmatically manage your projects in the Google Cloud Platform. You
|
26
|
+
# may be familiar with managing projects in the [Developers
|
27
|
+
# Console](https://developers.google.com/console/help/new/). With this API
|
28
|
+
# you can do the following:
|
29
|
+
#
|
30
|
+
# * Get a list of all projects associated with an account
|
31
|
+
# * Create new projects
|
32
|
+
# * Update existing projects
|
33
|
+
# * Delete projects
|
34
|
+
# * Undelete, or recover, projects that you don't want to delete
|
35
|
+
#
|
36
|
+
# The Resource Manager API is a Beta release and is not covered by any SLA
|
37
|
+
# or deprecation policy and may be subject to backward-incompatible changes.
|
38
|
+
#
|
39
|
+
# ## Accessing the Service
|
40
|
+
#
|
41
|
+
# Currently, the full functionality of the Resource Manager API is available
|
42
|
+
# only to whitelisted users. (Contact your account manager or a member of
|
43
|
+
# the Google Cloud sales team if you are interested in access.) Read-only
|
44
|
+
# methods such as {ResourceManager::Manager#projects} and
|
45
|
+
# {ResourceManager::Manager#project} are accessible to any user who enables
|
46
|
+
# the Resource Manager API in the [Developers
|
47
|
+
# Console](https://console.developers.google.com).
|
48
|
+
#
|
49
|
+
# ## Authentication
|
50
|
+
#
|
51
|
+
# The Resource Manager API currently requires authentication of a [User
|
52
|
+
# Account](https://developers.google.com/identity/protocols/OAuth2), and
|
53
|
+
# cannot currently be accessed with a [Service
|
54
|
+
# Account](https://developers.google.com/identity/protocols/OAuth2ServiceAccount).
|
55
|
+
# To use a User Account install the [Google Cloud
|
56
|
+
# SDK](http://cloud.google.com/sdk) and authenticate with the following:
|
57
|
+
#
|
58
|
+
# ```
|
59
|
+
# $ gcloud auth login
|
60
|
+
# ```
|
61
|
+
#
|
62
|
+
# Also make sure all `GCLOUD` environment variables are cleared of any
|
63
|
+
# service accounts. Then google-cloud will be able to detect the user
|
64
|
+
# authentication and connect with those credentials.
|
65
|
+
#
|
66
|
+
# ```ruby
|
67
|
+
# require "google/cloud"
|
68
|
+
#
|
69
|
+
# gcloud = Google::Cloud.new
|
70
|
+
# resource_manager = gcloud.resource_manager
|
71
|
+
# ```
|
72
|
+
#
|
73
|
+
# ## Listing Projects
|
74
|
+
#
|
75
|
+
# Project is a collection of settings, credentials, and metadata about the
|
76
|
+
# application or applications you're working on. You can retrieve and
|
77
|
+
# inspect all projects that you have permissions to. (See
|
78
|
+
# {Google::Cloud::ResourceManager::Manager#projects})
|
79
|
+
#
|
80
|
+
# ```ruby
|
81
|
+
# require "google/cloud"
|
82
|
+
#
|
83
|
+
# gcloud = Google::Cloud.new
|
84
|
+
# resource_manager = gcloud.resource_manager
|
85
|
+
# resource_manager.projects.each do |project|
|
86
|
+
# puts projects.project_id
|
87
|
+
# end
|
88
|
+
# ```
|
89
|
+
#
|
90
|
+
# ## Managing Projects with Labels
|
91
|
+
#
|
92
|
+
# Labels can be added to or removed from projects. (See
|
93
|
+
# {Google::Cloud::ResourceManager::Project#labels})
|
94
|
+
#
|
95
|
+
# ```ruby
|
96
|
+
# require "google/cloud"
|
97
|
+
#
|
98
|
+
# gcloud = Google::Cloud.new
|
99
|
+
# resource_manager = gcloud.resource_manager
|
100
|
+
# project = resource_manager.project "tokyo-rain-123"
|
101
|
+
# # Label the project as production
|
102
|
+
# project.update do |p|
|
103
|
+
# p.labels["env"] = "production"
|
104
|
+
# end
|
105
|
+
# ```
|
106
|
+
#
|
107
|
+
# Projects can then be filtered by labels. (See
|
108
|
+
# {Google::Cloud::ResourceManager::Manager#projects})
|
109
|
+
#
|
110
|
+
# ```ruby
|
111
|
+
# require "google/cloud"
|
112
|
+
#
|
113
|
+
# gcloud = Google::Cloud.new
|
114
|
+
# resource_manager = gcloud.resource_manager
|
115
|
+
# # Find only the productions projects
|
116
|
+
# projects = resource_manager.projects filter: "labels.env:production"
|
117
|
+
# projects.each do |project|
|
118
|
+
# puts project.project_id
|
119
|
+
# end
|
120
|
+
# ```
|
121
|
+
#
|
122
|
+
# ## Creating a Project
|
123
|
+
#
|
124
|
+
# You can also use the API to create new projects. (See
|
125
|
+
# {Google::Cloud::ResourceManager::Manager#create_project})
|
126
|
+
#
|
127
|
+
# ```ruby
|
128
|
+
# require "google/cloud"
|
129
|
+
#
|
130
|
+
# gcloud = Google::Cloud.new
|
131
|
+
# resource_manager = gcloud.resource_manager
|
132
|
+
# project = resource_manager.create_project "tokyo-rain-123",
|
133
|
+
# name: "Todos Development",
|
134
|
+
# labels: {env: :development}
|
135
|
+
# ```
|
136
|
+
#
|
137
|
+
# ## Deleting a Project
|
138
|
+
#
|
139
|
+
# You can delete projects when they are no longer needed. (See
|
140
|
+
# {Google::Cloud::ResourceManager::Manager#delete} and
|
141
|
+
# {Google::Cloud::ResourceManager::Project#delete})
|
142
|
+
#
|
143
|
+
# ```ruby
|
144
|
+
# require "google/cloud"
|
145
|
+
#
|
146
|
+
# gcloud = Google::Cloud.new
|
147
|
+
# resource_manager = gcloud.resource_manager
|
148
|
+
# resource_manager.delete "tokyo-rain-123"
|
149
|
+
# ```
|
150
|
+
#
|
151
|
+
# ## Undeleting a Project
|
152
|
+
#
|
153
|
+
# You can also restore a deleted project within the waiting period that
|
154
|
+
# starts when the project was deleted. Restoring a project returns it to the
|
155
|
+
# state it was in prior to being deleted. (See
|
156
|
+
# {Google::Cloud::ResourceManager::Manager#undelete} and
|
157
|
+
# {Google::Cloud::ResourceManager::Project#undelete})
|
158
|
+
#
|
159
|
+
# ```ruby
|
160
|
+
# require "google/cloud"
|
161
|
+
#
|
162
|
+
# gcloud = Google::Cloud.new
|
163
|
+
# resource_manager = gcloud.resource_manager
|
164
|
+
# resource_manager.undelete "tokyo-rain-123"
|
165
|
+
# ```
|
166
|
+
#
|
167
|
+
# ## Configuring retries and timeout
|
168
|
+
#
|
169
|
+
# You can configure how many times API requests may be automatically
|
170
|
+
# retried. When an API request fails, the response will be inspected to see
|
171
|
+
# if the request meets criteria indicating that it may succeed on retry,
|
172
|
+
# such as `500` and `503` status codes or a specific internal error code
|
173
|
+
# such as `rateLimitExceeded`. If it meets the criteria, the request will be
|
174
|
+
# retried after a delay. If another error occurs, the delay will be
|
175
|
+
# increased before a subsequent attempt, until the `retries` limit is
|
176
|
+
# reached.
|
177
|
+
#
|
178
|
+
# You can also set the request `timeout` value in seconds.
|
179
|
+
#
|
180
|
+
# ```ruby
|
181
|
+
# require "google/cloud"
|
182
|
+
#
|
183
|
+
# gcloud = Google::Cloud.new
|
184
|
+
# resource_manager = gcloud.resource_manager retries: 10, timeout: 120
|
185
|
+
# ```
|
186
|
+
#
|
187
|
+
# See the [Resource Manager error
|
188
|
+
# messages](https://cloud.google.com/resource-manager/docs/core_errors)
|
189
|
+
# for a list of error conditions.
|
190
|
+
#
|
191
|
+
# ## Managing IAM Policies
|
192
|
+
#
|
193
|
+
# Google Cloud Identity and Access Management ([Cloud
|
194
|
+
# IAM](https://cloud.google.com/iam/)) access control policies can be
|
195
|
+
# managed on projects. These policies allow project owners to manage _who_
|
196
|
+
# (identity) has access to _what_ (role). See [Cloud IAM
|
197
|
+
# Overview](https://cloud.google.com/iam/docs/overview) for more
|
198
|
+
# information.
|
199
|
+
#
|
200
|
+
# A project's access control policy can be retrieved. (See
|
201
|
+
# {Google::Cloud::ResourceManager::Project#policy} and
|
202
|
+
# {Google::Cloud::ResourceManager::Policy}.)
|
203
|
+
#
|
204
|
+
# ```ruby
|
205
|
+
# require "google/cloud"
|
206
|
+
#
|
207
|
+
# gcloud = Google::Cloud.new
|
208
|
+
# resource_manager = gcloud.resource_manager
|
209
|
+
# project = resource_manager.project "tokyo-rain-123"
|
210
|
+
# policy = project.policy
|
211
|
+
# ```
|
212
|
+
#
|
213
|
+
# A project's access control policy can also be updated:
|
214
|
+
#
|
215
|
+
# ```ruby
|
216
|
+
# require "google/cloud"
|
217
|
+
#
|
218
|
+
# gcloud = Google::Cloud.new
|
219
|
+
# resource_manager = gcloud.resource_manager
|
220
|
+
# project = resource_manager.project "tokyo-rain-123"
|
221
|
+
#
|
222
|
+
# policy = project.policy do |p|
|
223
|
+
# p.add "roles/viewer", "serviceAccount:your-service-account"
|
224
|
+
# end
|
225
|
+
# ```
|
226
|
+
#
|
227
|
+
# And permissions can be tested on a project. (See
|
228
|
+
# {Google::Cloud::ResourceManager::Project#test_permissions})
|
229
|
+
#
|
230
|
+
# ```ruby
|
231
|
+
# require "google/cloud"
|
232
|
+
#
|
233
|
+
# gcloud = Google::Cloud.new
|
234
|
+
# resource_manager = gcloud.resource_manager
|
235
|
+
# project = resource_manager.project "tokyo-rain-123"
|
236
|
+
# perms = project.test_permissions "resourcemanager.projects.get",
|
237
|
+
# "resourcemanager.projects.delete"
|
238
|
+
# perms.include? "resourcemanager.projects.get" #=> true
|
239
|
+
# perms.include? "resourcemanager.projects.delete" #=> false
|
240
|
+
# ```
|
241
|
+
#
|
242
|
+
# For more information about using access control policies see [Managing
|
243
|
+
# Policies](https://cloud.google.com/iam/docs/managing-policies).
|
244
|
+
#
|
245
|
+
module ResourceManager
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 "google/cloud/credentials"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module ResourceManager
|
21
|
+
##
|
22
|
+
# @private Represents the Oauth2 signing logic for Resource Manager.
|
23
|
+
class Credentials < Google::Cloud::Credentials
|
24
|
+
SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
|
25
|
+
PATH_ENV_VARS = %w(RESOURCE_MANAGER_KEYFILE
|
26
|
+
GOOGLE_CLOUD_KEYFILE GCLOUD_KEYFILE)
|
27
|
+
JSON_ENV_VARS = %w(RESOURCE_MANAGER_KEYFILE_JSON
|
28
|
+
GOOGLE_CLOUD_KEYFILE_JSON GCLOUD_KEYFILE_JSON)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,270 @@
|
|
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 "google/cloud/errors"
|
17
|
+
require "google/cloud/resource_manager/credentials"
|
18
|
+
require "google/cloud/resource_manager/service"
|
19
|
+
require "google/cloud/resource_manager/project"
|
20
|
+
|
21
|
+
module Google
|
22
|
+
module Cloud
|
23
|
+
module ResourceManager
|
24
|
+
##
|
25
|
+
# # Manager
|
26
|
+
#
|
27
|
+
# Provides methods for creating, retrieving, and updating projects.
|
28
|
+
#
|
29
|
+
# @example
|
30
|
+
# require "google/cloud"
|
31
|
+
#
|
32
|
+
# gcloud = Google::Cloud.new
|
33
|
+
# resource_manager = gcloud.resource_manager
|
34
|
+
# resource_manager.projects.each do |project|
|
35
|
+
# puts projects.project_id
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# See {Google::Cloud#resource_manager}
|
39
|
+
class Manager
|
40
|
+
##
|
41
|
+
# @private The Service object.
|
42
|
+
attr_accessor :service
|
43
|
+
|
44
|
+
##
|
45
|
+
# @private Creates a new Service instance.
|
46
|
+
#
|
47
|
+
# See {Google::Cloud.resource_manager}
|
48
|
+
def initialize service
|
49
|
+
@service = service
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Retrieves the projects that are visible to the user and satisfy the
|
54
|
+
# specified filter. This method returns projects in an unspecified
|
55
|
+
# order. New projects do not necessarily appear at the end of the list.
|
56
|
+
#
|
57
|
+
# @param [String] filter An expression for filtering the results of the
|
58
|
+
# request. Filter rules are case insensitive.
|
59
|
+
#
|
60
|
+
# The fields eligible for filtering are:
|
61
|
+
#
|
62
|
+
# * `name`
|
63
|
+
# * `id`
|
64
|
+
# * `labels.key` - where `key` is the name of a label
|
65
|
+
#
|
66
|
+
# Some examples of using labels as filters:
|
67
|
+
#
|
68
|
+
# * `name:*` - The project has a name.
|
69
|
+
# * `name:Howl` - The project's name is Howl or howl.
|
70
|
+
# * `name:HOWL` - Equivalent to above.
|
71
|
+
# * `NAME:howl` - Equivalent to above.
|
72
|
+
# * `labels.color:*` - The project has the label color.
|
73
|
+
# * `labels.color:red` - The project's label color has the value red.
|
74
|
+
# * <code>labels.color:red labels.size:big</code> - The project's
|
75
|
+
# label color has the value red and its label size has the value
|
76
|
+
# big.
|
77
|
+
# @param [String] token A previously-returned page token representing
|
78
|
+
# part of the larger set of results to view.
|
79
|
+
# @param [Integer] max Maximum number of projects to return.
|
80
|
+
#
|
81
|
+
# @return [Array<Google::Cloud::ResourceManager::Project>] (See
|
82
|
+
# {Google::Cloud::ResourceManager::Project::List})
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# require "google/cloud"
|
86
|
+
#
|
87
|
+
# gcloud = Google::Cloud.new
|
88
|
+
# resource_manager = gcloud.resource_manager
|
89
|
+
# projects = resource_manager.projects
|
90
|
+
#
|
91
|
+
# projects.each do |project|
|
92
|
+
# puts project.project_id
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# @example Projects can be filtered using the `filter` option:
|
96
|
+
# require "google/cloud"
|
97
|
+
#
|
98
|
+
# gcloud = Google::Cloud.new
|
99
|
+
# resource_manager = gcloud.resource_manager
|
100
|
+
# projects = resource_manager.projects filter: "labels.env:production"
|
101
|
+
#
|
102
|
+
# projects.each do |project|
|
103
|
+
# puts project.project_id
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
# @example Retrieve all projects: (See {Project::List#all})
|
107
|
+
# require "google/cloud"
|
108
|
+
#
|
109
|
+
# gcloud = Google::Cloud.new
|
110
|
+
# resource_manager = gcloud.resource_manager
|
111
|
+
# projects = resource_manager.projects
|
112
|
+
#
|
113
|
+
# projects.all do |project|
|
114
|
+
# puts project.project_id
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
def projects filter: nil, token: nil, max: nil
|
118
|
+
gapi = service.list_project filter: filter, token: token, max: max
|
119
|
+
Project::List.from_gapi gapi, self, filter, max
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Retrieves the project identified by the specified `project_id`.
|
124
|
+
#
|
125
|
+
# @param [String] project_id The ID of the project.
|
126
|
+
#
|
127
|
+
# @return [Google::Cloud::ResourceManager::Project, nil] Returns `nil`
|
128
|
+
# if the project does not exist
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# require "google/cloud"
|
132
|
+
#
|
133
|
+
# gcloud = Google::Cloud.new
|
134
|
+
# resource_manager = gcloud.resource_manager
|
135
|
+
# project = resource_manager.project "tokyo-rain-123"
|
136
|
+
# project.project_id #=> "tokyo-rain-123"
|
137
|
+
#
|
138
|
+
def project project_id
|
139
|
+
gapi = service.get_project project_id
|
140
|
+
Project.from_gapi gapi, service
|
141
|
+
rescue NotFoundError
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
# Creates a project resource.
|
147
|
+
#
|
148
|
+
# Initially, the project resource is owned by its creator exclusively.
|
149
|
+
# The creator can later grant permission to others to read or update the
|
150
|
+
# project.
|
151
|
+
#
|
152
|
+
# Several APIs are activated automatically for the project, including
|
153
|
+
# Google Cloud Storage.
|
154
|
+
#
|
155
|
+
# @param [String] project_id The unique, user-assigned ID of the
|
156
|
+
# project. It must be 6 to 30 lowercase letters, digits, or hyphens.
|
157
|
+
# It must start with a letter. Trailing hyphens are prohibited.
|
158
|
+
# @param [String] name The user-assigned name of the project. This field
|
159
|
+
# is optional and can remain unset.
|
160
|
+
#
|
161
|
+
# Allowed characters are: lowercase and uppercase letters, numbers,
|
162
|
+
# hyphen, single-quote, double-quote, space, and exclamation point.
|
163
|
+
# @param [Hash] labels The labels associated with this project.
|
164
|
+
#
|
165
|
+
# Label keys must be between 1 and 63 characters long and must conform
|
166
|
+
# to the following regular expression:
|
167
|
+
# <code>[a-z]([-a-z0-9]*[a-z0-9])?</code>.
|
168
|
+
#
|
169
|
+
# Label values must be between 0 and 63 characters long and must
|
170
|
+
# conform to the regular expression
|
171
|
+
# <code>([a-z]([-a-z0-9]*[a-z0-9])?)?</code>.
|
172
|
+
#
|
173
|
+
# No more than 256 labels can be associated with a given resource.
|
174
|
+
#
|
175
|
+
# @return [Google::Cloud::ResourceManager::Project]
|
176
|
+
#
|
177
|
+
# @example
|
178
|
+
# require "google/cloud"
|
179
|
+
#
|
180
|
+
# gcloud = Google::Cloud.new
|
181
|
+
# resource_manager = gcloud.resource_manager
|
182
|
+
# project = resource_manager.create_project "tokyo-rain-123"
|
183
|
+
#
|
184
|
+
# @example A project can also be created with a `name` and `labels`:
|
185
|
+
# require "google/cloud"
|
186
|
+
#
|
187
|
+
# gcloud = Google::Cloud.new
|
188
|
+
# resource_manager = gcloud.resource_manager
|
189
|
+
# project = resource_manager.create_project "tokyo-rain-123",
|
190
|
+
# name: "Todos Development", labels: {env: :development}
|
191
|
+
#
|
192
|
+
def create_project project_id, name: nil, labels: nil
|
193
|
+
gapi = service.create_project project_id, name, labels
|
194
|
+
Project.from_gapi gapi, service
|
195
|
+
end
|
196
|
+
|
197
|
+
##
|
198
|
+
# Marks the project for deletion. This method will only affect the
|
199
|
+
# project if the following criteria are met:
|
200
|
+
#
|
201
|
+
# * The project does not have a billing account associated with it.
|
202
|
+
# * The project has a lifecycle state of `ACTIVE`.
|
203
|
+
# * This method changes the project's lifecycle state from `ACTIVE` to
|
204
|
+
# `DELETE_REQUESTED`. The deletion starts at an unspecified time, at
|
205
|
+
# which point the lifecycle state changes to `DELETE_IN_PROGRESS`.
|
206
|
+
#
|
207
|
+
# Until the deletion completes, you can check the lifecycle state by
|
208
|
+
# retrieving the project with Manager#project. The project remains
|
209
|
+
# visible to Manager#project and Manager#projects, but cannot be
|
210
|
+
# updated.
|
211
|
+
#
|
212
|
+
# After the deletion completes, the project is not retrievable by the
|
213
|
+
# Manager#project and Manager#projects methods.
|
214
|
+
#
|
215
|
+
# The caller must have modify permissions for this project.
|
216
|
+
#
|
217
|
+
# @param [String] project_id The ID of the project.
|
218
|
+
#
|
219
|
+
# @example
|
220
|
+
# require "google/cloud"
|
221
|
+
#
|
222
|
+
# gcloud = Google::Cloud.new
|
223
|
+
# resource_manager = gcloud.resource_manager
|
224
|
+
# resource_manager.delete "tokyo-rain-123"
|
225
|
+
#
|
226
|
+
def delete project_id
|
227
|
+
service.delete_project project_id
|
228
|
+
true
|
229
|
+
end
|
230
|
+
|
231
|
+
##
|
232
|
+
# Restores the project. You can only use this method for a project that
|
233
|
+
# has a lifecycle state of `DELETE_REQUESTED`. After deletion starts, as
|
234
|
+
# indicated by a lifecycle state of `DELETE_IN_PROGRESS`, the project
|
235
|
+
# cannot be restored.
|
236
|
+
#
|
237
|
+
# The caller must have modify permissions for this project.
|
238
|
+
#
|
239
|
+
# @param [String] project_id The ID of the project.
|
240
|
+
#
|
241
|
+
# @example
|
242
|
+
# require "google/cloud"
|
243
|
+
#
|
244
|
+
# gcloud = Google::Cloud.new
|
245
|
+
# resource_manager = gcloud.resource_manager
|
246
|
+
# resource_manager.undelete "tokyo-rain-123"
|
247
|
+
#
|
248
|
+
def undelete project_id
|
249
|
+
service.undelete_project project_id
|
250
|
+
true
|
251
|
+
end
|
252
|
+
|
253
|
+
protected
|
254
|
+
|
255
|
+
##
|
256
|
+
# Create an options hash from the projects parameters.
|
257
|
+
def list_projects_options filter, options
|
258
|
+
# Handle only sending in options
|
259
|
+
if filter.is_a?(::Hash) && options.empty?
|
260
|
+
options = filter
|
261
|
+
filter = nil
|
262
|
+
end
|
263
|
+
# Give named parameter priority
|
264
|
+
options[:filter] = filter || options[:filter]
|
265
|
+
options
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|