@@ -79,38 +79,47 @@ class AccessEntry(object):
7979 """Represents grant of an access role to an entity.
8080
8181 An entry must have exactly one of the allowed :attr:`ENTITY_TYPES`. If
82- anything but ``view`` is set, a ``role`` is also required. ``role`` is
83- omitted for a ``view``, because ``view`` s are always read-only.
82+ anything but ``view`` or ``routine`` are set, a ``role`` is also required.
83+ ``role`` is omitted for ``view`` and ``routine``, because they are always
84+ read-only.
8485
8586 See https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets.
8687
8788 Args:
8889 role (str):
8990 Role granted to the entity. The following string values are
9091 supported: `'READER'`, `'WRITER'`, `'OWNER'`. It may also be
91- :data:`None` if the ``entity_type`` is ``view``.
92+ :data:`None` if the ``entity_type`` is ``view`` or ``routine`` .
9293
9394 entity_type (str):
9495 Type of entity being granted the role. One of :attr:`ENTITY_TYPES`.
9596
9697 entity_id (Union[str, Dict[str, str]]):
97- If the ``entity_type`` is not 'view', the ``entity_id`` is the
98- ``str`` ID of the entity being granted the role. If the
99- ``entity_type`` is 'view', the ``entity_id`` is a ``dict``
100- representing the view from a different dataset to grant access to
101- in the following format::
98+ If the ``entity_type`` is not 'view' or 'routine' , the ``entity_id``
99+ is the ``str`` ID of the entity being granted the role. If the
100+ ``entity_type`` is 'view' or 'routine' , the ``entity_id`` is a ``dict``
101+ representing the view or routine from a different dataset to grant
102+ access to in the following format for views ::
102103
103104 {
104105 'projectId': string,
105106 'datasetId': string,
106107 'tableId': string
107108 }
108109
110+ For routines::
111+
112+ {
113+ 'projectId': string,
114+ 'datasetId': string,
115+ 'routineId': string
116+ }
117+
109118 Raises:
110119 ValueError:
111120 If the ``entity_type`` is not among :attr:`ENTITY_TYPES`, or if a
112- ``view`` has ``role`` set, or a non ``view`` **does not** have a
113- ``role`` set.
121+ ``view`` or a ``routine`` has ``role`` set, or a non ``view`` and
122+ non ``routine`` **does not** have a ``role`` set.
114123
115124 Examples:
116125 >>> entry = AccessEntry('OWNER', 'userByEmail', '[email protected] ') @@ -124,7 +133,15 @@ class AccessEntry(object):
124133 """
125134
126135 ENTITY_TYPES = frozenset (
127- ["userByEmail" , "groupByEmail" , "domain" , "specialGroup" , "view" , "iamMember" ]
136+ [
137+ "userByEmail" ,
138+ "groupByEmail" ,
139+ "domain" ,
140+ "specialGroup" ,
141+ "view" ,
142+ "iamMember" ,
143+ "routine" ,
144+ ]
128145 )
129146 """Allowed entity types."""
130147
@@ -135,10 +152,11 @@ def __init__(self, role, entity_type, entity_id):
135152 ", " .join (self .ENTITY_TYPES ),
136153 )
137154 raise ValueError (message )
138- if entity_type == "view" :
155+ if entity_type in ( "view" , "routine" ) :
139156 if role is not None :
140157 raise ValueError (
141- "Role must be None for a view. Received " "role: %r" % (role ,)
158+ "Role must be None for a %r. Received "
159+ "role: %r" % (entity_type , role )
142160 )
143161 else :
144162 if role is None :
@@ -409,7 +427,7 @@ def access_entries(self):
409427 entries.
410428
411429 ``role`` augments the entity type and must be present **unless** the
412- entity type is ``view``.
430+ entity type is ``view`` or ``routine`` .
413431
414432 Raises:
415433 TypeError: If 'value' is not a sequence
0 commit comments