Skip to content
Open
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: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
FLASK_APP=todo_app/app
FLASK_ENV=development

LOG_LEVEL=DEBUG
LOGGLY_TOKEN=

# Change the following values for local development.
SECRET_KEY=secret-key

Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ before_deploy:
- sudo mv terraform /usr/local/bin/
- rm terraform_"$TF_VERSION"_linux_amd64.zip
- terraform init
- terraform apply -var AUTH_CLIENT_ID=$AUTH_CLIENT_ID -var AUTH_CLIENT_SECRET=$AUTH_CLIENT_SECRET -var SECRET_KEY=$SECRET_KEY -auto-approve
- terraform apply -var AUTH_CLIENT_ID=$AUTH_CLIENT_ID -var AUTH_CLIENT_SECRET=$AUTH_CLIENT_SECRET -var LOGGLY_TOKEN=$LOGGLY_TOKEN
-var SECRET_KEY=$SECRET_KEY -auto-approve
deploy:
provider: script
script: bash deploy.sh
Expand All @@ -28,3 +29,4 @@ env:
- secure: XDlwoi/3Cgb2nWPD24/Ioq/RNLr3gQwAgdchSfil7VfAR7k2O+xHGnI50A9caOmoChd4FeIsBdppErX0xNe+nFEddjJlh2JXhUrd2xkf8juv6qVYJ+IoRh2oKWkTSDFxH8y/Om81ycd1NbSJ2g+qCrIPBKFVc0qpYTTlcXf2GoTsUrwMJcHTqoqhhd0QSWRQgiB+IlMQCJ3Ixm2G3Wark0XOSd/TB3W5Jz9+XnKFfIuqiBq7a2UxlBm0fy08tzYd8b+VFtd8nS2rtqwWaTLtpiXyqMJlrwgXsfML05GI3ig1ZoMm8YgvJwIa//C/IYqD/JiwfeIPxFXIekpM+abZXHJhn40I0dEkPBBEcFAvcMxo6b7n3cW8fu2JOZSxmUEwS+FULiLUMrT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JS901+5k/183gZx0YAK/Q19cw45Iq2EC9yX0r6hoZmqr1MyBsTGnSRVU30VBdztgGf9Szo/gMB9JHCXbmEwqzr0wFslqj8C43OMBm6+/knu2DId5CTpvvzHDDpEhgfOxtRCqNhVy+H/R3sItxcb1a+OR8FAi/YCTk3V5DisjPVqg1GJz/bmjPL7YPlSsAgQqPBes=
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ You will be provided with a "Client Id" upon creating the application, you need
$ docker run --name to-do-database -p 27017:27017 -d mongo
```

### Setting up Loggly for logging

1. Sign up to Loggly ['here']('https://www.loggly.com/')
2. Obtain a token from Loggly: Once you've created your account, log in and find the icon for "Logs" in the lefthand menu. Under this, select "Source Setup". Then, on the tabs along the top of the page, select "Customer Tokens". Add a new customer token.
3. Copy the value and set LOGGLY_TOKEN it in your .env file.

## Running the App

### Option 1: Docker
Expand Down
199 changes: 131 additions & 68 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ selenium = "^3.141.0"
pymongo = {extras = ["srv"], version = "^3.11.3"}
oauthlib = "^3.1.0"
Flask-Login = "^0.5.0"
loggly-python-handler = "^1.0.1"

[tool.poetry.dev-dependencies]

Expand Down
19 changes: 18 additions & 1 deletion todo_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import requests
from flask_login import LoginManager, login_required, login_user, current_user
from oauthlib.oauth2 import WebApplicationClient
from loggly.handlers import HTTPSHandler
from logging import Formatter

from todo_app.data.mongodb import MongoDB
from todo_app.user import User
Expand All @@ -14,8 +16,17 @@ def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
app.config['LOGIN_DISABLED'] = os.getenv('LOGIN_DISABLED')
app.config['LOGGLY_TOKEN'] = os.getenv('LOGGLY_TOKEN')
app.logger.setLevel(os.environ.get('LOG_LEVEL', 'DEBUG'))
database = MongoDB()

if app.config['LOGGLY_TOKEN'] is not None:
handler = HTTPSHandler(f'https://logs-01.loggly.com/inputs/{app.config["LOGGLY_TOKEN"]}/tag/todo-app')
handler.setFormatter(
Formatter("[%(asctime)s] %(levelname)s in %(module)s: %(message)s")
)
app.logger.addHandler(handler)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crashes if LOGGLY_TOKEN is not set.


## Auth Service Setup
login_manager = LoginManager()
login_manager.init_app(app)
Expand Down Expand Up @@ -46,6 +57,7 @@ def login():
user_name = user_request_response.json()['login']
user = User(user_name)
login_user(user)
app.logger.info("USER LOGGED IN: %s", user_name)
return redirect(url_for('index'))

def writer_required(f):
Expand All @@ -71,35 +83,40 @@ def index():
@writer_required
def add_item():
name = request.form['name']
database.add_item(name)
id = database.add_item(name)
app.logger.info("CREATED ITEM: %s" , id)
return redirect(url_for('index'))


@app.route('/items/<id>/start')
@writer_required
def start_item(id):
database.start_item(id)
app.logger.info("STARTED ITEM: %s", id)
return redirect(url_for('index'))


@app.route('/items/<id>/complete')
@writer_required
def complete_item(id):
database.complete_item(id)
app.logger.info("COMPLETED ITEM: %s", id)
return redirect(url_for('index'))


@app.route('/items/<id>/uncomplete')
@writer_required
def uncomplete_item(id):
database.uncomplete_item(id)
app.logger.info("UNCOMPLETED ITEM: %s", id)
return redirect(url_for('index'))


@app.route('/items/<id>/delete')
@writer_required
def delete_item(id):
database.delete_item(id)
app.logger.info("DELETED ITEM: %s", id)
return redirect(url_for('index'))


Expand Down
3 changes: 1 addition & 2 deletions todo_app/data/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def get_items(self):
def add_item(self, name):
now = datetime.utcnow()
item = {"name": name, "status": "To Do", "dateLastActivity": now}
self.collection.insert_one(item)
return
return self.collection.insert_one(item).inserted_id

def start_item(self, id):
return self.set_item_status(id, "Doing")
Expand Down
9 changes: 9 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ variable "MONGODB_DATABASE_NAME" {
description = "Name of default database"
default = "main"
}

variable "LOG_LEVEL" {
description = "Level of logging"
default = "ERROR"
}

variable "LOGGLY_TOKEN" {
description = "Customer access token for loggly subscription"
}
Comment on lines +33 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variable "LOGGLY_TOKEN" {
description = "Customer access token for loggly subscription"
}
variable "LOGGLY_TOKEN" {
description = "Customer access token for loggly subscription"
sensitive = true
}