Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::PolicyV1.
A subclass of Policy that supports access to #roles
and related helpers. Attempts to call #bindings and #version= will
raise a runtime error. To update the Policy version and add bindings with a newer
syntax, use PolicyV3 instead by calling
Bucket#policy with requested_policy_version: 3. To
obtain instances of this class, call Bucket#policy
without the requested_policy_version keyword argument.
require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.policydo|p|p.version# the value is 1p.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
defadd(role_name,member)
Convenience method for adding a member to a binding on this policy.
See Understanding
Roles for a
listing of primitive and curated roles. See 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".
Convenience method for removing a member from a binding on this
policy. See Understanding
Roles for a
listing of primitive and curated roles. See 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".
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. See Understanding
Roles for a
listing of primitive and curated roles. See Buckets:
setIamPolicy
for a listing of values and patterns for members.
Returns
(Array<String>) — The members strings, or an empty array.
Returns the version 1 bindings (no conditions) as a hash that
associates roles with arrays of members. See Understanding
Roles for a
listing of primitive and curated roles. See Buckets:
setIamPolicy
for a listing of values and patterns for members.
Returns
(Hash) — the current value of roles
#roles=
defroles=(value)->Hash
Returns the version 1 bindings (no conditions) as a hash that
associates roles with arrays of members. See Understanding
Roles for a
listing of primitive and curated roles. See Buckets:
setIamPolicy
for a listing of values and patterns for members.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Storage API - Class Google::Cloud::Storage::PolicyV1 (v1.57.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.57.0 (latest)](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1)\n- [1.56.0](/ruby/docs/reference/google-cloud-storage/1.56.0/Google-Cloud-Storage-PolicyV1)\n- [1.55.0](/ruby/docs/reference/google-cloud-storage/1.55.0/Google-Cloud-Storage-PolicyV1)\n- [1.54.0](/ruby/docs/reference/google-cloud-storage/1.54.0/Google-Cloud-Storage-PolicyV1)\n- [1.53.0](/ruby/docs/reference/google-cloud-storage/1.53.0/Google-Cloud-Storage-PolicyV1)\n- [1.52.0](/ruby/docs/reference/google-cloud-storage/1.52.0/Google-Cloud-Storage-PolicyV1)\n- [1.51.0](/ruby/docs/reference/google-cloud-storage/1.51.0/Google-Cloud-Storage-PolicyV1)\n- [1.50.0](/ruby/docs/reference/google-cloud-storage/1.50.0/Google-Cloud-Storage-PolicyV1)\n- [1.49.0](/ruby/docs/reference/google-cloud-storage/1.49.0/Google-Cloud-Storage-PolicyV1)\n- [1.48.1](/ruby/docs/reference/google-cloud-storage/1.48.1/Google-Cloud-Storage-PolicyV1)\n- [1.47.0](/ruby/docs/reference/google-cloud-storage/1.47.0/Google-Cloud-Storage-PolicyV1)\n- [1.46.0](/ruby/docs/reference/google-cloud-storage/1.46.0/Google-Cloud-Storage-PolicyV1)\n- [1.45.0](/ruby/docs/reference/google-cloud-storage/1.45.0/Google-Cloud-Storage-PolicyV1)\n- [1.44.0](/ruby/docs/reference/google-cloud-storage/1.44.0/Google-Cloud-Storage-PolicyV1)\n- [1.43.0](/ruby/docs/reference/google-cloud-storage/1.43.0/Google-Cloud-Storage-PolicyV1)\n- [1.42.0](/ruby/docs/reference/google-cloud-storage/1.42.0/Google-Cloud-Storage-PolicyV1)\n- [1.41.0](/ruby/docs/reference/google-cloud-storage/1.41.0/Google-Cloud-Storage-PolicyV1)\n- [1.40.0](/ruby/docs/reference/google-cloud-storage/1.40.0/Google-Cloud-Storage-PolicyV1)\n- [1.39.0](/ruby/docs/reference/google-cloud-storage/1.39.0/Google-Cloud-Storage-PolicyV1)\n- [1.38.0](/ruby/docs/reference/google-cloud-storage/1.38.0/Google-Cloud-Storage-PolicyV1)\n- [1.37.0](/ruby/docs/reference/google-cloud-storage/1.37.0/Google-Cloud-Storage-PolicyV1)\n- [1.36.2](/ruby/docs/reference/google-cloud-storage/1.36.2/Google-Cloud-Storage-PolicyV1)\n- [1.35.0](/ruby/docs/reference/google-cloud-storage/1.35.0/Google-Cloud-Storage-PolicyV1) \nReference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::PolicyV1.\n\nA subclass of [Policy](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy \"Google::Cloud::Storage::Policy (class)\") that supports access to [#roles](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1#Google__Cloud__Storage__PolicyV1_roles_instance_ \"Google::Cloud::Storage::PolicyV1#roles (method)\")\nand related helpers. Attempts to call [#bindings](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1#Google__Cloud__Storage__PolicyV1_bindings_instance_ \"Google::Cloud::Storage::PolicyV1#bindings (method)\") and [#version=](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1#Google__Cloud__Storage__PolicyV1_version__instance_ \"Google::Cloud::Storage::PolicyV1#version= (method)\") will\nraise a runtime error. To update the Policy version and add bindings with a newer\nsyntax, use [PolicyV3](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3 \"Google::Cloud::Storage::PolicyV3 (class)\") instead by calling\n[Bucket#policy](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket#Google__Cloud__Storage__Bucket_policy_instance_ \"Google::Cloud::Storage::Bucket#policy (method)\") with `requested_policy_version: 3`. To\nobtain instances of this class, call [Bucket#policy](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket#Google__Cloud__Storage__Bucket_policy_instance_ \"Google::Cloud::Storage::Bucket#policy (method)\")\nwithout the `requested_policy_version` keyword argument. \n\nInherits\n--------\n\n- [Google::Cloud::Storage::Policy](./Google-Cloud-Storage-Policy)\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.policy do |p|\n p.version # the value is 1\n p.remove \"roles/storage.admin\", \"user:owner@example.com\"\n p.add \"roles/storage.admin\", \"user:newowner@example.com\"\n p.roles[\"roles/storage.objectViewer\"] = [\"allUsers\"]\nend\n```\n\nMethods\n-------\n\n### #add\n\n def add(role_name, member)\n\nConvenience method for adding a member to a binding on this policy.\nSee [Understanding\nRoles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Parameters**\n\n- **role_name** (String) --- A Cloud IAM role, such as `\"roles/storage.admin\"`.\n- **member** (String) --- A Cloud IAM identity, such as `\"user:owner@example.com\"`.\n**Example** \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\n\nbucket = storage.bucket \"my-bucket\"\n\nbucket.policy do |p|\n p.add \"roles/storage.admin\", \"user:newowner@example.com\"\nend\n```\n\n### #deep_dup\n\n def deep_dup() -\u003e Policy\n\nReturns a deep copy of the policy. \n**Returns**\n\n- ([Policy](./Google-Cloud-Storage-Policy))\n\n### #remove\n\n def remove(role_name, member)\n\nConvenience method for removing a member from a binding on this\npolicy. See [Understanding\nRoles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Parameters**\n\n- **role_name** (String) --- A Cloud IAM role, such as `\"roles/storage.admin\"`.\n- **member** (String) --- A Cloud IAM identity, such as `\"user:owner@example.com\"`.\n**Example** \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\n\nbucket = storage.bucket \"my-bucket\"\n\nbucket.policy do |p|\n p.remove \"roles/storage.admin\", \"user:owner@example.com\"\nend\n```\n\n### #role\n\n def role(role_name) -\u003e Array\u003cString\u003e\n\nConvenience method returning the array of members bound to a role in\nthis policy, or an empty array if no value is present for the role in\n[#roles](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1#Google__Cloud__Storage__PolicyV1_roles_instance_ \"Google::Cloud::Storage::PolicyV1#roles (method)\"). See [Understanding\nRoles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Returns**\n\n- (Array\\\u003cString\\\u003e) --- The members strings, or an empty array.\n**Example** \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\n\nbucket = storage.bucket \"my-bucket\"\n\nbucket.policy do |p|\n p.role(\"roles/storage.admin\") \u003c\u003c \"user:owner@example.com\"\nend\n```\n\n### #roles\n\n def roles() -\u003e Hash\n\nReturns the version 1 bindings (no conditions) as a hash that\nassociates roles with arrays of members. See [Understanding\nRoles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Returns**\n\n- (Hash) --- the current value of roles\n\n### #roles=\n\n def roles=(value) -\u003e Hash\n\nReturns the version 1 bindings (no conditions) as a hash that\nassociates roles with arrays of members. See [Understanding\nRoles](https://cloud.google.com/iam/docs/understanding-roles) for a\nlisting of primitive and curated roles. See [Buckets:\nsetIamPolicy](https://cloud.google.com/storage/docs/json_api/v1/buckets/setIamPolicy)\nfor a listing of values and patterns for members. \n**Parameter**\n\n- **value** (Hash) --- the newly set value \n**Returns**\n\n- (Hash) --- the newly set value"]]