Skip to content

Commit b071e48

Browse files
committed
Rename class: 'dataset.AccessGrant' -> 'dataset.AccessEntry'. (#3798)
* Rename class: 'dataset.AccessGrant' -> 'dataset.AccessEntry'. * PEP8 names for unit test helpers. * Rename 'Dataset.access_grants' -> 'Dataaset.access_entries'.
1 parent 6e81e62 commit b071e48

File tree

3 files changed

+132
-125
lines changed

3 files changed

+132
-125
lines changed

bigquery/google/cloud/bigquery/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@
3030
from google.cloud.bigquery._helpers import ScalarQueryParameter
3131
from google.cloud.bigquery._helpers import StructQueryParameter
3232
from google.cloud.bigquery.client import Client
33-
from google.cloud.bigquery.dataset import AccessGrant
33+
from google.cloud.bigquery.dataset import AccessEntry
3434
from google.cloud.bigquery.dataset import Dataset
3535
from google.cloud.bigquery.schema import SchemaField
3636
from google.cloud.bigquery.table import Table
3737

3838
__all__ = [
39-
'__version__', 'AccessGrant', 'ArrayQueryParameter', 'Client',
40-
'Dataset', 'ScalarQueryParameter', 'SchemaField', 'StructQueryParameter',
39+
'__version__',
40+
'AccessEntry',
41+
'ArrayQueryParameter',
42+
'Client',
43+
'Dataset',
44+
'ScalarQueryParameter',
45+
'SchemaField',
46+
'StructQueryParameter',
4147
'Table',
4248
]

bigquery/google/cloud/bigquery/dataset.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from google.cloud.bigquery.table import Table
2222

2323

24-
class AccessGrant(object):
24+
class AccessEntry(object):
2525
"""Represent grant of an access role to an entity.
2626
2727
Every entry in the access list will have exactly one of
@@ -76,7 +76,7 @@ def __init__(self, role, entity_type, entity_id):
7676
self.entity_id = entity_id
7777

7878
def __eq__(self, other):
79-
if not isinstance(other, AccessGrant):
79+
if not isinstance(other, AccessEntry):
8080
return NotImplemented
8181
return (
8282
self.role == other.role and
@@ -87,7 +87,7 @@ def __ne__(self, other):
8787
return not self == other
8888

8989
def __repr__(self):
90-
return '<AccessGrant: role=%s, %s=%s>' % (
90+
return '<AccessEntry: role=%s, %s=%s>' % (
9191
self.role, self.entity_type, self.entity_id)
9292

9393

@@ -104,22 +104,22 @@ class Dataset(object):
104104
:param client: A client which holds credentials and project configuration
105105
for the dataset (which requires a project).
106106
107-
:type access_grants: list of :class:`AccessGrant`
108-
:param access_grants: roles granted to entities for this dataset
107+
:type access_entries: list of :class:`AccessEntry`
108+
:param access_entries: roles granted to entities for this dataset
109109
110110
:type project: str
111111
:param project: (Optional) project ID for the dataset (defaults to
112112
the project of the client).
113113
"""
114114

115-
_access_grants = None
115+
_access_entries = None
116116

117-
def __init__(self, name, client, access_grants=(), project=None):
117+
def __init__(self, name, client, access_entries=(), project=None):
118118
self.name = name
119119
self._client = client
120120
self._properties = {}
121121
# Let the @property do validation.
122-
self.access_grants = access_grants
122+
self.access_entries = access_entries
123123
self._project = project or client.project
124124

125125
@property
@@ -141,27 +141,27 @@ def path(self):
141141
return '/projects/%s/datasets/%s' % (self.project, self.name)
142142

143143
@property
144-
def access_grants(self):
145-
"""Dataset's access grants.
144+
def access_entries(self):
145+
"""Dataset's access entries.
146146
147-
:rtype: list of :class:`AccessGrant`
147+
:rtype: list of :class:`AccessEntry`
148148
:returns: roles granted to entities for this dataset
149149
"""
150-
return list(self._access_grants)
150+
return list(self._access_entries)
151151

152-
@access_grants.setter
153-
def access_grants(self, value):
154-
"""Update dataset's access grants
152+
@access_entries.setter
153+
def access_entries(self, value):
154+
"""Update dataset's access entries
155155
156-
:type value: list of :class:`AccessGrant`
156+
:type value: list of :class:`AccessEntry`
157157
:param value: roles granted to entities for this dataset
158158
159159
:raises: TypeError if 'value' is not a sequence, or ValueError if
160-
any item in the sequence is not an AccessGrant
160+
any item in the sequence is not an AccessEntry
161161
"""
162-
if not all(isinstance(field, AccessGrant) for field in value):
163-
raise ValueError('Values must be AccessGrant instances')
164-
self._access_grants = tuple(value)
162+
if not all(isinstance(field, AccessEntry) for field in value):
163+
raise ValueError('Values must be AccessEntry instances')
164+
self._access_entries = tuple(value)
165165

166166
@property
167167
def created(self):
@@ -341,29 +341,29 @@ def _require_client(self, client):
341341
return client
342342

343343
@staticmethod
344-
def _parse_access_grants(access):
345-
"""Parse a resource fragment into a set of access grants.
344+
def _parse_access_entries(access):
345+
"""Parse a resource fragment into a set of access entries.
346346
347347
``role`` augments the entity type and present **unless** the entity
348348
type is ``view``.
349349
350350
:type access: list of mappings
351-
:param access: each mapping represents a single access grant.
351+
:param access: each mapping represents a single access entry.
352352
353-
:rtype: list of :class:`AccessGrant`
354-
:returns: a list of parsed grants.
355-
:raises: :class:`ValueError` if a grant in ``access`` has more keys
353+
:rtype: list of :class:`AccessEntry`
354+
:returns: a list of parsed entries.
355+
:raises: :class:`ValueError` if a entry in ``access`` has more keys
356356
than ``role`` and one additional key.
357357
"""
358358
result = []
359-
for grant in access:
360-
grant = grant.copy()
361-
role = grant.pop('role', None)
362-
entity_type, entity_id = grant.popitem()
363-
if len(grant) != 0:
364-
raise ValueError('Grant has unexpected keys remaining.', grant)
359+
for entry in access:
360+
entry = entry.copy()
361+
role = entry.pop('role', None)
362+
entity_type, entity_id = entry.popitem()
363+
if len(entry) != 0:
364+
raise ValueError('Entry has unexpected keys remaining.', entry)
365365
result.append(
366-
AccessGrant(role, entity_type, entity_id))
366+
AccessEntry(role, entity_type, entity_id))
367367
return result
368368

369369
def _set_properties(self, api_response):
@@ -375,7 +375,7 @@ def _set_properties(self, api_response):
375375
self._properties.clear()
376376
cleaned = api_response.copy()
377377
access = cleaned.pop('access', ())
378-
self.access_grants = self._parse_access_grants(access)
378+
self.access_entries = self._parse_access_entries(access)
379379
if 'creationTime' in cleaned:
380380
cleaned['creationTime'] = float(cleaned['creationTime'])
381381
if 'lastModifiedTime' in cleaned:
@@ -386,12 +386,12 @@ def _set_properties(self, api_response):
386386
self._properties.update(cleaned)
387387

388388
def _build_access_resource(self):
389-
"""Generate a resource fragment for dataset's access grants."""
389+
"""Generate a resource fragment for dataset's access entries."""
390390
result = []
391-
for grant in self.access_grants:
392-
info = {grant.entity_type: grant.entity_id}
393-
if grant.role is not None:
394-
info['role'] = grant.role
391+
for entry in self.access_entries:
392+
info = {entry.entity_type: entry.entity_id}
393+
if entry.role is not None:
394+
info['role'] = entry.role
395395
result.append(info)
396396
return result
397397

@@ -414,7 +414,7 @@ def _build_resource(self):
414414
if self.location is not None:
415415
resource['location'] = self.location
416416

417-
if len(self.access_grants) > 0:
417+
if len(self.access_entries) > 0:
418418
resource['access'] = self._build_access_resource()
419419

420420
return resource

0 commit comments

Comments
 (0)