Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Apr 29, 2024
1 parent 22cf752 commit 91af508
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
32 changes: 19 additions & 13 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
cache = Cache(app)
app.secret_key = "blahblahblah"

class LabException(Exception):
"""lab exception"""

def render_md(file: str) -> str:
"""render markdown w/ common extentions"""
with open(file, "r") as file:
content = file.read()
with open(file, "r", encoding="utf-8") as md:
content = md.read()
html = markdown.markdown(
content,
extensions=['markdown.extensions.attr_list','markdown.extensions.codehilite','markdown.extensions.fenced_code']
Expand Down Expand Up @@ -113,33 +116,36 @@ def header():
html = render_md("markdown/header.md")
return render_template('exercise_standard.html', title="MCN Practical: Headers", content=html, ns=ns)

@app.route('/_lb_aws')
@app.route('/_lb1')
def lb_aws():
"""AWS LB test"""
try:
ns = eph_ns()
if not ns:
raise Exception("Ephemeral NS not set.")
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}/raw"
print(url)
response = requests.get(url, timeout=5)
print(response.text)
print(response.json())
response.raise_for_status()
if response.json()['request_env'] != "AWS":
raise Exception("Invalid request env.")
raise LabException("Invalid request environment.")
return jsonify(status='success', data=response.json())
except Exception as e:
except (LabException, requests.RequestException) as e:
return jsonify(status='fail', error=str(e))

@app.route('/_lb_azure')
@app.route('/_lb2')
def lb_azure():
"""Azure LB test"""
try:
response = requests.get('https://ifconfig1.io/all.json')
response.raise_for_status()
ns = eph_ns()
if not ns:
raise LabException("Ephemeral NS not set")
url = f"https://{ns}.{app.config['base_url']}/raw"
response = requests.get(url, timeout=5)
response.raise_for_status()
if response.json()['request_env'] != "Azure":
raise LabException("Invalid request environment.")
return jsonify(status='success', data=response.json())
except requests.RequestException as e:
except (LabException, requests.RequestException) as e:
return jsonify(status='fail', error=str(e))

if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions labapp/app/markdown/header.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div href="/" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none">
<img src="/static/path.png" width="300px" height="auto" alt="intro">
<img src="/static/header.png" width="300px" height="auto" alt="intro">
</div>

# **Header Manipulation**
Expand All @@ -20,7 +20,7 @@ HERE
document.getElementById('requestBtn2').addEventListener('click', async () => {
const resultDiv = document.getElementById('result2');
try {
const response = await axios.get('/_lb_azure');
const response = await axios.get('/_head1');
if(response.data.status === 'success') {
const prettyJson = JSON.stringify(response.data.data, null, 4);
resultDiv.innerHTML = `<pre class="alert alert-success"><code>${prettyJson}</code></pre>`;
Expand Down
7 changes: 4 additions & 3 deletions labapp/app/markdown/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ Build an origin pool and load balancer based on the following criteria:
document.getElementById('requestBtn1').addEventListener('click', async () => {
const resultDiv = document.getElementById('result1');
try {
const response = await axios.get('/_lb_aws');
const response = await axios.get('/_lb1');
if(response.data.status === 'success') {
const prettyJson = JSON.stringify(response.data.data, null, 4);
resultDiv.innerHTML = `<pre class="alert alert-success"><code>${prettyJson}</code></pre>`;
} else {
resultDiv.innerHTML = `<div class="alert alert-danger"><b>Request Failed</b></div>`;
const errJson = JSON.stringify(response.data.error, null, 4);
resultDiv.innerHTML = `<div class="alert alert-danger"><b>Request Failed:</b>&nbsp;&nbsp;<code>${errJson}</code></div>`;
}
resultDiv.scrollIntoView({ behavior: 'smooth', block: 'end' }); // Smooth scroll to the resultDiv
} catch (error) {
Expand Down Expand Up @@ -147,7 +148,7 @@ Create a new origin pool for the Azure cloud app. Reuse your load balancer.
document.getElementById('requestBtn2').addEventListener('click', async () => {
const resultDiv = document.getElementById('result2');
try {
const response = await axios.get('/_lb_azure');
const response = await axios.get('/_lb2');
if(response.data.status === 'success') {
const prettyJson = JSON.stringify(response.data.data, null, 4);
resultDiv.innerHTML = `<pre class="alert alert-success"><code>${prettyJson}</code></pre>`;
Expand Down
2 changes: 1 addition & 1 deletion labapp/app/markdown/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ HERE
document.getElementById('requestBtn2').addEventListener('click', async () => {
const resultDiv = document.getElementById('result2');
try {
const response = await axios.get('/_lb_azure');
const response = await axios.get('/_path1');
if(response.data.status === 'success') {
const prettyJson = JSON.stringify(response.data.data, null, 4);
resultDiv.innerHTML = `<pre class="alert alert-success"><code>${prettyJson}</code></pre>`;
Expand Down
File renamed without changes

0 comments on commit 91af508

Please sign in to comment.