Skip to content

Commit

Permalink
Setup oso, add policy.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhatch committed Dec 10, 2020
1 parent 922af81 commit 8bf8c4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Entrypoint to the expenses application"""
from pathlib import Path

from flask import Flask
from flask_graphql import GraphQLView

from oso import Oso
from sqlalchemy_oso import register_models

from .models import db
from .schema import schema

Expand All @@ -24,6 +29,12 @@ def create_app(test_config=None):
app.register_blueprint(user.bp)
app.register_blueprint(sql.bp)

oso = Oso()
register_models(oso, db.Model)
oso.load_file(Path(__file__).parent / "policy.polar")

app.oso = oso

return app


Expand Down
9 changes: 8 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from flask import g, current_app, request
from flask_sqlalchemy import SQLAlchemy

from sqlalchemy.orm import relationship

db = SQLAlchemy()
from sqlalchemy_oso.flask import AuthorizedSQLAlchemy

db = AuthorizedSQLAlchemy(
get_oso=lambda: current_app.oso,
get_user=lambda: getattr(g, "current_user", None),
get_action=lambda: "read"
)


class Expense(db.Model):
Expand Down
Empty file added app/policy.polar
Empty file.

0 comments on commit 8bf8c4a

Please sign in to comment.