Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Policy.
Policy
An abstract Cloud IAM Policy for the Cloud Storage service. See concrete
subclasses PolicyV1 and
PolicyV3.
A common pattern for updating a resource's metadata, such as its Policy,
is to read the current data from the service, update the data locally,
and then send the modified data for writing. This pattern may result in
a conflict if two or more processes attempt the sequence simultaneously.
IAM solves this problem with the
#etag property, which is used to
verify whether the policy has changed since the last request. When you
make a request to with an etag value, Cloud IAM compares the etag
value in the request with the existing etag value associated with the
policy. It writes the policy only if the etag values match.
When you update a policy, first read the policy (and its current etag)
from the service, then modify the policy locally, and then write the
modified policy to the service. See
Bucket#policy and
Bucket#policy=.
Inherits
Object
Methods
#etag
defetag()->String
Used to verify whether the policy has changed since
the last request. The policy will be written only if the etag values
match.
Returns
(String) — the current value of etag
#etag=
defetag=(value)->String
Used to verify whether the policy has changed since
the last request. The policy will be written only if the etag values
match.
Parameter
value (String) — the newly set value
Returns
(String) — the newly set value
#version
defversion()->Integer
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
and Overview of Cloud IAM Conditions
for more information.
Returns
(Integer) — the current value of version
#version=
defversion=(value)->Integer
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
and Overview of Cloud IAM Conditions
for more information.
[[["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 (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)\n- [1.56.0](/ruby/docs/reference/google-cloud-storage/1.56.0/Google-Cloud-Storage-Policy)\n- [1.55.0](/ruby/docs/reference/google-cloud-storage/1.55.0/Google-Cloud-Storage-Policy)\n- [1.54.0](/ruby/docs/reference/google-cloud-storage/1.54.0/Google-Cloud-Storage-Policy)\n- [1.53.0](/ruby/docs/reference/google-cloud-storage/1.53.0/Google-Cloud-Storage-Policy)\n- [1.52.0](/ruby/docs/reference/google-cloud-storage/1.52.0/Google-Cloud-Storage-Policy)\n- [1.51.0](/ruby/docs/reference/google-cloud-storage/1.51.0/Google-Cloud-Storage-Policy)\n- [1.50.0](/ruby/docs/reference/google-cloud-storage/1.50.0/Google-Cloud-Storage-Policy)\n- [1.49.0](/ruby/docs/reference/google-cloud-storage/1.49.0/Google-Cloud-Storage-Policy)\n- [1.48.1](/ruby/docs/reference/google-cloud-storage/1.48.1/Google-Cloud-Storage-Policy)\n- [1.47.0](/ruby/docs/reference/google-cloud-storage/1.47.0/Google-Cloud-Storage-Policy)\n- [1.46.0](/ruby/docs/reference/google-cloud-storage/1.46.0/Google-Cloud-Storage-Policy)\n- [1.45.0](/ruby/docs/reference/google-cloud-storage/1.45.0/Google-Cloud-Storage-Policy)\n- [1.44.0](/ruby/docs/reference/google-cloud-storage/1.44.0/Google-Cloud-Storage-Policy)\n- [1.43.0](/ruby/docs/reference/google-cloud-storage/1.43.0/Google-Cloud-Storage-Policy)\n- [1.42.0](/ruby/docs/reference/google-cloud-storage/1.42.0/Google-Cloud-Storage-Policy)\n- [1.41.0](/ruby/docs/reference/google-cloud-storage/1.41.0/Google-Cloud-Storage-Policy)\n- [1.40.0](/ruby/docs/reference/google-cloud-storage/1.40.0/Google-Cloud-Storage-Policy)\n- [1.39.0](/ruby/docs/reference/google-cloud-storage/1.39.0/Google-Cloud-Storage-Policy)\n- [1.38.0](/ruby/docs/reference/google-cloud-storage/1.38.0/Google-Cloud-Storage-Policy)\n- [1.37.0](/ruby/docs/reference/google-cloud-storage/1.37.0/Google-Cloud-Storage-Policy)\n- [1.36.2](/ruby/docs/reference/google-cloud-storage/1.36.2/Google-Cloud-Storage-Policy)\n- [1.35.0](/ruby/docs/reference/google-cloud-storage/1.35.0/Google-Cloud-Storage-Policy) \nReference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Policy.\n\nPolicy\n------\n\nAn abstract Cloud IAM Policy for the Cloud Storage service. See concrete\nsubclasses [PolicyV1](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV1 \"Google::Cloud::Storage::PolicyV1 (class)\") and\n[PolicyV3](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-PolicyV3 \"Google::Cloud::Storage::PolicyV3 (class)\").\n\nA common pattern for updating a resource's metadata, such as its Policy,\nis to read the current data from the service, update the data locally,\nand then send the modified data for writing. This pattern may result in\na conflict if two or more processes attempt the sequence simultaneously.\nIAM solves this problem with the\n[#etag](/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy#Google__Cloud__Storage__Policy_etag_instance_ \"Google::Cloud::Storage::Policy#etag (method)\") property, which is used to\nverify whether the policy has changed since the last request. When you\nmake a request to with an `etag` value, Cloud IAM compares the `etag`\nvalue in the request with the existing `etag` value associated with the\npolicy. It writes the policy only if the `etag` values match.\n\nWhen you update a policy, first read the policy (and its current `etag`)\nfrom the service, then modify the policy locally, and then write the\nmodified policy to the service. See\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)\") and\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)\"). \n\nInherits\n--------\n\n- Object\n\nMethods\n-------\n\n### #etag\n\n def etag() -\u003e String\n\nUsed to verify whether the policy has changed since\nthe last request. The policy will be written only if the `etag` values\nmatch. \n**Returns**\n\n- (String) --- the current value of etag\n\n### #etag=\n\n def etag=(value) -\u003e String\n\nUsed to verify whether the policy has changed since\nthe last request. The policy will be written only if the `etag` values\nmatch. \n**Parameter**\n\n- **value** (String) --- the newly set value \n**Returns**\n\n- (String) --- the newly set value\n\n### #version\n\n def version() -\u003e Integer\n\nThe syntax schema version of the policy. Each version\nof the policy contains a specific syntax schema that can be used by bindings.\nThe newer version may contain role bindings with the newer syntax schema\nthat is unsupported by earlier versions. This field is not intended to\nbe used for any purposes other than policy syntax schema control.\n\nThe following policy versions are valid:\n\n- 1 - The first version of Cloud IAM policy schema. Supports binding one role to one or more members. Does not support conditional bindings.\n- 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. \n**Returns**\n\n- (Integer) --- the current value of version\n\n### #version=\n\n def version=(value) -\u003e Integer\n\nThe syntax schema version of the policy. Each version\nof the policy contains a specific syntax schema that can be used by bindings.\nThe newer version may contain role bindings with the newer syntax schema\nthat is unsupported by earlier versions. This field is not intended to\nbe used for any purposes other than policy syntax schema control.\n\nThe following policy versions are valid:\n\n- 1 - The first version of Cloud IAM policy schema. Supports binding one role to one or more members. Does not support conditional bindings.\n- 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. \n**Parameter**\n\n- **value** (Integer) --- the newly set value \n**Returns**\n\n- (Integer) --- the newly set value"]]