예제 #1
0
from ultitrackerapi import backend, get_s3Client, models, sql_models

import psycopg2 as psql
import time
from ultitrackerapi import (
    get_logger,
    NUM_CONNECTION_RETRIES,
    POSTGRES_USERNAME,
    POSTGRES_PASSWORD,
    POSTGRES_HOSTNAME,
    POSTGRES_PORT,
    POSTGRES_DATABASE,
)

# get logger
logger = get_logger(__name__, level="DEBUG")

# start s3 client
s3Client = get_s3Client()


class SQLClient(object):
    def __init__(
        self,
        username=POSTGRES_USERNAME,
        password=POSTGRES_PASSWORD,
        hostname=POSTGRES_HOSTNAME,
        port=POSTGRES_PORT,
        database=POSTGRES_DATABASE,
        num_connection_retries=NUM_CONNECTION_RETRIES,
    ):
예제 #2
0
import datetime 
import posixpath 

from enum import Enum
from fastapi import Form
from pydantic import BaseConfig, BaseModel
from typing import Dict, List, Optional, Set, Type
from ultitrackerapi import ANNOTATION_EXPIRATION_DURATION, ULTITRACKER_AUTH_JWT_ALGORITHM, get_logger


logger = get_logger(__name__)


# NOTE: Header and Payload information is readable by everyone
class Header(BaseModel):
    alg: str = ULTITRACKER_AUTH_JWT_ALGORITHM
    typ: str = "JWT"


class Payload(BaseModel):
    exp: int
    iat: int
    iss: str = None
    sub: str = None
    aud: List[str] = []
    nbf: int = None


class User(BaseModel):
    username: str
    email: str = None
예제 #3
0
import bleach

from authlib.jose import jwt
from authlib.jose.errors import DecodeError, ExpiredTokenError
from datetime import datetime, timedelta
from fastapi import Depends, HTTPException, Cookie
from fastapi.security import OAuth2PasswordBearer
from passlib.hash import pbkdf2_sha256
from starlette.requests import Request
from starlette.status import HTTP_401_UNAUTHORIZED

from ultitrackerapi import ULTITRACKER_AUTH_SECRET_KEY, ULTITRACKER_AUTH_TOKEN_EXP_LENGTH, ULTITRACKER_COOKIE_KEY, ULTITRACKER_URL, models, get_backend, get_logger


EXP_LENGTH = timedelta(seconds=ULTITRACKER_AUTH_TOKEN_EXP_LENGTH)
LOGGER = get_logger(__name__)

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token")
backend_instance = get_backend()


def verify_password(password, salted_password):
    return pbkdf2_sha256.verify(password, salted_password)


def get_password_hash(password):
    return pbkdf2_sha256.hash(password)


def sanitize_for_html(string):
    return bleach.clean(string)
예제 #4
0
from fastapi import Cookie, Depends, FastAPI, HTTPException, File, Form, UploadFile
from fastapi.security import OAuth2PasswordRequestForm
from starlette.middleware.cors import CORSMiddleware
from starlette.requests import Request
from starlette.responses import Response
from starlette.status import HTTP_401_UNAUTHORIZED, HTTP_404_NOT_FOUND
from typing import List, Optional

from ultitrackerapi import CORS_ORIGINS, S3_BUCKET_NAME, ULTITRACKER_COOKIE_KEY, annotator_queue, auth, get_backend, get_logger, get_s3Client, models, sql_models, video

# sleep just to make sure the above happened
time.sleep(1)

backend_instance = get_backend()
s3Client = get_s3Client()
logger = get_logger(__name__, "DEBUG")

try:
    backend_instance.client._establish_connection()

except psql.DatabaseError as e:
    logger.error("main: Couldn't connect to database. Aborting")
    raise e

logger.info("CORS_ORIGINS: {}".format(CORS_ORIGINS))

app = FastAPI()

# allow cors
app.add_middleware(CORSMiddleware,
                   allow_origins=CORS_ORIGINS,