Skip to content

Commit

Permalink
ready to test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Apr 29, 2024
1 parent 1082e1a commit dd47345
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 80 deletions.
81 changes: 62 additions & 19 deletions labapp/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ def eph_ns() -> str:
eph_ns = request.cookies.get('eph_ns', None)
return eph_ns

def cloudapp_fetch(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.raise_for_status()

data = response.json() ##Clean this
if data.get(prop) != value:
raise ValueError(f"Invalid {prop}: expected {value}, got {data.get(prop)}")
return data


@app.errorhandler(404)
@app.errorhandler(500)
def return_err(err):
Expand Down Expand Up @@ -108,12 +122,6 @@ def ce_state():
data = get_ce_state(app.config['ce_info'])
return data

@app.route('/_ce_info')
@cache.cached(timeout=30)
def ce_info():
"""temp for status build"""
return jsonify(app.config['ce_info'])

@app.route('/lb')
def lb():
"""lb page"""
Expand Down Expand Up @@ -152,18 +160,15 @@ def header():

@app.route('/_lb1')
def lb_aws():
"""AWS LB test"""
"""Azure LB test"""
try:
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'] != "AWS":
raise LabException("Invalid request environment.")
return jsonify(status='success', data=response.json())
except (LabException, requests.RequestException) as e:
data = cloudapp_fetch(url, 5, 'request_env', 'AWS')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))

@app.route('/_lb2')
Expand All @@ -174,13 +179,51 @@ def lb_azure():
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 (LabException, requests.RequestException) as e:
data = cloudapp_fetch(url, 5, 'request_env', 'Azure')
return jsonify(status='success', data=data)
except (LabException, requests.RequestException, ValueError) as e:
return jsonify(status='fail', error=str(e))

