Skip to content

Commit 3499e9b

Browse files
dschallermattklein123
authored andcommitted
format all python files in envoy (envoyproxy#5422)
Signed-off-by: Derek Schaller <[email protected]>
1 parent 5e82130 commit 3499e9b

34 files changed

+2057
-1930
lines changed

api/tools/capture2pcap.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@ def DumpEvent(direction, timestamp, data):
3434
dump = StringIO.StringIO()
3535
dump.write('%s\n' % direction)
3636
# Adjust to local timezone
37-
adjusted_dt = timestamp.ToDatetime() - datetime.timedelta(
38-
seconds=time.altzone)
37+
adjusted_dt = timestamp.ToDatetime() - datetime.timedelta(seconds=time.altzone)
3938
dump.write('%s\n' % adjusted_dt)
40-
od = sp.Popen(
41-
['od', '-Ax', '-tx1', '-v'],
42-
stdout=sp.PIPE,
43-
stdin=sp.PIPE,
44-
stderr=sp.PIPE)
39+
od = sp.Popen(['od', '-Ax', '-tx1', '-v'], stdout=sp.PIPE, stdin=sp.PIPE, stderr=sp.PIPE)
4540
packet_dump = od.communicate(data)[0]
4641
dump.write(packet_dump)
4742
return dump.getvalue()

api/tools/capture2pcap_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
pcap_path = os.path.join(os.getenv('TEST_TMPDIR'), 'generated.pcap')
1717

1818
capture2pcap.Capture2Pcap(capture_path, pcap_path)
19-
actual_output = sp.check_output(
20-
['tshark', '-r', pcap_path, '-d', 'tcp.port==10000,http2', '-P'])
19+
actual_output = sp.check_output(['tshark', '-r', pcap_path, '-d', 'tcp.port==10000,http2', '-P'])
2120
with open(expected_path, 'r') as f:
2221
expected_output = f.read()
2322
if actual_output != expected_output:

api/tools/generate_listeners.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ def ProtoToStruct(proto):
3232
def ParseProto(path, filter_name):
3333
# We only know about some filter config protos ahead of time.
3434
KNOWN_FILTERS = {
35-
'http_connection_manager':
36-
lambda: http_connection_manager_pb2.HttpConnectionManager()
35+
'http_connection_manager': lambda: http_connection_manager_pb2.HttpConnectionManager()
3736
}
3837
filter_config = KNOWN_FILTERS[filter_name]()
3938
with open(path, 'r') as f:
4039
text_format.Merge(f.read(), filter_config)
4140
return filter_config
4241

4342

44-
def GenerateListeners(listeners_pb_path, output_pb_path, output_json_path,
45-
fragments):
43+
def GenerateListeners(listeners_pb_path, output_pb_path, output_json_path, fragments):
4644
listener = lds_pb2.Listener()
4745
with open(listeners_pb_path, 'r') as f:
4846
text_format.Merge(f.read(), listener)

api/tools/generate_listeners_test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@
77
if __name__ == "__main__":
88
srcdir = os.path.join(os.getenv("TEST_SRCDIR"), 'envoy_api')
99
generate_listeners.GenerateListeners(
10-
os.path.join(srcdir, "examples/service_envoy/listeners.pb"),
11-
"/dev/stdout", "/dev/stdout",
12-
iter([
13-
os.path.join(srcdir,
14-
"examples/service_envoy/http_connection_manager.pb")
15-
]))
10+
os.path.join(srcdir, "examples/service_envoy/listeners.pb"), "/dev/stdout", "/dev/stdout",
11+
iter([os.path.join(srcdir, "examples/service_envoy/http_connection_manager.pb")]))

bazel/cc_wrapper.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def main():
3434
# https://github.com/bazelbuild/bazel/issues/4572
3535
# https://bazel-review.googlesource.com/c/bazel/+/39951
3636
if sys.argv[1:] == ["-E", "-xc++", "-", "-v"] and "clang" in compiler:
37-
os.execv(envoy_real_cxx,
38-
[envoy_real_cxx, "-E", "-", "-v", "-no-canonical-prefixes"])
37+
os.execv(envoy_real_cxx, [envoy_real_cxx, "-E", "-", "-v", "-no-canonical-prefixes"])
3938

4039
# `g++` and `gcc -lstdc++` have similar behavior and Bazel treats them as
4140
# interchangeable, but `gcc` will ignore the `-static-libstdc++` flag.
@@ -55,8 +54,7 @@ def main():
5554
# unless the user has explicitly set environment variables
5655
# before starting Bazel. But here in $PWD is the Bazel sandbox,
5756
# which will be deleted automatically after the compiler exits.
58-
(flagfile_fd, flagfile_path) = tempfile.mkstemp(
59-
dir='./', suffix=".linker-params")
57+
(flagfile_fd, flagfile_path) = tempfile.mkstemp(dir='./', suffix=".linker-params")
6058
with closing_fd(flagfile_fd):
6159
sanitize_flagfile(arg[len("-Wl,@"):], flagfile_fd)
6260
argv.append("-Wl,@" + flagfile_path)

