-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_oso.py
More file actions
40 lines (25 loc) · 1.01 KB
/
build_oso.py
File metadata and controls
40 lines (25 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sqlalchemy import create_engine, schema
from sqlalchemy.orm import Session
from oso import Oso
import os
from data_model import *
from sqlalchemy.orm import sessionmaker, Session, close_all_sessions
# oso = Oso()
# register_models(oso,Base)
# oso.load_files(["policy.polar"])
UID = os.environ["POSTGRES_USER"]
PWD = os.environ["POSTGRES_PASSWORD"]
DBNAME = os.environ["POSTGRES_DB"]
connection_url = f"postgresql+psycopg2://{UID}:{PWD}@opencdms-database:5432/{DBNAME}"
engine = create_engine(connection_url)
Base.metadata.bind = engine
schemas = {v.schema for k, v in Base.metadata.tables.items()}
for _schema in schemas:
if not engine.dialect.has_schema(engine, _schema):
engine.execute(schema.CreateSchema(_schema))
Base.metadata.create_all(engine)
def get_authenticated_user(user_id: str):
SessionLocal = sessionmaker(autocommit=False,class_=Session, autoflush=False, bind=engine)
session = SessionLocal()
user = session.query(Users).filter(Users.id == user_id).one()
return user