Skip to content

Commit e8f88f2

Browse files
authored
Merge branch 'master' into master
2 parents 4d39586 + 1e5ee87 commit e8f88f2

File tree

74 files changed

+3787
-2616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3787
-2616
lines changed

.kokoro/presubmit_tests_trace.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download secrets from Cloud Storage.
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
5+
6+
# Tell the trampoline which build file to use.
7+
env_vars: {
8+
key: "TRAMPOLINE_BUILD_FILE"
9+
value: "github/python-docs-samples/.kokoro/system_tests.sh"
10+
}
11+
12+
env_vars: {
13+
key: "NOX_SESSION"
14+
value: "trace and py36 and not appengine"
15+
}

.kokoro/system_tests_trace.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Format: //devtools/kokoro/config/proto/build.proto
2+
3+
# Download secrets from Cloud Storage.
4+
gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples"
5+
6+
# Tell the trampoline which build file to use.
7+
env_vars: {
8+
key: "TRAMPOLINE_BUILD_FILE"
9+
value: "github/python-docs-samples/.kokoro/system_tests.sh"
10+
}
11+
12+
env_vars: {
13+
key: "NOX_SESSION"
14+
value: "trace and py36 and not appengine"
15+
}

appengine/flexible/multiple_services/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ and enter `Y` when prompted. Or to skip the check add `-q`.
6363
To deploy multiple services simultaneously just add the path to each `app.yaml`
6464
file as an argument to `gcloud app deploy `:
6565
```Bash
66-
$ gcloud app deploy gateway/app.yaml static/app.yaml
66+
$ gcloud app deploy gateway-service/app.yaml static-service/app.yaml
6767
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
google-endpoints==4.7.0
1+
google-endpoints==4.8.0
22
google-endpoints-api-management==1.11.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
runtime: python37
2+
3+
inbound_services:
4+
- warmup
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2018 Google LLC.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START gae_python37_warmup_app]
16+
from flask import Flask
17+
18+
19+
app = Flask(__name__)
20+
21+
22+
@app.route('/')
23+
def main():
24+
return 'Hello World!'
25+
26+
27+
@app.route('/_ah/warmup')
28+
def warmup():
29+
# Handle your warmup logic here, e.g. set up a database connection pool
30+
return '', 200, {}
31+
32+
33+
if __name__ == '__main__':
34+
# This is used when running locally only. When deploying to Google App
35+
# Engine, a webserver process such as Gunicorn will serve the app. This
36+
# can be configured by adding an `entrypoint` to app.yaml.
37+
app.run(host='127.0.0.1', port=8080, debug=True)
38+
# [END gae_python37_warmup_app]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 Google Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import main
16+
17+
18+
def test_index():
19+
main.app.testing = True
20+
client = main.app.test_client()
21+
22+
r = client.get('/')
23+
assert r.status_code == 200
24+
assert 'Hello World' in r.data.decode('utf-8')
25+
26+
27+
def test_warmup():
28+
main.app.testing = True
29+
client = main.app.test_client()
30+
31+
r = client.get('/')
32+
assert r.status_code == 200
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask==1.0.2

bigquery/cloud-client/user_credentials.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,18 @@
2323
import argparse
2424

2525

26-
def run_query(credentials, project, query):
27-
from google.cloud import bigquery
28-
29-
client = bigquery.Client(project=project, credentials=credentials)
30-
query_job = client.query(query)
31-
32-
# Print the results.
33-
for row in query_job.result(): # Wait for the job to complete.
34-
print(row)
35-
36-
37-
def authenticate_and_query(project, query, launch_browser=True):
26+
def main(project, launch_browser=True):
27+
# [START bigquery_auth_user_flow]
3828
from google_auth_oauthlib import flow
3929

30+
# TODO: Uncomment the line below to set the `launch_browser` variable.
31+
# launch_browser = True
32+
#
33+
# The `launch_browser` boolean variable indicates if a local server is used
34+
# as the callback URL in the auth flow. A value of `True` is recommended,
35+
# but a local server does not work if accessing the application remotely,
36+
# such as over SSH or from a remote Jupyter notebook.
37+
4038
appflow = flow.InstalledAppFlow.from_client_secrets_file(
4139
'client_secrets.json',
4240
scopes=['https://www.googleapis.com/auth/bigquery'])
@@ -46,7 +44,33 @@ def authenticate_and_query(project, query, launch_browser=True):
4644
else:
4745
appflow.run_console()
4846

49-
run_query(appflow.credentials, project, query)
47+
credentials = appflow.credentials
48+
# [END bigquery_auth_user_flow]
49+
50+
# [START bigquery_auth_user_query]
51+
from google.cloud import bigquery
52+
53+
# TODO: Uncomment the line below to set the `project` variable.
54+
# project = 'user-project-id'
55+
#
56+
# The `project` variable defines the project to be billed for query
57+
# processing. The user must have the bigquery.jobs.create permission on
58+
# this project to run a query. See:
59+
# https://cloud.google.com/bigquery/docs/access-control#permissions
60+
61+
client = bigquery.Client(project=project, credentials=credentials)
62+
63+
query_string = """SELECT name, SUM(number) as total
64+
FROM `bigquery-public-data.usa_names.usa_1910_current`
65+
WHERE name = 'William'
66+
GROUP BY name;
67+
"""
68+
query_job = client.query(query_string)
69+
70+
# Print the results.
71+
for row in query_job.result(): # Wait for the job to complete.
72+
print("{}: {}".format(row['name'], row['total']))
73+
# [END bigquery_auth_user_query]
5074

5175

5276
if __name__ == '__main__':
@@ -58,9 +82,8 @@ def authenticate_and_query(project, query, launch_browser=True):
5882
help='Use a local server flow to authenticate. ',
5983
action='store_true')
6084
parser.add_argument('project', help='Project to use for BigQuery billing.')
61-
parser.add_argument('query', help='BigQuery SQL Query.')
6285

6386
args = parser.parse_args()
6487

65-
authenticate_and_query(
66-
args.project, args.query, launch_browser=args.launch_browser)
88+
main(
89+
args.project, launch_browser=args.launch_browser)

bigquery/cloud-client/user_credentials_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import mock
1919
import pytest
2020

21-
from user_credentials import authenticate_and_query
21+
from user_credentials import main
2222

2323

2424
PROJECT = os.environ['GCLOUD_PROJECT']
@@ -36,6 +36,7 @@ def mock_flow():
3636

3737

3838
def test_auth_query_console(mock_flow, capsys):
39-
authenticate_and_query(PROJECT, 'SELECT 1+1;', launch_browser=False)
39+
main(PROJECT, launch_browser=False)
4040
out, _ = capsys.readouterr()
41-
assert '2' in out
41+
# Fun fact: William P. Wood was the 1st director of the US Secret Service.
42+
assert 'William' in out

0 commit comments

Comments
 (0)