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::PolicyV1.

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 [#roles](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1.md.txt#Google__Cloud__Storage__PolicyV1_roles_instance_ "Google::Cloud::Storage::PolicyV1#roles (method)")
and related helpers. Attempts to call [#bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1.md.txt#Google__Cloud__Storage__PolicyV1_bindings_instance_ "Google::Cloud::Storage::PolicyV1#bindings (method)") and [#version=](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1.md.txt#Google__Cloud__Storage__PolicyV1_version__instance_ "Google::Cloud::Storage::PolicyV1#version= (method)") will
raise a runtime error. To update the Policy version and add bindings with a newer
syntax, use [PolicyV3](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3.md.txt "Google::Cloud::Storage::PolicyV3 (class)") instead by calling
[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`. 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)")
without the `requested_policy_version` keyword argument.

## Inherits

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

## Example

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

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

bucket.policy do |p|
  p.version # the value is 1
  p.remove "roles/storage.admin", "user:owner@example.com"
  p.add "roles/storage.admin", "user:newowner@example.com"
  p.roles["roles/storage.objectViewer"] = ["allUsers"]
end
```

## Methods

### #add

```ruby
def add(role_name, member)
```
Convenience method for adding a member to a binding on this policy.
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.
**Parameters**

- **role_name** (String) --- A Cloud IAM role, such as `"roles/storage.admin"`.
- **member** (String) --- A Cloud IAM identity, such as `"user:owner@example.com"`.
**Example**

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

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.policy do |p|
  p.add "roles/storage.admin", "user:newowner@example.com"
end
```

### #deep_dup

```ruby
def deep_dup() -> Policy
```
Returns a deep copy of the policy.
**Returns**

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

### #remove

```ruby
def remove(role_name, member)
```
Convenience method for removing a member from a binding on this
policy. 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.
**Parameters**

- **role_name** (String) --- A Cloud IAM role, such as `"roles/storage.admin"`.
- **member** (String) --- A Cloud IAM identity, such as `"user:owner@example.com"`.
**Example**

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

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.policy do |p|
  p.remove "roles/storage.admin", "user:owner@example.com"
end
```

### #role

```ruby
def role(role_name) -> Array<String>
```
Convenience method returning the array of members bound to a role in
this policy, or an empty array if no value is present for the role in
[#roles](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1.md.txt#Google__Cloud__Storage__PolicyV1_roles_instance_ "Google::Cloud::Storage::PolicyV1#roles (method)"). 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**

- (Array\<String\>) --- The members strings, or an empty array.
**Example**

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

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.policy do |p|
  p.role("roles/storage.admin") << "user:owner@example.com"
end
```

### #roles

```ruby
def roles() -> Hash
```
Returns the version 1 bindings (no conditions) as a hash that
associates roles with arrays of members. 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**

- (Hash) --- the current value of roles

### #roles=

```ruby
def roles=(value) -> Hash
```
Returns the version 1 bindings (no conditions) as a hash that
associates roles with arrays of members. 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** (Hash) --- the newly set value
**Returns**

- (Hash) --- the newly set value