|
20 | 20 | import copy
|
21 | 21 |
|
22 | 22 | import google.cloud._helpers
|
| 23 | + |
23 | 24 | from google.cloud.bigquery import _helpers
|
24 | 25 | from google.cloud.bigquery.model import ModelReference
|
25 | 26 | from google.cloud.bigquery.routine import RoutineReference
|
@@ -145,38 +146,60 @@ def __init__(self, role, entity_type, entity_id):
|
145 | 146 | "Role must be set for entity " "type %r" % (entity_type,)
|
146 | 147 | )
|
147 | 148 |
|
148 |
| - self.role = role |
149 |
| - self.entity_type = entity_type |
150 |
| - self.entity_id = entity_id |
| 149 | + self._role = role |
| 150 | + self._entity_type = entity_type |
| 151 | + self._entity_id = entity_id |
| 152 | + |
| 153 | + @property |
| 154 | + def role(self): |
| 155 | + """str: The role of the entry.""" |
| 156 | + return self._role |
| 157 | + |
| 158 | + @property |
| 159 | + def entity_type(self): |
| 160 | + """str: The entity_type of the entry.""" |
| 161 | + return self._entity_type |
| 162 | + |
| 163 | + @property |
| 164 | + def entity_id(self): |
| 165 | + """str: The entity_id of the entry.""" |
| 166 | + return self._entity_id |
151 | 167 |
|
152 | 168 | def __eq__(self, other):
|
153 | 169 | if not isinstance(other, AccessEntry):
|
154 | 170 | return NotImplemented
|
155 |
| - return ( |
156 |
| - self.role == other.role |
157 |
| - and self.entity_type == other.entity_type |
158 |
| - and self.entity_id == other.entity_id |
159 |
| - ) |
| 171 | + return self._key() == other._key() |
160 | 172 |
|
161 | 173 | def __ne__(self, other):
|
162 | 174 | return not self == other
|
163 | 175 |
|
164 | 176 | def __repr__(self):
|
165 | 177 | return "<AccessEntry: role=%s, %s=%s>" % (
|
166 |
| - self.role, |
167 |
| - self.entity_type, |
168 |
| - self.entity_id, |
| 178 | + self._role, |
| 179 | + self._entity_type, |
| 180 | + self._entity_id, |
169 | 181 | )
|
170 | 182 |
|
| 183 | + def _key(self): |
| 184 | + """ A tuple key that uniquely describes this field. |
| 185 | + Used to compute this instance's hashcode and evaluate equality. |
| 186 | + Returns: |
| 187 | + Tuple: The contents of this :class:`~google.cloud.bigquery.dataset.AccessEntry`. |
| 188 | + """ |
| 189 | + return (self._role, self._entity_type, self._entity_id) |
| 190 | + |
| 191 | + def __hash__(self): |
| 192 | + return hash(self._key()) |
| 193 | + |
171 | 194 | def to_api_repr(self):
|
172 | 195 | """Construct the API resource representation of this access entry
|
173 | 196 |
|
174 | 197 | Returns:
|
175 | 198 | Dict[str, object]: Access entry represented as an API resource
|
176 | 199 | """
|
177 |
| - resource = {self.entity_type: self.entity_id} |
178 |
| - if self.role is not None: |
179 |
| - resource["role"] = self.role |
| 200 | + resource = {self._entity_type: self._entity_id} |
| 201 | + if self._role is not None: |
| 202 | + resource["role"] = self._role |
180 | 203 | return resource
|
181 | 204 |
|
182 | 205 | @classmethod
|
|
0 commit comments