@app.route('/_route1')
def route1():
"""First Route Test"""
try:
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, 'request_env', 'AWS')
azure_data = cloudapp_fetch(azure_url, 5, 'request_env', '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('/_route2')
def route1():
"""First Route Test"""
try:
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, 'request_env', 'AWS', headers={"X-MCN-lab": "aws"})
azure_data = cloudapp_fetch(azure_url, 5, 'request_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))


if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=False)
112 changes: 58 additions & 54 deletions labapp/app/markdown/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,38 @@ More complicated configurations (underlay networking, security services, observa
For the initial exercise, make the cloud application running in AWS available to the UDF environment.
Build an origin pool and load balancer based on the following criteria:

<ul class="list-group">
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
The URL for the cloud app hosted in AWS is <a href="https://aws-cloud-app.mcn-lab.f5demos.com">https://aws-cloud-app.mcn-lab.f5demos.com</a>
</li>
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
The cloud app is only reachable from the <strong>student-awsnet</strong> site.
</li>
<li class="list-group-item">
<img src="/static/tls-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
The cloud app is TLS only.
</li>
<li class="list-group-item">
<img src="/static/tls-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
Use the wildcard cert provided in the shared NS, <strong>mcn-lab-wildcard</strong>, to enable TLS on the LB.
</li>
</ul>

<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckDefault">
The URL for the cloud app hosted in AWS is <a href="https://aws-cloud-app.mcn-lab.f5demos.com">https://aws-cloud-app.mcn-lab.f5demos.com</a>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckCDefault">
The cloud app is only reachable from the "student-awsnet" site.
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckCDefault">
The cloud app is TLS enabled.
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckCDefault">
Use the wildcard cert provided in the shared NS, "mcn-lab-wildcard", to enable TLS on the LB.
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckCDefault">
The load balancer should only be advertised from your CE in UDF. <b>Do not advertise this service on the Internet.</b>
</label>
</div>
<div style="height:25px"></div>

#### **Test Criteria**

<div style="height:25px"></div>
```http
GET https://eph-ns.mcn-lab.f5demos.com/raw HTTP/1.1
Host: eph-ns.mcn-lab.f5demos.com
{
"env": "aws",
...
}
```

<div class="left-aligned-button-container">
<button id="requestBtn1" class="btn btn-primary">Test Load Balancer</button>
Expand Down Expand Up @@ -99,34 +97,42 @@ Since this is the first exercise, here are some hints (if you need them).
</div>
</div>

<div style="height:25px"></div>
<div style="height:25px" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>

### **Exercise 2: Azure Cloud App**

For the second exercise, make the cloud application running in Azure available to the UDF environment.
Create a new origin pool for the Azure cloud app. Reuse your load balancer.

<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckDefault">
The URL for the cloud app hosted in Azure is <a href="https://azure-cloud-app.mcn-lab.f5demos.com">https://aws-cloud-app.mcn-lab.f5demos.com</a>
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckCDefault">
The cloud app is only reachable from the "student-azurenet" site.
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault" checked>
<label class="form-check-label" for="flexCheckCDefault">
The cloud app is TLS enabled.
</label>
</div>

<ul class="list-group">
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
The URL for the cloud app hosted in Azure is <a href="https://azure-cloud-app.mcn-lab.f5demos.com">https://aws-cloud-app.mcn-lab.f5demos.com</a>
</li>
<li class="list-group-item">
<img src="/static/origin-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
The cloud app is only reachable from the <strong>student-azurenet</strong> site.
</li>
<li class="list-group-item">
<img src="/static/tls-icon.png" width="auto" height="25px"> &nbsp; &nbsp;
The cloud app is TLS only.
</li>
</ul>

<div style="height:25px"></div>

#### **Test Criteria**

```http
GET https://eph-ns.mcn-lab.f5demos.com/raw HTTP/1.1
Host: eph-ns.mcn-lab.f5demos.com
{
"env": "azure",
...
}
```

<div class="left-aligned-button-container">
<button id="requestBtn2" class="btn btn-primary">Test Load Balancer</button>
Expand All @@ -138,9 +144,7 @@ document.getElementById('requestBtn2').addEventListener('click', () => {
});
</script>

<div style="height:25px"></div>

Once you've completed both exercises, move on to the <a href="/path" class="alert-link">path based routing</a> exercise.
<div style="height:25px" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>

<div style="height:25px"></div>
Once you've completed both exercises, move on to the <a href="/route" class="alert-link">http routing</a> exercise.

13 changes: 6 additions & 7 deletions labapp/app/markdown/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

Modern applications, and some classic ones, are often comprised of disparate services spread across sites.
MCN solutions must be able to make routing decisions based on characterstics of an HTTP request.
F5 XC App Connect is a distributed L7 proxy that provide intelligent routing, visibility, and strategic points of control.

<div style="height:25px"></div>

Expand Down Expand Up @@ -62,11 +63,11 @@ Host: eph-ns.mcn-lab.f5demos.com
<div id="result1" class="mt-3"></div>
<script>
document.getElementById('requestBtn1').addEventListener('click', () => {
makeHttpRequest('requestBtn1', '/_path1', 'result1');
makeHttpRequest('requestBtn1', '/_route1', 'result1');
});
</script>

<div style="height:25px"></div>
<div style="height:25px" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>

### **Exercise 2: Header Routing**

Expand Down Expand Up @@ -116,12 +117,10 @@ X-MCN-lab: azure
<div id="result2" class="mt-3"></div>
<script>
document.getElementById('requestBtn2').addEventListener('click', () => {
makeHttpRequest('requestBtn2', '/_path2', 'result2');
makeHttpRequest('requestBtn2', '/_route2', 'result2');
});
</script>

<div style="height:25px" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom"></div>


Once you've completed both exercises, move on to the <a href="/header" class="alert-link">header manipulation</a> exercise.

<div style="height:100px"></div>
Once you've completed the exercises, move on to the <a href="/header" class="alert-link">header manipulation</a> exercise.
Binary file added labapp/app/static/tls-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd47345

Please sign in to comment.