Skip to content

Commit da05647

Browse files
authored
Merge pull request #13 from f5devcentral/main
dev take2
2 parents 787693b + 009f874 commit da05647

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

cloudapp/app/app.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def return_err(err):
2121
'error': err.description
2222
}
2323

24+
@app.route('/', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
2425
@app.route('/raw', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
2526
def echo():
2627
"""
@@ -35,20 +36,27 @@ def echo():
3536
print(e)
3637
response = {
3738
'request_headers': headers,
38-
'request_env': app.config['site']
39+
'env': app.config['site'],
40+
'info': {
41+
'method': request.method,
42+
'url': request.url,
43+
'path': request.path,
44+
'full_path': request.full_path
45+
}
3946
}
4047
if data:
4148
response['request_data'] = data
4249
return jsonify(response)
4350

51+
@app.route('/<env>/', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
4452
@app.route('/<env>/raw', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
4553
def env_echo(env):
4654
if env.lower() == app.config['site'].lower():
4755
return echo()
4856
return jsonify({'error': 'Invalid environment'})
4957

50-
@app.route('/', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
51-
@app.route('/echo', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
58+
@app.route('/pretty', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
59+
@app.route('/pretty_echo', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
5260
def echo_html():
5361
""" Same as /raw, just prettier"""
5462
headers = dict(request.headers)
@@ -62,7 +70,13 @@ def echo_html():
6270
data = request.form.to_dict()
6371
except Exception:
6472
pass
65-
return render_template('pretty_echo.html', request_env=app.config['site'], request_headers=headers, request_data=data)
73+
info = {
74+
'method': request.method,
75+
'url': request.url,
76+
'path': request.path,
77+
'full_path': request.full_path
78+
}
79+
return render_template('pretty_echo.html', request_env=app.config['site'], info=info, request_headers=headers, request_data=data)
6680

6781
return app
6882

cloudapp/app/templates/pretty_echo.html

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ <h1 class="mt-5">
4949
&nbsp{{ request_env }}
5050
</div>
5151
</div>
52+
<div class="card mt-3">
53+
<div class="card-header">Info</div>
54+
<div class="card-body json-output">
55+
<pre><code class="json">{{ info | to_pretty_json }}</code></pre>
56+
</div>
57+
</div>
5258
<div class="card mt-3">
5359
<div class="card-header">Headers</div>
5460
<div class="card-body json-output">

labapp/app/app.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ def lb_aws():
174174
ns = eph_ns()
175175
if not ns:
176176
raise LabException("Ephemeral NS not set")
177-
url = f"https://{ns}.{app.config['base_url']}/raw"
178-
data = cloudapp_fetch(url, 5, 'request_env', 'AWS')
177+
url = f"https://{ns}.{app.config['base_url']}"
178+
data = cloudapp_fetch(url, 5, 'env', 'AWS')
179179
return jsonify(status='success', data=data)
180180
except (LabException, requests.RequestException, ValueError) as e:
181181
return jsonify(status='fail', error=str(e))
@@ -187,8 +187,8 @@ def lb_azure():
187187
ns = eph_ns()
188188
if not ns:
189189
raise LabException("Ephemeral NS not set")
190-
url = f"https://{ns}.{app.config['base_url']}/raw"
191-
data = cloudapp_fetch(url, 5, 'request_env', 'Azure')
190+
url = f"https://{ns}.{app.config['base_url']}"
191+
data = cloudapp_fetch(url, 5, 'env', 'Azure')
192192
return jsonify(status='success', data=data)
193193
except (LabException, requests.RequestException, ValueError) as e:
194194
return jsonify(status='fail', error=str(e))
@@ -203,8 +203,8 @@ def route1():
203203
base_url = app.config['base_url']
204204
aws_url = f"https://{ns}.{base_url}/aws/raw"
205205
azure_url = f"https://{ns}.{base_url}/azure/raw"
206-
aws_data = cloudapp_fetch(aws_url, 5, 'request_env', 'AWS')
207-
azure_data = cloudapp_fetch(azure_url, 5, 'request_env', 'Azure')
206+
aws_data = cloudapp_fetch(aws_url, 5, 'env', 'AWS')
207+
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure')
208208
data = {
209209
"aws": aws_data,
210210
"azure": azure_data
@@ -221,10 +221,10 @@ def route2():
221221
if not ns:
222222
raise LabException("Ephemeral NS not set")
223223
base_url = app.config['base_url']
224-
aws_url = f"https://{ns}.{base_url}/raw"
225-
azure_url = f"https://{ns}.{base_url}/raw"
226-
aws_data = cloudapp_fetch(aws_url, 5, 'request_env', 'AWS', headers={"X-MCN-lab": "aws"})
227-
azure_data = cloudapp_fetch(azure_url, 5, 'request_env', 'Azure', headers={"X-MCN-lab": "azure"})
224+
aws_url = f"https://{ns}.{base_url}/"
225+
azure_url = f"https://{ns}.{base_url}/"
226+
aws_data = cloudapp_fetch(aws_url, 5, 'env', 'AWS', headers={"X-MCN-lab": "aws"})
227+
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure', headers={"X-MCN-lab": "azure"})
228228
data = {
229229
"aws": aws_data,
230230
"azure": azure_data

labapp/app/markdown/lb.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Build an origin pool and load balancer based on the exercise requirements.
4242
#### **Test Criteria**
4343

4444
```http
45-
GET https://eph-ns.mcn-lab.f5demos.com/raw HTTP/1.1
45+
GET https://eph-ns.mcn-lab.f5demos.com/ HTTP/1.1
4646
Host: eph-ns.mcn-lab.f5demos.com
4747
4848
{
@@ -125,7 +125,7 @@ Create a new origin pool for the Azure cloud app. Reuse your load balancer.
125125
#### **Test Criteria**
126126

127127
```http
128-
GET https://eph-ns.mcn-lab.f5demos.com/raw HTTP/1.1
128+
GET https://eph-ns.mcn-lab.f5demos.com/ HTTP/1.1
129129
Host: eph-ns.mcn-lab.f5demos.com
130130
131131
{

0 commit comments

Comments
 (0)