bazel/git_repository_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
print 'Unknown repository: %s' % repo
1818
sys.exit(1)
1919
repoloc = repolocs.REPOSITORY_LOCATIONS[repo]
20-
print '%s %s' % (repoloc['remote'], repoloc['commit'])
20+
print '%s %s' % (repoloc['remote'], repoloc['commit'])

configs/configgen.py

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@
2222
# in envoy_router.template.json must be specified here. It is a dictionary of dictionaries.
2323
# Options can be specified for each cluster if needed. See make_route_internal() in
2424
# routing_helper.template.json for the types of options supported.
25-
front_envoy_clusters = {
26-
'service1': {},
27-
'service2': {},
28-
'service3': {},
29-
'ratelimit': {}
30-
}
25+
front_envoy_clusters = {'service1': {}, 'service2': {}, 'service3': {}, 'ratelimit': {}}
3126

3227
# This is the set of internal services that local Envoys will route to. All services that will be
3328
# accessed via the 9001 egress port need to be listed here. It is a dictionary of dictionaries.
@@ -46,24 +41,28 @@
4641
# we demonstrate setting up proxying for DynamoDB. In the config, this ends up using the HTTP
4742
# DynamoDB statistics filter, as well as generating a special access log which includes the
4843
# X-AMZN-RequestId response header.
49-
external_virtual_hosts = [
50-
{
51-
'name': 'dynamodb_iad',
52-
'address': "127.0.0.1",
53-
'protocol':"TCP",
54-
'port_value':"9204",
55-
'hosts': [
56-
{
57-
'name': 'dynamodb_iad', 'domain': '*',
58-
'remote_address': 'dynamodb.us-east-1.amazonaws.com',
59-
'protocol': 'TCP',
60-
'port_value': '443',
61-
'verify_subject_alt_name': [ 'dynamodb.us-east-1.amazonaws.com' ],
62-
'ssl': True
63-
}
64-
],
65-
'is_amzn_service': True,
66-
'cluster_type': 'logical_dns'
44+
external_virtual_hosts = [{
45+
'name':
46+
'dynamodb_iad',
47+
'address':
48+
"127.0.0.1",
49+
'protocol':
50+
"TCP",
51+
'port_value':
52+
"9204",
53+
'hosts': [{
54+
'name': 'dynamodb_iad',
55+
'domain': '*',
56+
'remote_address': 'dynamodb.us-east-1.amazonaws.com',
57+
'protocol': 'TCP',
58+
'port_value': '443',
59+
'verify_subject_alt_name': ['dynamodb.us-east-1.amazonaws.com'],
60+
'ssl': True
61+
}],
62+
'is_amzn_service':
63+
True,
64+
'cluster_type':
65+
'logical_dns'
6766
}]
6867

6968
# This is the set of mongo clusters that local Envoys can talk to. Each database defines a set of
@@ -73,31 +72,57 @@
7372
# as it demonstrates how to setup TCP proxy and the network rate limit filter.
7473
mongos_servers = {
7574
'somedb': {
76-
'address': "127.0.0.1",
77-
'protocol': "TCP",
78-
'port_value': 27019,
75+
'address':
76+
"127.0.0.1",
77+
'protocol':
78+
"TCP",
79+
'port_value':
80+
27019,
7981
'hosts': [
80-
{'port_value' : 27817, 'address':'router1.yourcompany.net' , 'protocol': 'TCP'},
81-
{'port_value' : 27817, 'address':'router2.yourcompany.net' , 'protocol': 'TCP'},
82-
{'port_value' : 27817, 'address':'router3.yourcompany.net' , 'protocol': 'TCP'},
83-
{'port_value' : 27817, 'address':'router4.yourcompany.net' , 'protocol': 'TCP'},
82+
{
83+
'port_value': 27817,
84+
'address': 'router1.yourcompany.net',
85+
'protocol': 'TCP'
86+
},
87+
{
88+
'port_value': 27817,
89+
'address': 'router2.yourcompany.net',
90+
'protocol': 'TCP'
91+
},
92+
{
93+
'port_value': 27817,
94+
'address': 'router3.yourcompany.net',
95+
'protocol': 'TCP'
96+
},
97+
{
98+
'port_value': 27817,
99+
'address': 'router4.yourcompany.net',
100+
'protocol': 'TCP'
101+
},
84102
],
85-
'ratelimit': True
103+
'ratelimit':
104+
True
86105
}
87106
}
88107

108+
89109
def generate_config(template_path, template, output_file, **context):
90-
""" Generate a final config file based on a template and some context. """
91-
env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path, followlinks=True),
92-
undefined=jinja2.StrictUndefined)
93-
raw_output = env.get_template(template).render(**context)
94-
with open(output_file, 'w') as fh:
95-
fh.write(raw_output)
110+
""" Generate a final config file based on a template and some context. """
111+
env = jinja2.Environment(
112+
loader=jinja2.FileSystemLoader(template_path, followlinks=True),
113+
undefined=jinja2.StrictUndefined)
114+
raw_output = env.get_template(template).render(**context)
115+
with open(output_file, 'w') as fh:
116+
fh.write(raw_output)
117+
96118

