Skip to content

Commit

Permalink
Merge pull request #13 from f5devcentral/main
Browse files Browse the repository at this point in the history
dev take2
  • Loading branch information
kreynoldsf5 authored Apr 30, 2024
2 parents 787693b + 009f874 commit da05647
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
22 changes: 18 additions & 4 deletions cloudapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def return_err(err):
'error': err.description
}

@app.route('/', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
@app.route('/raw', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
def echo():
"""
Expand All @@ -35,20 +36,27 @@ def echo():
print(e)
response = {
'request_headers': headers,
'request_env': app.config['site']
'env': app.config['site'],
'info': {
'method': request.method,
'url': request.url,
'path': request.path,
'full_path': request.full_path
}
}
if data:
response['request_data'] = data
return jsonify(response)

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

@app.route('/', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
@app.route('/echo', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
@app.route('/pretty', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
@app.route('/pretty_echo', methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'])
def echo_html():
""" Same as /raw, just prettier"""
headers = dict(request.headers)
Expand All @@ -62,7 +70,13 @@ def echo_html():
data = request.form.to_dict()
except Exception:
pass
return render_template('pretty_echo.html', request_env=app.config['site'], request_headers=headers, request_data=data)
info = {
'method': request.method,
'url': request.url,
'path': request.path,
'full_path': request.full_path
}
return render_template('pretty_echo.html', request_env=app.config['site'], info=info, request_headers=headers, request_data=data)

return app

Expand Down
6 changes: 6 additions & 0 deletions cloudapp/app/templates/pretty_echo.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ <h1 class="mt-5">
&nbsp{{ request_env }}
</div>
</div>
<div class="card mt-3">
<div class="card-header">Info</div>
<div class="card-body json-output">
<pre><code class="json">{{ info | to_pretty_json }}</code></pre>
</div>
</div>
<div class="card mt-3">
<div class="card-header">Headers</div>
<div class="card-body json-output">
Expand Down
20 changes: 10 additions & 10 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def lb_aws():
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}/raw"
data = cloudapp_fetch(url, 5, 'request_env', 'AWS')
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(url, 5, 'env', 'AWS')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand All @@ -187,8 +187,8 @@ def lb_azure():
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}/raw"
data = cloudapp_fetch(url, 5, 'request_env', 'Azure')
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(url, 5, 'env', 'Azure')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))
Expand All @@ -203,8 +203,8 @@ def route1():
base_url = app.config['base_url']
aws_url = f"https://{ns}.{base_url}/aws/raw"
azure_url = f"https://{ns}.{base_url}/azure/raw"
aws_data = cloudapp_fetch(aws_url, 5, 'request_env', 'AWS')
azure_data = cloudapp_fetch(azure_url, 5, 'request_env', 'Azure')
aws_data = cloudapp_fetch(aws_url, 5, 'env', 'AWS')
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure')
data = {
"aws": aws_data,
"azure": azure_data
Expand All @@ -221,10 +221,10 @@ def route2():
if not ns:
raise LabException("Ephemeral NS not set")
base_url = app.config['base_url']
aws_url = f"https://{ns}.{base_url}/raw"
azure_url = f"https://{ns}.{base_url}/raw"
aws_data = cloudapp_fetch(aws_url, 5, 'request_env', 'AWS', headers={"X-MCN-lab": "aws"})
azure_data = cloudapp_fetch(azure_url, 5, 'request_env', 'Azure', headers={"X-MCN-lab": "azure"})
aws_url = f"https://{ns}.{base_url}/"
azure_url = f"https://{ns}.{base_url}/"
aws_data = cloudapp_fetch(aws_url, 5, 'env', 'AWS', headers={"X-MCN-lab": "aws"})
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure', headers={"X-MCN-lab": "azure"})
data = {
"aws": aws_data,
"azure": azure_data
Expand Down
4 changes: 2 additions & 2 deletions labapp/app/markdown/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Build an origin pool and load balancer based on the exercise requirements.
#### **Test Criteria**

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

```http
GET https://eph-ns.mcn-lab.f5demos.com/raw HTTP/1.1
GET https://eph-ns.mcn-lab.f5demos.com/ HTTP/1.1
Host: eph-ns.mcn-lab.f5demos.com
{
Expand Down

0 comments on commit da05647

Please sign in to comment.