Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 04fdc8e

Browse files
committed
Updates AccessEntry with condition setter/getter
1 parent bbfb818 commit 04fdc8e

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

google/cloud/bigquery/dataset.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,15 @@ def __init__(
298298
role: Optional[str] = None,
299299
entity_type: Optional[str] = None,
300300
entity_id: Optional[Union[Dict[str, Any], str]] = None,
301+
**kwargs,
301302
):
302303
self._properties = {}
303304
if entity_type is not None:
304305
self._properties[entity_type] = entity_id
305306
self._properties["role"] = role
306307
self._entity_type = entity_type
308+
for prop, val in kwargs.items():
309+
setattr(self, prop, val)
307310

308311
@property
309312
def role(self) -> Optional[str]:
@@ -437,6 +440,25 @@ def special_group(self) -> Optional[str]:
437440
def special_group(self, value):
438441
self._properties["specialGroup"] = value
439442

443+
@property
444+
def condition(self) -> Optional["Condition"]:
445+
"""Optional[Condition]: The IAM condition associated with this entry."""
446+
value = self._properties.get("condition")
447+
if value:
448+
return Condition.from_api_repr(value)
449+
450+
@condition.setter
451+
def condition(self, value: Union["Condition", dict, None]):
452+
"""Set the IAM condition for this entry."""
453+
if value is None:
454+
self._properties["condition"] = None
455+
elif isinstance(value, Condition):
456+
self._properties["condition"] = value.to_api_repr()
457+
elif isinstance(value, dict):
458+
self._properties["condition"] = value
459+
else:
460+
raise TypeError("condition must be a Condition object, dict, or None")
461+
440462
@property
441463
def entity_type(self) -> Optional[str]:
442464
"""The entity_type of the entry."""
@@ -469,6 +491,9 @@ def _key(self):
469491
return (self.role, self._entity_type, self.entity_id, prop_tup)
470492

471493
def __hash__(self):
494+
# TODO: if a dict is a sub property, hash fails.
495+
print(f"DINOSAUR: {self._key()}")
496+
472497
return hash(self._key())
473498

474499
def to_api_repr(self):
@@ -1163,3 +1188,30 @@ def from_api_repr(cls, resource: Dict[str, Any]) -> "Condition":
11631188
title=resource.get("title"),
11641189
description=resource.get("description"),
11651190
)
1191+
1192+
def __eq__(self, other: object) -> bool:
1193+
"""Check for equality based on expression, title, and description."""
1194+
if not isinstance(other, Condition):
1195+
return NotImplemented
1196+
return (
1197+
self.expression == other.expression
1198+
and self.title == other.title
1199+
and self.description == other.description
1200+
)
1201+
1202+
def __ne__(self, other: object) -> bool:
1203+
"""Check for inequality."""
1204+
return not self == other
1205+
1206+
def __hash__(self) -> int:
1207+
"""Generate a hash based on expression, title, and description."""
1208+
return hash((self.expression, self.title, self.description))
1209+
1210+
def __repr__(self) -> str:
1211+
"""Return a string representation of the Condition object."""
1212+
parts = [f"expression={self.expression!r}"]
1213+
if self.title is not None:
1214+
parts.append(f"title={self.title!r}")
1215+
if self.description is not None:
1216+
parts.append(f"description={self.description!r}")
1217+
return f"Condition({', '.join(parts)})"

0 commit comments

Comments
 (0)