Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #17

Merged
merged 30 commits into from
May 1, 2024
Merged

Dev #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ cython_debug/
#.idea/

.venv/
.DS_Store
.DS_Store
.vscode
8 changes: 5 additions & 3 deletions cloudapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def echo():
'env': app.config['site'],
'info': {
'method': request.method,
'url': request.url,
'path': request.path,
'full_path': request.full_path
'path': request.path
}
}
if data:
Expand Down Expand Up @@ -78,6 +76,10 @@ def echo_html():
}
return render_template('pretty_echo.html', request_env=app.config['site'], info=info, request_headers=headers, request_data=data)

@app.route('/foo/', methods=['GET'])
def ex_test():
return jsonify({'info': 'bar'})

return app

app = create_app()
Expand Down
166 changes: 132 additions & 34 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ def eph_ns() -> str:
this_eph_ns = request.cookies.get('eph_ns', None)
return this_eph_ns

def cloudapp_fetch(url, timeout, prop, value, headers = {}):
def cloudapp_fetch(session, url, timeout, prop, value, headers = {}):
"""
Fetch data from URL
Validate prop and value in the JSON response
"""
response = requests.get(url, timeout=timeout, headers=headers)
response = session.get(url, timeout=timeout)
response.raise_for_status()
data = response.json()
if data.get(prop) != value:
raise ValueError(f"Invalid {prop}: expected {value}, got {data.get(prop)}")
clean_headers = headers_cleaner(data['request_headers'])
data['request_headers'] = clean_headers
if data.get("request_headers"):
clean_headers = headers_cleaner(data['request_headers'])
data['request_headers'] = clean_headers
return data
return data

def headers_cleaner(headers):
Expand All @@ -81,16 +83,25 @@ def return_err(err):
@app.route('/')
def index():
"""index page"""
html = render_md("markdown/overview.md")
html = render_md("markdown/welcome.md")
return render_template('standard.html',
title="MCN Practical: Overview",
content=html,
udf=app.config['UDF']
content=html
)

@app.route('/overview')
def arch():
"""arch page"""
html = render_md("markdown/overview.md")
return render_template('standard.html',
title="MCN Practical: Architecture",
content=html
)

@app.route('/setup', methods=['GET', 'POST'])
def setup():
"""setup page"""
ns = eph_ns()
if request.method == 'POST':
action = request.form['action']
if action == 'save':
Expand All @@ -100,7 +111,7 @@ def setup():
return redirect(url_for('setup'))
response = make_response(redirect('/setup'))
response.set_cookie('eph_ns', this_eph_ns, max_age=60*60*24)
flash("Ephemeral NS successfully set.", "success")
flash('Ephemeral NS successfully set.', "success")
return response
if action == 'clear':
response = make_response(redirect('/setup'))
Expand All @@ -111,17 +122,7 @@ def setup():
return render_template('setup.html',
title="MCN Practical: Setup",
content=html,
udf=app.config['UDF']
)

@app.route('/arch')
def arch():
"""arch page"""
html = render_md("markdown/arch.md")
return render_template('standard.html',
title="MCN Practical: Architecture",
content=html,
udf=app.config['UDF']
ns=ns
)

@app.route('/_ce_status')
Expand All @@ -139,8 +140,7 @@ def lb():
return render_template('exercise_standard.html',
title="MCN Practical: LB",
content=html,
ns=ns,
udf=app.config['UDF']
ns=ns
)

@app.route('/route')
Expand All @@ -152,30 +152,108 @@ def path():
title="MCN Practical: HTTP Routing",
content=html,
ns=ns,
udf=app.config['UDF']

)

@app.route('/header')
@app.route('/manipulation')
def header():
"""header page"""
"""manipulation page"""
ns = eph_ns()
html = render_md("markdown/header.md")
html = render_md("markdown/manipulation.md")
return render_template('exercise_standard.html',
title="MCN Practical: Headers",
title="MCN Practical: Manipulation",
content=html,
ns=ns,
udf=app.config['UDF']
ns=ns
)

@app.route('/portability')
def port():
"""portability page"""
ns = eph_ns()
html = render_md("markdown/portability.md")
return render_template('exercise_standard.html',
title="MCN Practical: Portability",
content=html,
ns=ns
)

@app.route('/vnet')
def vnet():
"""reference page"""
ns = eph_ns()
html = render_md("markdown/reference.md")
return render_template('coming-soon.html',
title="MCN Practical: Reference",
content=html,
ns=ns
)

@app.route('/netpolicy')
def netp():
"""reference page"""
ns = eph_ns()
html = render_md("markdown/reference.md")
return render_template('coming-soon.html',
title="MCN Practical: Reference",
content=html,
ns=ns
)

@app.route('/ref')
def ref():
"""reference page"""
ns = eph_ns()
html = render_md("markdown/reference.md")
return render_template('coming-soon.html',
title="MCN Practical: Reference",
content=html,
ns=ns
)

@app.route('/score')
def score():
"""scoreboard page"""
ns = eph_ns()
html = render_md("markdown/score.md")
return render_template('coming-soon.html',
title="MCN Practical: Scoreboard",
content=html,
ns=ns
)

@app.route('/_test1')
def ex_test():
"""Example test"""
try:
s = requests.Session()
url = f"https://foo.{app.config['base_url']}/"
data = cloudapp_fetch(s, url, 5, 'info', 'bar')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))

@app.route('/_test2')
def ex_test2():
"""Example test"""
try:
s = requests.Session()
url = f"https://bar.{app.config['base_url']}/"
data = cloudapp_fetch(s, url, 5, 'info', 'foo')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))


@app.route('/_lb1')
def lb_aws():
"""Azure LB test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(url, 5, 'env', 'AWS')
data = cloudapp_fetch(s, 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 @@ -184,11 +262,12 @@ def lb_aws():
def lb_azure():
"""Azure LB test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}"
data = cloudapp_fetch(url, 5, 'env', 'Azure')
data = cloudapp_fetch(s, 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 @@ -197,14 +276,15 @@ def lb_azure():
def route1():
"""First Route Test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
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, 'env', 'AWS')
azure_data = cloudapp_fetch(azure_url, 5, 'env', 'Azure')
aws_data = cloudapp_fetch(s, aws_url, 5, 'env', 'AWS')
azure_data = cloudapp_fetch(s, azure_url, 5, 'env', 'Azure')
data = {
"aws": aws_data,
"azure": azure_data
Expand All @@ -217,21 +297,39 @@ def route1():
def route2():
"""First Route Test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
base_url = app.config['base_url']
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"})
s.headers["X-MCN-lab"] = "aws"
aws_data = cloudapp_fetch(s, aws_url, 5, 'env', 'AWS')
s.headers["X-MCN-lab"] = "azure"
azure_data = cloudapp_fetch(s, azure_url, 5, 'env', 'Azure', headers={"X-MCN-lab": "azure"})
data = {
"aws": aws_data,
"azure": azure_data
}
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))

@app.route('/_manip1')
def manip1():
"""First Manip Test"""
try:
s = requests.Session()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
base_url = app.config['base_url']
url = f"https://{ns}.{base_url}/aws/raw"
r_data = cloudapp_fetch(s, url, 5, 'info', '{"path": "/"}')
return jsonify(status='success', data=r_data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))


if __name__ == '__main__':
Expand Down
14 changes: 0 additions & 14 deletions labapp/app/markdown/arch.md

This file was deleted.

44 changes: 0 additions & 44 deletions labapp/app/markdown/header.md

This file was deleted.

Loading