Class: Google::Cloud::ResourceManager::Project
- Inherits:
-
Object
- Object
- Google::Cloud::ResourceManager::Project
- Defined in:
- lib/google/cloud/resource_manager/project.rb,
lib/google/cloud/resource_manager/project/list.rb,
lib/google/cloud/resource_manager/project/updater.rb
Overview
Project
Project is a high-level Google Cloud Platform entity. It is a container for ACLs, APIs, AppEngine Apps, VMs, and other Google Cloud Platform resources.
Direct Known Subclasses
Defined Under Namespace
Instance Method Summary collapse
-
#active? ⇒ Boolean
Checks if the state is
ACTIVE
. -
#created_at ⇒ Object
The time that this project was created.
-
#delete ⇒ Object
Marks the project for deletion.
-
#delete_in_progress? ⇒ Boolean
Checks if the state is
DELETE_IN_PROGRESS
. -
#delete_requested? ⇒ Boolean
Checks if the state is
DELETE_REQUESTED
. -
#labels {|labels| ... } ⇒ Object
The labels associated with this project.
-
#labels=(new_labels) ⇒ Object
Updates the labels associated with this project.
-
#name ⇒ Object
The user-assigned name of the project.
-
#name=(new_name) ⇒ Object
Updates the user-assigned name of the project.
-
#policy(force: false) {|policy| ... } ⇒ Policy
Gets and updates the Cloud IAM access control policy for this project.
-
#policy=(new_policy) ⇒ Object
Updates the Cloud IAM access control policy for this project.
-
#project_id ⇒ Object
The unique, user-assigned ID of the project.
-
#project_number ⇒ Object
The number uniquely identifying the project.
-
#reload! ⇒ Object
(also: #refresh!)
Reloads the project (with updated state) from the Google Cloud Resource Manager service.
-
#state ⇒ Object
The project lifecycle state.
-
#test_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
-
#undelete ⇒ Object
Restores the project.
-
#unspecified? ⇒ Boolean
Checks if the state is
LIFECYCLE_STATE_UNSPECIFIED
. -
#update {|project| ... } ⇒ Object
Updates the project in a single API call.
Instance Method Details
#active? ⇒ Boolean
Checks if the state is ACTIVE
.
196 197 198 199 |
# File 'lib/google/cloud/resource_manager/project.rb', line 196 def active? return false if state.nil? "ACTIVE".casecmp(state).zero? end |
#created_at ⇒ Object
The time that this project was created.
171 172 173 174 175 |
# File 'lib/google/cloud/resource_manager/project.rb', line 171 def created_at Time.parse @gapi.create_time rescue nil end |
#delete ⇒ Object
Marks the project for deletion. This method will only affect the project if the following criteria are met:
- The project does not have a billing account associated with it.
- The project has a lifecycle state of
ACTIVE
. - This method changes the project's lifecycle state from
ACTIVE
toDELETE_REQUESTED
. The deletion starts at an unspecified time, at which point the lifecycle state changes toDELETE_IN_PROGRESS
.
Until the deletion completes, you can check the lifecycle state by calling #reload!, or by retrieving the project with Manager#project. The project remains visible to Manager#project and Manager#projects, but cannot be updated.
After the deletion completes, the project is not retrievable by the Manager#project and Manager#projects methods.
The caller must have modify permissions for this project.
294 295 296 297 298 |
# File 'lib/google/cloud/resource_manager/project.rb', line 294 def delete service.delete_project project_id reload! true end |
#delete_in_progress? ⇒ Boolean
Checks if the state is DELETE_IN_PROGRESS
.
217 218 219 220 |
# File 'lib/google/cloud/resource_manager/project.rb', line 217 def delete_in_progress? return false if state.nil? "DELETE_IN_PROGRESS".casecmp(state).zero? end |
#delete_requested? ⇒ Boolean
Checks if the state is DELETE_REQUESTED
.
210 211 212 213 |
# File 'lib/google/cloud/resource_manager/project.rb', line 210 def delete_requested? return false if state.nil? "DELETE_REQUESTED".casecmp(state).zero? end |
#labels {|labels| ... } ⇒ Object
The labels associated with this project.
Label keys must be between 1 and 63 characters long and must conform
to the regular expression a-z?
.
Label values must be between 0 and 63 characters long and must conform
to the regular expression (a-z?)?
.
No more than 256 labels can be associated with a given resource.
(Hash
)
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/google/cloud/resource_manager/project.rb', line 132 def labels labels = @gapi.labels.to_h if block_given? yielded_labels = labels.dup yield yielded_labels self.labels = yielded_labels if yielded_labels != labels # changed else labels.freeze end end |
#labels=(new_labels) ⇒ Object
Updates the labels associated with this project.
Label keys must be between 1 and 63 characters long and must conform
to the regular expression a-z?
.
Label values must be between 0 and 63 characters long and must conform
to the regular expression (a-z?)?
.
No more than 256 labels can be associated with a given resource.
(Hash
)
162 163 164 165 166 |
# File 'lib/google/cloud/resource_manager/project.rb', line 162 def labels= new_labels ensure_service! @gapi.labels = new_labels @gapi = service.update_project @gapi end |
#name ⇒ Object
The user-assigned name of the project.
76 77 78 |
# File 'lib/google/cloud/resource_manager/project.rb', line 76 def name @gapi.name end |
#name=(new_name) ⇒ Object
Updates the user-assigned name of the project. This field is optional and can remain unset.
Allowed characters are: lowercase and uppercase letters, numbers, hyphen, single-quote, double-quote, space, and exclamation point.
94 95 96 97 98 |
# File 'lib/google/cloud/resource_manager/project.rb', line 94 def name= new_name ensure_service! @gapi.name = new_name @gapi = service.update_project @gapi end |
#policy(force: false) {|policy| ... } ⇒ Policy
Gets and updates the Cloud IAM access control policy for this project.
373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/google/cloud/resource_manager/project.rb', line 373 def policy force: false @policy = nil if force || block_given? @policy ||= begin ensure_service! gapi = service.get_policy project_id Policy.from_gapi gapi end return @policy unless block_given? p = @policy.deep_dup yield p self.policy = p end |
#policy=(new_policy) ⇒ Object
Updates the Cloud IAM access control
policy for this project. The policy should be read from #policy. See
Google::Cloud::ResourceManager::Policy for an explanation of the
policy etag
property and how to modify policies.
You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.
415 416 417 418 419 420 421 |
# File 'lib/google/cloud/resource_manager/project.rb', line 415 def policy= new_policy ensure_service! gapi = service.set_policy project_id, new_policy.to_gapi # Convert symbols to strings for backwards compatibility. # This will go away when we add a ResourceManager::Policy class. @policy = Policy.from_gapi gapi end |
#project_id ⇒ Object
The unique, user-assigned ID of the project. It must be 6 to 30 lowercase letters, digits, or hyphens. It must start with a letter. Trailing hyphens are prohibited. e.g. tokyo-rain-123
62 63 64 |
# File 'lib/google/cloud/resource_manager/project.rb', line 62 def project_id @gapi.project_id end |
#project_number ⇒ Object
The number uniquely identifying the project. e.g. 415104041262
69 70 71 |
# File 'lib/google/cloud/resource_manager/project.rb', line 69 def project_number @gapi.project_number end |
#reload! ⇒ Object Also known as: refresh!
Reloads the project (with updated state) from the Google Cloud Resource Manager service.
259 260 261 |
# File 'lib/google/cloud/resource_manager/project.rb', line 259 def reload! @gapi = service.get_project project_id end |
#state ⇒ Object
The project lifecycle state.
Possible values are:
ACTIVE
- The normal and active state.DELETE_REQUESTED
- The project has been marked for deletion by the user (by invoking ##delete) or by the system (Google Cloud Platform). This can generally be reversed by invoking #undelete.DELETE_IN_PROGRESS
- The process of deleting the project has begun. Reversing the deletion is no longer possible.LIFECYCLE_STATE_UNSPECIFIED
- Unspecified state. This is only used/useful for distinguishing unset values.
190 191 192 |
# File 'lib/google/cloud/resource_manager/project.rb', line 190 def state @gapi.lifecycle_state end |
#test_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
446 447 448 449 450 451 |
# File 'lib/google/cloud/resource_manager/project.rb', line 446 def * = Array().flatten ensure_service! gapi = service. project_id, gapi. end |
#undelete ⇒ Object
Restores the project. You can only use this method for a project that
has a lifecycle state of DELETE_REQUESTED
. After deletion starts, as
indicated by a lifecycle state of DELETE_IN_PROGRESS
, the project
cannot be restored.
The caller must have modify permissions for this project.
318 319 320 321 322 |
# File 'lib/google/cloud/resource_manager/project.rb', line 318 def undelete service.undelete_project project_id reload! true end |
#unspecified? ⇒ Boolean
Checks if the state is LIFECYCLE_STATE_UNSPECIFIED
.
203 204 205 206 |
# File 'lib/google/cloud/resource_manager/project.rb', line 203 def unspecified? return false if state.nil? "LIFECYCLE_STATE_UNSPECIFIED".casecmp(state).zero? end |
#update {|project| ... } ⇒ Object
Updates the project in a single API call. See Updater
239 240 241 242 243 244 245 246 |
# File 'lib/google/cloud/resource_manager/project.rb', line 239 def update updater = Updater.from_project self yield updater if updater.gapi.to_h != @gapi.to_h # changed @gapi = service.update_project updater.gapi end self end |