Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_httpdb_kwargs(host, username, password):
username = username or config.httpdb.user
password = password or config.httpdb.password
username, password, token = add_or_refresh_credentials(
host, username, password, config.httpdb.token
)
return {
'user': username,
'password': password,
'token': token,
}
def check_auth():
if request.path == '/api/healthz':
return
cfg = config.httpdb
header = request.headers.get('Authorization', '')
try:
if basic_auth_required(cfg):
if not header.startswith(basic_prefix):
raise AuthError('missing basic auth')
user, passwd = parse_basic_auth(header)
if user != cfg.user or passwd != cfg.password:
raise AuthError('bad basic auth')
elif bearer_auth_required(cfg):
if not header.startswith(bearer_prefix):
raise AuthError('missing bearer auth')
token = header[len(bearer_prefix):]
if token != cfg.token:
raise AuthError('bad bearer auth')
except AuthError as err:
def get_obj_path(schema, path):
if schema:
return schema + '://' + path
elif path.startswith('/User/'):
user = environ.get('V3IO_USERNAME', 'admin')
return 'v3io:///users/' + user + path[5:]
elif config.httpdb.files_path and \
path.startswith(config.httpdb.files_path):
return path
return None
def main():
parser = ArgumentParser(description=__doc__)
parser.parse_args()
app.app.run(
host='0.0.0.0',
port=config.httpdb.port,
debug=config.httpdb.debug,
)
def init_app():
global db, logs_dir, k8s, scheduler
logger.info('configuration dump\n%s', config.dump_yaml())
if config.httpdb.db_type == 'sqldb':
logger.info('using SQLDB')
db = SQLDB(config.httpdb.dsn)
else:
logger.info('using FileRunDB')
db = FileRunDB(config.httpdb.dirpath)
db.connect()
logs_dir = Path(config.httpdb.logs_path)
try:
k8s = K8sHelper()
except Exception:
pass
# @yaronha - Initialize here
task = periodic.Task()
periodic.schedule(task, 60)
scheduler = Scheduler()
def get_obj_path(schema, path):
if schema:
return schema + '://' + path
elif path.startswith('/User/'):
user = environ.get('V3IO_USERNAME', 'admin')
return 'v3io:///users/' + user + path[5:]
elif config.httpdb.data_volume and \
path.startswith(config.httpdb.data_volume):
if config.httpdb.real_path:
path = config.httpdb.real_path + \
path[len(config.httpdb.data_volume)-1:]
return path
return None
def _initialize_db():
global db
if config.httpdb.db_type == "filedb":
logger.info("using FileRunDB")
db = FileDB(config.httpdb.dirpath)
db.initialize(None)
else:
logger.info("using SQLDB")
db = SQLDB(config.httpdb.dsn)
db_session = None
try:
db_session = create_session()
db.initialize(db_session)
finally:
db_session.close()
def check_auth():
if request.path == '/api/healthz':
return
cfg = config.httpdb
header = request.headers.get('Authorization', '')
try:
if basic_auth_required(cfg):
if not header.startswith(basic_prefix):
raise AuthError('missing basic auth')
user, passwd = parse_basic_auth(header)
if user != cfg.user or passwd != cfg.password:
raise AuthError('bad basic auth')
elif bearer_auth_required(cfg):
if not header.startswith(bearer_prefix):
raise AuthError('missing bearer auth')
token = header[len(bearer_prefix):]
if token != cfg.token:
raise AuthError('bad bearer auth')
except AuthError as err:
def main():
init_data()
uvicorn.run(
'mlrun.api.main:app',
host='0.0.0.0',
port=config.httpdb.port,
debug=config.httpdb.debug,
)
def __init__(self, request: Request):
self.username = None
self.password = None
self.token = None
cfg = config.httpdb
header = request.headers.get('Authorization', '')
if self._basic_auth_required(cfg):
if not header.startswith(self._basic_prefix):
log_and_raise(HTTPStatus.UNAUTHORIZED, reason="missing basic auth")
user, password = self._parse_basic_auth(header)
if user != cfg.user or password != cfg.password:
log_and_raise(HTTPStatus.UNAUTHORIZED, reason="bad basic auth")
self.username = user
self.password = password
elif self._bearer_auth_required(cfg):
if not header.startswith(self._bearer_prefix):
log_and_raise(HTTPStatus.UNAUTHORIZED, reason="missing bearer auth")
token = header[len(self._bearer_prefix) :]
if token != cfg.token:
log_and_raise(HTTPStatus.UNAUTHORIZED, reason="bad basic auth")