1.62.2 (latest) 1.62.1 1.61.0 1.60.0 1.59.0 1.58.0 1.57.1 1.56.0 1.55.0 1.54.0 1.53.0 1.52.0 1.51.0 1.50.0 1.49.0 1.48.1 1.47.0 1.46.0 1.45.0 1.44.0 1.43.0 1.42.0 1.41.0 1.40.0 1.39.0 1.38.0 1.37.0 1.36.2 1.35.0 Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::PolicyV3.

A subclass of [Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt "Google::Cloud::Storage::Policy (class)") that supports access to [#bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3.md.txt#Google__Cloud__Storage__PolicyV3_bindings_instance_ "Google::Cloud::Storage::PolicyV3#bindings (method)")
and [#version=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3.md.txt#Google__Cloud__Storage__PolicyV3_version__instance_ "Google::Cloud::Storage::PolicyV3#version= (method)"). Attempts to call [#roles](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3.md.txt#Google__Cloud__Storage__PolicyV3_roles_instance_ "Google::Cloud::Storage::PolicyV3#roles (method)") and relate helpers will raise a runtime
error. This class may be used to update the Policy version and add bindings with a newer
syntax. To obtain instances of this class, call [Bucket#policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_policy_instance_ "Google::Cloud::Storage::Bucket#policy (method)")
with `requested_policy_version: 3`.

## Inherits

- [Google::Cloud::Storage::Policy](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy.md.txt)

## Examples

Updating Policy version 1 to version 3:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true

bucket.policy requested_policy_version: 3 do |p|
  p.version # the value is 1
  p.version = 3

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```

Using Policy version 3:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access? # true

bucket.policy requested_policy_version: 3 do |p|
  p.version = 3 # Must be explicitly set to opt-in to support for conditions.

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```

## Methods

### #bindings

```ruby
def bindings() -> Bindings
```
Returns the Policy's bindings object that associate roles with
an array of members. Conditions can be configured on the [Google::Cloud::Storage::Policy::Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") object. See
[Understanding Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
listing of primitive and curated roles. See [Buckets:
setIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)
for a listing of values and patterns for members.
**Returns**

- ([Bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt)) --- the current value of bindings

### #bindings=

```ruby
def bindings=(value) -> Bindings
```
Returns the Policy's bindings object that associate roles with
an array of members. Conditions can be configured on the [Google::Cloud::Storage::Policy::Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") object. See
[Understanding Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
listing of primitive and curated roles. See [Buckets:
setIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)
for a listing of values and patterns for members.
**Parameter**

- **value** ([Bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt)) --- the newly set value
**Returns**

- ([Bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt)) --- the newly set value

### #version=

```ruby
def version=(new_version)
```
Updates the syntax schema version of the policy. Each version of the
policy contains a specific syntax schema that can be used by bindings.
The newer version may contain role bindings with the newer syntax schema
that is unsupported by earlier versions. This field is not intended to
be used for any purposes other than policy syntax schema control.

The following policy versions are valid:

- 1 - The first version of Cloud IAM policy schema. Supports binding one role to one or more members. Does not support conditional bindings.
- 3 - Introduces the condition field in the role binding, which further constrains the role binding via context-based and attribute-based rules. See [Understanding policies](https://cloud.google.com/iam/docs/policies) and [Overview of Cloud IAM Conditions](https://cloud.google.com/iam/docs/conditions-overview) for more information.
**Parameter**

- **new_version** (Integer) --- The syntax schema version of the policy.
**Example**

Updating Policy version 1 to version 3:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true

bucket.policy requested_policy_version: 3 do |p|
  p.version # the value is 1
  p.version = 3

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```