97119
# Generate a demo config for the main front proxy. This sets up both HTTP and HTTPS listeners,
98120
# as well as a listener for the double proxy to connect to via SSL client authentication.
99-
generate_config(SCRIPT_DIR, 'envoy_front_proxy_v2.template.yaml',
100-
'{}/envoy_front_proxy.v2.yaml'.format(OUT_DIR), clusters=front_envoy_clusters)
121+
generate_config(
122+
SCRIPT_DIR,
123+
'envoy_front_proxy_v2.template.yaml',
124+
'{}/envoy_front_proxy.v2.yaml'.format(OUT_DIR),
125+
clusters=front_envoy_clusters)
101126

102127
# Generate a demo config for the double proxy. This sets up both an HTTP and HTTPS listeners,
103128
# and backhauls the traffic to the main front proxy.
@@ -112,11 +137,13 @@ def generate_config(template_path, template, output_file, **context):
112137
# optional external service ports: built from external_virtual_hosts above. Each external host
113138
# that Envoy proxies to listens on its own port.
114139
# optional mongo ports: built from mongos_servers above.
115-
generate_config(SCRIPT_DIR, 'envoy_service_to_service_v2.template.yaml',
116-
'{}/envoy_service_to_service.yaml'.format(OUT_DIR),
117-
internal_virtual_hosts=service_to_service_envoy_clusters,
118-
external_virtual_hosts=external_virtual_hosts,
119-
mongos_servers=mongos_servers)
140+
generate_config(
141+
SCRIPT_DIR,
142+
'envoy_service_to_service_v2.template.yaml',
143+
'{}/envoy_service_to_service.yaml'.format(OUT_DIR),
144+
internal_virtual_hosts=service_to_service_envoy_clusters,
145+
external_virtual_hosts=external_virtual_hosts,
146+
mongos_servers=mongos_servers)
120147

121148
for google_ext in ['v2.yaml']:
122149
shutil.copy(os.path.join(SCRIPT_DIR, 'google_com_proxy.%s' % google_ext), OUT_DIR)

docs/conf.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
import sys
1717
import os
1818

19+
1920
def setup(app):
2021
app.add_config_value('release_level', '', 'env')
2122

23+
2224
if not os.environ.get('ENVOY_DOCS_RELEASE_LEVEL'):
2325
raise Exception("ENVOY_DOCS_RELEASE_LEVEL env var must be defined")
2426

@@ -39,8 +41,8 @@ def setup(app):
3941
# ones.
4042
extensions = ['sphinxcontrib.httpdomain', 'sphinx.ext.extlinks', 'sphinx.ext.ifconfig']
4143
extlinks = {
42-
'repo': ('https://github.com/envoyproxy/envoy/blob/master/%s', ''),
43-
'api': ('https://github.com/envoyproxy/envoy/blob/master/api/%s', ''),
44+
'repo': ('https://github.com/envoyproxy/envoy/blob/master/%s', ''),
45+
'api': ('https://github.com/envoyproxy/envoy/blob/master/api/%s', ''),
4446
}
4547

4648
# Add any paths that contain templates here, relative to this directory.
@@ -119,7 +121,6 @@ def setup(app):
119121
# If true, `todo` and `todoList` produce output, else they produce nothing.
120122
todo_include_todos = False
121123

122-
123124
# -- Options for HTML output ----------------------------------------------
124125

125126
# The theme to use for HTML and HTML Help pages. See the documentation for

examples/cors/backend/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
@app.route('/cors/<status>')
88
def cors_enabled(status):
9-
return 'Success!'
9+
return 'Success!'
1010

1111

1212
if __name__ == "__main__":
13-
app.run(host='127.0.0.1', port=8080, debug=True)
13+
app.run(host='127.0.0.1', port=8080, debug=True)

examples/cors/frontend/service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
@app.route('/')
88
def index():
9-
file_dir = os.path.dirname(os.path.realpath(__file__))
10-
return send_from_directory(file_dir, 'index.html')
9+
file_dir = os.path.dirname(os.path.realpath(__file__))
10+
return send_from_directory(file_dir, 'index.html')
1111

1212

1313
if __name__ == "__main__":
14-
app.run(host='127.0.0.1', port=8080, debug=True)
14+
app.run(host='127.0.0.1', port=8080, debug=True)

0 commit comments

Comments
 (0)