Skip to content

Commit 1841c7a

Browse files
authored
Spanner: add 'synth.py' for the three protos and regen (#6040)
1 parent e551423 commit 1841c7a

37 files changed

+3174
-2814
lines changed

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ setuptools >= 36.4.0
22
sphinx >= 1.6.3
33
ipython >= 4
44
recommonmark >= 0.4.0
5+
grpcio-gcp >= 0.2.2
56

67
-e api_core/
78
-e core/

spanner/google/cloud/spanner_admin_database_v1/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright 2017 Google LLC
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
46
# you may not use this file except in compliance with the License.

spanner/google/cloud/spanner_admin_database_v1/gapic/database_admin_client.py

Lines changed: 229 additions & 108 deletions
Large diffs are not rendered by default.

spanner/google/cloud/spanner_admin_database_v1/gapic/enums.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Copyright 2017 Google LLC
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
46
# you may not use this file except in compliance with the License.
@@ -13,9 +15,11 @@
1315
# limitations under the License.
1416
"""Wrappers for protocol buffer enum types."""
1517

18+
import enum
19+
1620

1721
class Database(object):
18-
class State(object):
22+
class State(enum.IntEnum):
1923
"""
2024
Indicates the current state of the database.
2125

spanner/google/cloud/spanner_admin_database_v1/gapic/transports/__init__.py

Whitespace-only changes.
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import google.api_core.grpc_helpers
18+
import google.api_core.operations_v1
19+
20+
from google.cloud.spanner_admin_database_v1.proto import spanner_database_admin_pb2_grpc
21+
22+
23+
class DatabaseAdminGrpcTransport(object):
24+
"""gRPC transport class providing stubs for
25+
google.spanner.admin.database.v1 DatabaseAdmin API.
26+
27+
The transport provides access to the raw gRPC stubs,
28+
which can be used to take advantage of advanced
29+
features of gRPC.
30+
"""
31+
# The scopes needed to make gRPC calls to all of the methods defined
32+
# in this service.
33+
_OAUTH_SCOPES = (
34+
'https://www.googleapis.com/auth/cloud-platform',
35+
'https://www.googleapis.com/auth/spanner.admin',
36+
)
37+
38+
def __init__(self,
39+
channel=None,
40+
credentials=None,
41+
address='spanner.googleapis.com:443'):
42+
"""Instantiate the transport class.
43+
44+
Args:
45+
channel (grpc.Channel): A ``Channel`` instance through
46+
which to make calls. This argument is mutually exclusive
47+
with ``credentials``; providing both will raise an exception.
48+
credentials (google.auth.credentials.Credentials): The
49+
authorization credentials to attach to requests. These
50+
credentials identify this application to the service. If none
51+
are specified, the client will attempt to ascertain the
52+
credentials from the environment.
53+
address (str): The address where the service is hosted.
54+
"""
55+
# If both `channel` and `credentials` are specified, raise an
56+
# exception (channels come with credentials baked in already).
57+
if channel is not None and credentials is not None:
58+
raise ValueError(
59+
'The `channel` and `credentials` arguments are mutually '
60+
'exclusive.', )
61+
62+
# Create the channel.
63+
if channel is None:
64+
channel = self.create_channel(
65+
address=address,
66+
credentials=credentials,
67+
)
68+
69+
# gRPC uses objects called "stubs" that are bound to the
70+
# channel and provide a basic method for each RPC.
71+
self._stubs = {
72+
'database_admin_stub':
73+
spanner_database_admin_pb2_grpc.DatabaseAdminStub(channel),
74+
}
75+
76+
# Because this API includes a method that returns a
77+
# long-running operation (proto: google.longrunning.Operation),
78+
# instantiate an LRO client.
79+
self._operations_client = google.api_core.operations_v1.OperationsClient(
80+
channel)
81+
82+
@classmethod
83+
def create_channel(cls,
84+
address='spanner.googleapis.com:443',
85+
credentials=None):
86+
"""Create and return a gRPC channel object.
87+
88+
Args:
89+
address (str): The host for the channel to use.
90+
credentials (~.Credentials): The
91+
authorization credentials to attach to requests. These
92+
credentials identify this application to the service. If
93+
none are specified, the client will attempt to ascertain
94+
the credentials from the environment.
95+
96+
Returns:
97+
grpc.Channel: A gRPC channel object.
98+
"""
99+
return google.api_core.grpc_helpers.create_channel(
100+
address,
101+
credentials=credentials,
102+
scopes=cls._OAUTH_SCOPES,
103+
)
104+
105+
@property
106+
def list_databases(self):
107+
"""Return the gRPC stub for {$apiMethod.name}.
108+
109+
Lists Cloud Spanner databases.
110+
111+
Returns:
112+
Callable: A callable which accepts the appropriate
113+
deserialized request object and returns a
114+
deserialized response object.
115+
"""
116+
return self._stubs['database_admin_stub'].ListDatabases
117+
118+
@property
119+
def create_database(self):
120+
"""Return the gRPC stub for {$apiMethod.name}.
121+
122+
Creates a new Cloud Spanner database and starts to prepare it for serving.
123+
The returned ``long-running operation`` will
124+
have a name of the format ``<database_name>/operations/<operation_id>`` and
125+
can be used to track preparation of the database. The
126+
``metadata`` field type is
127+
``CreateDatabaseMetadata``. The
128+
``response`` field type is
129+
``Database``, if successful.
130+
131+
Returns:
132+
Callable: A callable which accepts the appropriate
133+
deserialized request object and returns a
134+
deserialized response object.
135+
"""
136+
return self._stubs['database_admin_stub'].CreateDatabase
137+
138+
@property
139+
def get_database(self):
140+
"""Return the gRPC stub for {$apiMethod.name}.
141+
142+
Gets the state of a Cloud Spanner database.
143+
144+
Returns:
145+
Callable: A callable which accepts the appropriate
146+
deserialized request object and returns a
147+
deserialized response object.
148+
"""
149+
return self._stubs['database_admin_stub'].GetDatabase
150+
151+
@property
152+
def update_database_ddl(self):
153+
"""Return the gRPC stub for {$apiMethod.name}.
154+
155+
Updates the schema of a Cloud Spanner database by
156+
creating/altering/dropping tables, columns, indexes, etc. The returned
157+
``long-running operation`` will have a name of
158+
the format ``<database_name>/operations/<operation_id>`` and can be used to
159+
track execution of the schema change(s). The
160+
``metadata`` field type is
161+
``UpdateDatabaseDdlMetadata``. The operation has no response.
162+
163+
Returns:
164+
Callable: A callable which accepts the appropriate
165+
deserialized request object and returns a
166+
deserialized response object.
167+
"""
168+
return self._stubs['database_admin_stub'].UpdateDatabaseDdl
169+
170+
@property
171+
def drop_database(self):
172+
"""Return the gRPC stub for {$apiMethod.name}.
173+
174+
Drops (aka deletes) a Cloud Spanner database.
175+
176+
Returns:
177+
Callable: A callable which accepts the appropriate
178+
deserialized request object and returns a
179+
deserialized response object.
180+
"""
181+
return self._stubs['database_admin_stub'].DropDatabase
182+
183+
@property
184+
def get_database_ddl(self):
185+
"""Return the gRPC stub for {$apiMethod.name}.
186+
187+
Returns the schema of a Cloud Spanner database as a list of formatted
188+
DDL statements. This method does not show pending schema updates, those may
189+
be queried using the ``Operations`` API.
190+
191+
Returns:
192+
Callable: A callable which accepts the appropriate
193+
deserialized request object and returns a
194+
deserialized response object.
195+
"""
196+
return self._stubs['database_admin_stub'].GetDatabaseDdl
197+
198+
@property
199+
def set_iam_policy(self):
200+
"""Return the gRPC stub for {$apiMethod.name}.
201+
202+
Sets the access control policy on a database resource. Replaces any
203+
existing policy.
204+
205+
Authorization requires ``spanner.databases.setIamPolicy`` permission on
206+
``resource``.
207+
208+
Returns:
209+
Callable: A callable which accepts the appropriate
210+
deserialized request object and returns a
211+
deserialized response object.
212+
"""
213+
return self._stubs['database_admin_stub'].SetIamPolicy
214+
215+
@property
216+
def get_iam_policy(self):
217+
"""Return the gRPC stub for {$apiMethod.name}.
218+
219+
Gets the access control policy for a database resource. Returns an empty
220+
policy if a database exists but does not have a policy set.
221+
222+
Authorization requires ``spanner.databases.getIamPolicy`` permission on
223+
``resource``.
224+
225+
Returns:
226+
Callable: A callable which accepts the appropriate
227+
deserialized request object and returns a
228+
deserialized response object.
229+
"""
230+
return self._stubs['database_admin_stub'].GetIamPolicy
231+
232+
@property
233+
def test_iam_permissions(self):
234+
"""Return the gRPC stub for {$apiMethod.name}.
235+
236+
Returns permissions that the caller has on the specified database resource.
237+
238+
Attempting this RPC on a non-existent Cloud Spanner database will result in
239+
a NOT_FOUND error if the user has ``spanner.databases.list`` permission on
240+
the containing Cloud Spanner instance. Otherwise returns an empty set of
241+
permissions.
242+
243+
Returns:
244+
Callable: A callable which accepts the appropriate
245+
deserialized request object and returns a
246+
deserialized response object.
247+
"""
248+
return self._stubs['database_admin_stub'].TestIamPermissions

0 commit comments

Comments
 (0)