Skip to content

Commit 50af251

Browse files
committed
working on next blog post
1 parent f812d1c commit 50af251

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Posts and associated code:
77

88
|Post|Code Directory|
99
|---|---|
10-
|[Adding Okta Authentication to an Existing Flask Web App](https://www.fullstackpython.com/blog/okta-user-auth-existing-flask-web-app.html)|[auth-existing-flask-app](/auth-existing-flask-app)|
10+
|Tracking Flask Application Deployment Versions in Rollbar with Ansible|[ansible-rollbar-flask](./ansible-rollbar-flask)|
11+
|[Adding Okta Authentication to an Existing Flask Web App](https://www.fullstackpython.com/blog/okta-user-auth-existing-flask-web-app.html)|[auth-existing-flask-app](./auth-existing-flask-app)|
1112
|[Fresh Tutorials on Full Stack Python](https://www.fullstackpython.com/blog/fresh-tutorials-october-2018.html)|No code in post.|
1213
|[How to Provision Ubuntu 18.04 LTS Linux Servers on DigitalOcean](https://www.fullstackpython.com/blog/provision-ubuntu-1804-linux-servers-digitalocean.html)|No code in post.|
1314
|[How to Add User Authentication to Flask Apps with Okta](https://www.fullstackpython.com/blog/add-user-authentication-flask-apps-okta.html)|[flask-auth-okta](./flask-auth-okta)|

Diff for: ansible-rollbar-flask/app.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import re
3+
import rollbar
4+
import rollbar.contrib.flask
5+
from flask import Flask, render_template, Response
6+
from flask import got_request_exception
7+
from werkzeug.exceptions import NotFound
8+
9+
10+
app = Flask(__name__)
11+
MIN_PAGE_NAME_LENGTH = 2
12+
13+
14+
@app.before_first_request
15+
def add_monitoring():
16+
rollbar.init(os.environ.get('ROLLBAR_SECRET'))
17+
## delete the next line if you dont want this event anymore
18+
rollbar.report_message('Rollbar is configured correctly')
19+
got_request_exception.connect(rollbar.contrib.flask.report_exception, app)
20+
21+
22+
@app.route("/<string:page>/")
23+
def show_page(page):
24+
try:
25+
valid_length = len(page) >= MIN_PAGE_NAME_LENGTH
26+
valid_name = re.match('^[a-z]+$', page.lower()) is not None
27+
if valid_length and valid_name:
28+
return render_template("{}.html".format(page))
29+
else:
30+
msg = "Sorry, couldn't find page with name {}".format(page)
31+
raise NotFound(msg)
32+
except:
33+
rollbar.report_exc_info()
34+
return Response("404 Not Found")
35+
36+
37+
if __name__ == "__main__":
38+
app.run(debug=True)

Diff for: ansible-rollbar-flask/deploy/hosts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[dev]
2+
192.168.1.1

Diff for: ansible-rollbar-flask/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
blinker==1.4
2+
Flask==1.0.2
3+
rollbar==0.14.5

Diff for: ansible-rollbar-flask/template.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Rollbar token, found in project settings
2+
export ROLLBAR_SECRET=''

Diff for: ansible-rollbar-flask/templates/battlegrounds.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>You found the Battlegrounds GIF!</title>
5+
</head>
6+
<body>
7+
<h1>PUBG so good.</h1>
8+
<img src="https://media.giphy.com/media/3ohzdLMlhId2rJuLUQ/giphy.gif">
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)