require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucket"my-bucket"bucket.uniform_bucket_level_access=truebucket.policyrequested_policy_version:3do|p|p.version# the value is 1p.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
The
condition that is associated with this binding, or nil if there is
no condition. NOTE: An unsatisfied condition will not allow user
access via current binding. Different bindings, including their
conditions, are examined independently.
title (String) — Used to identify the condition. Required.
description (String) — Used to document the condition. Optional.
expression (String) — Defines an attribute-based logic
expression using a subset of the Common Expression Language (CEL).
The condition expression can contain multiple statements, each uses
one attributes, and statements are combined using logic operators,
following CEL language specification. Required.
role (String) — Role that is assigned to members. For example,
roles/viewer, roles/editor, or roles/owner. Required.
members (Array<String>) —
Specifies the identities requesting
access for a Cloud Platform resource. members can have the
following values. Required.
allUsers: A special identifier that represents anyone who is on
the internet; with or without a Google account.
allAuthenticatedUsers: A special identifier that represents
anyone who is authenticated with a Google account or a service
account.
user:{emailid}: An email address that represents a specific
Google account. For example, alice@example.com.
serviceAccount:{emailid}: An email address that represents a
service account. For example, my-other-app@appspot.gserviceaccount.com.
group:{emailid}: An email address that represents a Google group.
For example, admins@example.com.
domain:{domain}: The G Suite domain (primary) that represents
all the users of that domain. For example, google.com or
example.com. Required.
condition (Google::Cloud::Storage::Policy::Condition) (defaults to: nil) — The
condition that is associated with this binding. NOTE: An unsatisfied
condition will not allow user access via current binding. Different
bindings, including their conditions, are examined independently.
Optional.
[[["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::Policy::Binding (v1.57.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.57.0 (latest)](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding)\n- [1.56.0](/ruby/docs/reference/google-cloud-storage/1.56.0/Google-Cloud-Storage-Policy-Binding)\n- [1.55.0](/ruby/docs/reference/google-cloud-storage/1.55.0/Google-Cloud-Storage-Policy-Binding)\n- [1.54.0](/ruby/docs/reference/google-cloud-storage/1.54.0/Google-Cloud-Storage-Policy-Binding)\n- [1.53.0](/ruby/docs/reference/google-cloud-storage/1.53.0/Google-Cloud-Storage-Policy-Binding)\n- [1.52.0](/ruby/docs/reference/google-cloud-storage/1.52.0/Google-Cloud-Storage-Policy-Binding)\n- [1.51.0](/ruby/docs/reference/google-cloud-storage/1.51.0/Google-Cloud-Storage-Policy-Binding)\n- [1.50.0](/ruby/docs/reference/google-cloud-storage/1.50.0/Google-Cloud-Storage-Policy-Binding)\n- [1.49.0](/ruby/docs/reference/google-cloud-storage/1.49.0/Google-Cloud-Storage-Policy-Binding)\n- [1.48.1](/ruby/docs/reference/google-cloud-storage/1.48.1/Google-Cloud-Storage-Policy-Binding)\n- [1.47.0](/ruby/docs/reference/google-cloud-storage/1.47.0/Google-Cloud-Storage-Policy-Binding)\n- [1.46.0](/ruby/docs/reference/google-cloud-storage/1.46.0/Google-Cloud-Storage-Policy-Binding)\n- [1.45.0](/ruby/docs/reference/google-cloud-storage/1.45.0/Google-Cloud-Storage-Policy-Binding)\n- [1.44.0](/ruby/docs/reference/google-cloud-storage/1.44.0/Google-Cloud-Storage-Policy-Binding)\n- [1.43.0](/ruby/docs/reference/google-cloud-storage/1.43.0/Google-Cloud-Storage-Policy-Binding)\n- [1.42.0](/ruby/docs/reference/google-cloud-storage/1.42.0/Google-Cloud-Storage-Policy-Binding)\n- [1.41.0](/ruby/docs/reference/google-cloud-storage/1.41.0/Google-Cloud-Storage-Policy-Binding)\n- [1.40.0](/ruby/docs/reference/google-cloud-storage/1.40.0/Google-Cloud-Storage-Policy-Binding)\n- [1.39.0](/ruby/docs/reference/google-cloud-storage/1.39.0/Google-Cloud-Storage-Policy-Binding)\n- [1.38.0](/ruby/docs/reference/google-cloud-storage/1.38.0/Google-Cloud-Storage-Policy-Binding)\n- [1.37.0](/ruby/docs/reference/google-cloud-storage/1.37.0/Google-Cloud-Storage-Policy-Binding)\n- [1.36.2](/ruby/docs/reference/google-cloud-storage/1.36.2/Google-Cloud-Storage-Policy-Binding)\n- [1.35.0](/ruby/docs/reference/google-cloud-storage/1.35.0/Google-Cloud-Storage-Policy-Binding) \nReference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Policy::Binding.\n\nBinding\n-------\n\nValue object associating members and an optional condition with a role. \n\nInherits\n--------\n\n- Object\n\nExamples\n--------\n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\npolicy = bucket.policy requested_policy_version: 3\npolicy.bindings.each do |binding|\n puts binding.role\nend\n```\n\nUpdating a Policy from version 1 to version 3: \n\n```ruby\nrequire \"google/cloud/storage\"\n\nstorage = Google::Cloud::Storage.new\nbucket = storage.bucket \"my-bucket\"\n\nbucket.uniform_bucket_level_access = true\n\nbucket.policy requested_policy_version: 3 do |p|\n p.version # the value is 1\n p.version = 3 # Must be explicitly set to opt-in to support for conditions.\n\n expr = \"resource.name.startsWith(\\\"projects/_/buckets/bucket-name/objects/prefix-a-\\\")\"\n p.bindings.insert({\n role: \"roles/storage.admin\",\n members: [\"user:owner@example.com\"],\n condition: {\n title: \"my-condition\",\n description: \"description of condition\",\n expression: expr\n }\n })\nend\n```\n\nMethods\n-------\n\n### #condition\n\n def condition() -\u003e Google::Cloud::Storage::Policy::Condition, nil\n\nThe\ncondition that is associated with this binding, or `nil` if there is\nno condition. NOTE: An unsatisfied condition will not allow user\naccess via current binding. Different bindings, including their\nconditions, are examined independently. \n**Returns**\n\n- ([Google::Cloud::Storage::Policy::Condition](./Google-Cloud-Storage-Policy-Condition), nil) --- the current value of condition\n\n### #condition=\n\n def condition=(title:, description: nil, expression:)\n\nSets the condition for the binding. \n**Overloads** \n\n def condition=(title:, description: nil, expression:)\n\nSets the condition for the binding. \n**Parameters**\n\n- **title** (String) --- Used to identify the condition. Required.\n- **description** (String) --- Used to document the condition. Optional.\n- **expression** (String) --- Defines an attribute-based logic expression using a subset of the Common Expression Language (CEL). The condition expression can contain multiple statements, each uses one attributes, and statements are combined using logic operators, following CEL language specification. Required.\n\n### #initialize\n\n def initialize(role:, members:, condition: nil) -\u003e Binding\n\nCreates a Binding object. \n**Parameters**\n\n- **role** (String) --- Role that is assigned to members. For example, `roles/viewer`, `roles/editor`, or `roles/owner`. Required.\n- **members** (Array\\\u003cString\\\u003e) ---\n\n Specifies the identities requesting\n access for a Cloud Platform resource. members can have the\n following values. Required.\n - `allUsers`: A special identifier that represents anyone who is on the internet; with or without a Google account.\n - `allAuthenticatedUsers`: A special identifier that represents anyone who is authenticated with a Google account or a service account.\n - `user:{emailid}`: An email address that represents a specific Google account. For example, `alice@example.com`.\n - `serviceAccount:{emailid}`: An email address that represents a service account. For example, `my-other-app@appspot.gserviceaccount.com`.\n - `group:{emailid}`: An email address that represents a Google group. For example, `admins@example.com`.\n - `domain:{domain}`: The G Suite domain (primary) that represents all the users of that domain. For example, `google.com` or `example.com`. Required.\n- **condition** ([Google::Cloud::Storage::Policy::Condition](./Google-Cloud-Storage-Policy-Condition)) *(defaults to: nil)* --- The condition that is associated with this binding. NOTE: An unsatisfied condition will not allow user access via current binding. Different bindings, including their conditions, are examined independently. Optional. \n**Returns**\n\n- ([Binding](./Google-Cloud-Storage-Policy-Binding)) --- a new instance of Binding \n**Raises**\n\n- (ArgumentError)\n\n### #members\n\n def members() -\u003e Array\u003cString\u003e\n\nSpecifies the identities requesting\naccess for a Cloud Platform resource. members can have the\nfollowing values. Required.\n\n- `allUsers`: A special identifier that represents anyone who is on the internet; with or without a Google account.\n- `allAuthenticatedUsers`: A special identifier that represents anyone who is authenticated with a Google account or a service account.\n- `user:{emailid}`: An email address that represents a specific Google account. For example, `alice@example.com`.\n- `serviceAccount:{emailid}`: An email address that represents a service account. For example, `my-other-app@appspot.gserviceaccount.com`.\n- `group:{emailid}`: An email address that represents a Google group. For example, `admins@example.com`.\n- `domain:{domain}`: The G Suite domain (primary) that represents all the users of that domain. For example, `google.com` or `example.com`. Required. \n**Returns**\n\n- (Array\\\u003cString\\\u003e) --- the current value of members\n\n### #members=\n\n def members=(new_members)\n\nSets the members for the binding. \n**Raises**\n\n- (ArgumentError)\n\n### #role\n\n def role() -\u003e String\n\nRole that is assigned to members. For example,\n`roles/viewer`, `roles/editor`, or `roles/owner`. Required. \n**Returns**\n\n- (String) --- the current value of role\n\n### #role=\n\n def role=(new_role)\n\nSets the role for the binding."]]