Skip to content

Commit 9bd23b3

Browse files
authored
Merge branch 'master' into warn-to-warning
2 parents df50bca + cdab25b commit 9bd23b3

File tree

74 files changed

+6432
-109
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

+6432
-109
lines changed

appengine/flexible/analytics/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def track_event(category, action, label=None, value=0):
4242
}
4343

4444
response = requests.post(
45-
'http://www.google-analytics.com/collect', data=data)
45+
'https://www.google-analytics.com/collect', data=data)
4646

4747
# If the request fails, this will raise a RequestException. Depending
4848
# on your application's needs, this may be a non-error and can be caught

appengine/standard/analytics/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def track_event(category, action, label=None, value=0):
4545
}
4646

4747
response = requests.post(
48-
'http://www.google-analytics.com/collect', data=data)
48+
'https://www.google-analytics.com/collect', data=data)
4949

5050
# If the request fails, this will raise a RequestException. Depending
5151
# on your application's needs, this may be a non-error and can be caught

appengine/standard_python37/cloudsql/app.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
runtime: python37
33

44
env_variables:
5-
CLOUDSQL_USERNAME: YOUR-USERNAME
6-
CLOUDSQL_PASSWORD: YOUR-PASSWORD
7-
CLOUDSQL_DATABASE_NAME: YOUR-DATABASE
8-
CLOUDSQL_CONNECTION_NAME: YOUR-CONNECTION-NAME
5+
CLOUD_SQL_USERNAME: YOUR-USERNAME
6+
CLOUD_SQL_PASSWORD: YOUR-PASSWORD
7+
CLOUD_SQL_DATABASE_NAME: YOUR-DATABASE
8+
CLOUD_SQL_CONNECTION_NAME: YOUR-CONNECTION-NAME
99
# [END gae_python37_cloudsql_config]

appengine/standard_python37/cloudsql/main_mysql.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,18 @@ def main():
3232
# set to `standard`
3333
if os.environ.get('GAE_ENV') == 'standard':
3434
# If deployed, use the local socket interface for accessing Cloud SQL
35-
host = '/cloudsql/{}'.format(db_connection_name)
35+
unix_socket = '/cloudsql/{}'.format(db_connection_name)
36+
cnx = pymysql.connect(user=db_user, password=db_password,
37+
unix_socket=unix_socket, db=db_name)
3638
else:
3739
# If running locally, use the TCP connections instead
3840
# Set up Cloud SQL Proxy (cloud.google.com/sql/docs/mysql/sql-proxy)
3941
# so that your application can use 127.0.0.1:3306 to connect to your
4042
# Cloud SQL instance
4143
host = '127.0.0.1'
44+
cnx = pymysql.connect(user=db_user, password=db_password,
45+
host=host, db=db_name)
4246

43-
cnx = pymysql.connect(user=db_user, password=db_password,
44-
host=host, db=db_name)
4547
with cnx.cursor() as cursor:
4648
cursor.execute('SELECT NOW() as now;')
4749
result = cursor.fetchall()

appengine/standard_python37/cloudsql/main_mysql_pooling.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
# set to `standard`
2828
if os.environ.get('GAE_ENV') == 'standard':
2929
# If deployed, use the local socket interface for accessing Cloud SQL
30-
host = '/cloudsql/{}'.format(db_connection_name)
30+
unix_socket = '/cloudsql/{}'.format(db_connection_name)
31+
engine_url = 'mysql+pymysql://{}:{}@/{}?unix_socket={}'.format(
32+
db_user, db_password, db_name, unix_socket)
3133
else:
3234
# If running locally, use the TCP connections instead
3335
# Set up Cloud SQL Proxy (cloud.google.com/sql/docs/mysql/sql-proxy)
3436
# so that your application can use 127.0.0.1:3306 to connect to your
3537
# Cloud SQL instance
3638
host = '127.0.0.1'
39+
engine_url = 'mysql+pymysql://{}:{}@{}/{}'.format(
40+
db_user, db_password, host, db_name)
3741

3842
# The Engine object returned by create_engine() has a QueuePool integrated
3943
# See https://docs.sqlalchemy.org/en/latest/core/pooling.html for more
4044
# information
41-
engine = sqlalchemy.create_engine('mysql+pymysql://{}:{}@{}/{}'.format(
42-
db_user, db_password, host, db_name
43-
), pool_size=3)
45+
engine = sqlalchemy.create_engine(engine_url, pool_size=3)
4446

4547
app = Flask(__name__)
4648

appengine/standard_python37/cloudsql/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
flask==1.0.2
12
psycopg2==2.7.5
23
psycopg2-binary==2.7.5
34
PyMySQL==0.9.2
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
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+
# http://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+
18+
import argparse
19+
20+
21+
def export_assets(project_id, dump_file_path):
22+
# [START asset_quickstart_exportassets]
23+
from google.cloud import asset_v1beta1
24+
from google.cloud.asset_v1beta1.proto import asset_service_pb2
25+
26+
# TODO project_id = 'Your Google Cloud Project ID'
27+
# TODO dump_file_path = 'Your asset dump file path'
28+
29+
client = asset_v1beta1.AssetServiceClient()
30+
parent = client.project_path(project_id)
31+
output_config = asset_service_pb2.OutputConfig()
32+
output_config.gcs_destination.uri = dump_file_path
33+
response = client.export_assets(parent, output_config)
34+
print(response.result())
35+
# [END asset_quickstart_exportassets]
36+
37+
38+
if __name__ == '__main__':
39+
40+
parser = argparse.ArgumentParser(
41+
description=__doc__,
42+
formatter_class=argparse.RawDescriptionHelpFormatter
43+
)
44+
parser.add_argument('project_id', help='Your Google Cloud project ID')
45+
parser.add_argument(
46+
'dump_file_path',
47+
help='The file ExportAssets API will dump assets to, '
48+
'e.g.: gs://<bucket-name>/asset_dump_file')
49+
50+
args = parser.parse_args()
51+
52+
export_assets(args.project_id, args.dump_file_path)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2018 Google LLC. All Rights Reserved.
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+
# http://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 os
18+
import time
19+
20+
from google.cloud import storage
21+
import pytest
22+
23+
import quickstart_exportassets
24+
25+
PROJECT = os.environ['GCLOUD_PROJECT']
26+
BUCKET = 'assets-{}'.format(int(time.time()))
27+
28+
29+
@pytest.fixture(scope='module')
30+
def storage_client():
31+
yield storage.Client()
32+
33+
34+
@pytest.fixture(scope='module')
35+
def asset_bucket(storage_client):
36+
bucket = storage_client.create_bucket(BUCKET)
37+
38+
yield BUCKET
39+
40+
try:
41+
bucket.delete(force=True)
42+
except Exception as e:
43+
print('Failed to delete bucket{}'.format(BUCKET))
44+
raise e
45+
46+
47+
def test_export_assets(asset_bucket, capsys):
48+
dump_file_path = 'gs://{}/assets-dump.txt'.format(asset_bucket)
49+
quickstart_exportassets.export_assets(PROJECT, dump_file_path)
50+
out, _ = capsys.readouterr()
51+
52+
assert dump_file_path in out

asset/cloud-client/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google-cloud-storage==1.13.0
2+
google-cloud-asset==0.1.1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# pandas-gbq Migration Guide
2+
3+
This directory contains samples used in the `pandas-gbq` to
4+
`google-cloud-bigquery` migration guide.

0 commit comments

Comments
 (0)