google-cloud-resource_manager - Class Google::Cloud::ResourceManager::Project (v0.36.2)

Reference documentation and code samples for the google-cloud-resource_manager class Google::Cloud::ResourceManager::Project.

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.

Inherits

  • Object

Example

require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.update do |p|
  p.name = "My Project"
  p.labels["env"] = "production"
end

Methods

#active?

def active?() -> Boolean

Checks if the state is ACTIVE.

Returns
  • (Boolean)

#created_at

def created_at()

The time that this project was created.

#delete

def delete()

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 to DELETE_REQUESTED. The deletion starts at an unspecified time, at which point the lifecycle state changes to DELETE_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.

Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.active? #=> true
project.delete
project.active? #=> false
project.delete_requested? #=> true

#delete_in_progress?

def delete_in_progress?() -> Boolean

Checks if the state is DELETE_IN_PROGRESS.

Returns
  • (Boolean)

#delete_requested?

def delete_requested?() -> Boolean

Checks if the state is DELETE_REQUESTED.

Returns
  • (Boolean)

#labels

def labels() { |labels| ... }

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)

Yields
  • (labels) — a block for setting labels
Yield Parameter
  • labels (Hash) — the hash accepting labels
Examples

Labels are read-only and cannot be changed:

require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.labels["env"] # read-only

Labels can be updated by passing a block, or with #labels=:

require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.labels do |labels|
  labels["env"] = "production"
end

#labels=

def labels=(new_labels)

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)

Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.labels = { "env" => "production" }

#name

def name()

The user-assigned name of the project.

#name=

def name=(new_name)

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.

Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.name = "My Project"

#parent

def parent() -> nil, Resource

An optional reference to a parent Resource.

Supported parent types include "organization" and "folder". Once set, the parent can be updated but cannot be cleared.

The resource object returned is read-only and cannot be changed. A new resource object can be set using the #parent= or #update methods. (See Resource and Manager#resource.)

Returns
  • (nil, Resource) — the reference to a parent Resource (read-only)

#parent=

def parent=(new_parent)

Updates the reference to a parent with a new Resource.

Supported parent types include "organization" and "folder". Once set, the parent can be updated but cannot be cleared.

The end user must have the resourcemanager.projects.create permission on the parent.

(See Resource and Manager#resource.)

Parameter
  • new_parent (Resource) — A new parent Resource.
Raises
  • (ArgumentError)
Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
folder = resource_manager.resource "folder", "1234"
project.parent = folder

#policy

def policy() { |policy| ... } -> Policy

Gets and updates the Cloud IAM access control policy for this project.

Yields
  • (policy) — A block for updating the policy. The latest policy will be read from the service and passed to the block. After the block completes, the modified policy will be written to the service.
Yield Parameter
  • policy (Policy) — the current Cloud IAM Policy for this project
Returns
  • (Policy) — the current Cloud IAM Policy for this project
Examples
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"

policy = project.policy

Update the policy by passing a block:

require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"

project.policy do |p|
  p.add "roles/owner", "user:owner@example.com"
end

#policy=

def policy=(new_policy) -> Policy
Alias Of: #update_policy

Updates the Cloud IAM access control policy for this project. The policy should be read from #policy. See 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.

Parameter
  • new_policy (Policy) — a new or modified Cloud IAM Policy for this project
Returns
  • (Policy) — the policy returned by the API update operation
Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"

policy = project.policy # API call

policy.add "roles/owner", "user:owner@example.com"

project.update_policy policy # API call

#project_id

def project_id()

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

#project_number

def project_number()

The number uniquely identifying the project. e.g. 415104041262

#refresh!

def refresh!()
Alias Of: #reload!

Reloads the project (with updated state) from the Google Cloud Resource Manager service.

Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.reload!

#reload!

def reload!()
Aliases

Reloads the project (with updated state) from the Google Cloud Resource Manager service.

Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.reload!

#state

def state()

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.

#test_permissions

def test_permissions(*permissions) -> Array<String>

Tests the specified permissions against the Cloud IAM access control policy.

Parameter
  • permissions (String, Array<String>) — The set of permissions to check access for. Permissions with wildcards (such as * or storage.*) are not allowed.
Returns
  • (Array<String>) — The permissions that have access
Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
perms = project.test_permissions "resourcemanager.projects.get",
                                 "resourcemanager.projects.delete"
perms.include? "resourcemanager.projects.get"    #=> true
perms.include? "resourcemanager.projects.delete" #=> false

#undelete

def undelete()

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.

Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
project.delete_requested? #=> true
project.undelete
project.delete_requested? #=> false
project.active? #=> true

#unspecified?

def unspecified?() -> Boolean

Checks if the state is LIFECYCLE_STATE_UNSPECIFIED.

Returns
  • (Boolean)

#update

def update() { |project| ... }

Updates the project in a single API call. See Updater

Yields
  • (project) — a block yielding a project delegate
Yield Parameter
Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
folder = resource_manager.resource "folder", "1234"
project.update do |p|
  p.name = "My Project"
  p.parent = folder
  p.labels["env"] = "production"
end

#update_policy

def update_policy(new_policy) -> Policy
Aliases

Updates the Cloud IAM access control policy for this project. The policy should be read from #policy. See 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.

Parameter
  • new_policy (Policy) — a new or modified Cloud IAM Policy for this project
Returns
  • (Policy) — the policy returned by the API update operation
Example
require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"

policy = project.policy # API call

policy.add "roles/owner", "user:owner@example.com"

project.update_policy policy # API call