This repository has been archived on 2023-02-28. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-asset-manager/webservice/bam/application/__init__.py

97 lines
2.6 KiB
Python
Raw Normal View History

2014-10-29 19:11:29 +01:00
#!/usr/bin/env python3
2014-10-16 16:10:25 +02:00
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
"""
Environment vars:
- BAM_VERBOSE, set to get debug logging.
"""
# ------------------
# Ensure module path
import os
import sys
path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", ".."))
if path not in sys.path:
sys.path.append(path)
del os, sys, path
# --------
2014-10-23 14:45:21 +02:00
import os
2014-10-30 19:23:57 +01:00
import json
2014-10-29 19:11:29 +01:00
import svn.local
2014-10-30 16:47:03 +01:00
import werkzeug
2014-11-06 15:40:13 +01:00
import xml.etree.ElementTree
2014-11-20 12:29:29 +01:00
import logging
2014-10-23 14:45:21 +02:00
2014-12-18 15:45:39 +01:00
from flask import Flask
from flask import jsonify
from flask import abort
from flask import request
from flask import make_response
from flask import url_for
from flask import Response
2014-10-16 16:10:25 +02:00
from flask.views import MethodView
2014-12-18 15:45:39 +01:00
from flask.ext.restful import Api
2014-10-16 16:10:25 +02:00
from flask.ext.httpauth import HTTPBasicAuth
2014-11-05 18:52:18 +01:00
from flask.ext.sqlalchemy import SQLAlchemy
2014-10-16 16:10:25 +02:00
app = Flask(__name__)
api = Api(app)
auth = HTTPBasicAuth()
2014-11-20 15:21:11 +01:00
try:
import config
app.config.from_object(config.Development)
2014-11-20 15:21:11 +01:00
except ImportError:
app.config["ALLOWED_EXTENSIONS"] = {'txt', 'mp4', 'png', 'jpg', 'jpeg', 'gif', 'blend', 'zip'}
app.config["STORAGE_BUNDLES"] = "/tmp/bam_storage_bundles"
2014-11-20 15:21:11 +01:00
2014-11-05 18:52:18 +01:00
db = SQLAlchemy(app)
2014-11-20 12:29:29 +01:00
log = logging.getLogger("webservice")
2014-12-18 15:45:39 +01:00
from application.modules.resources import DirectoryAPI
from application.modules.resources import FileAPI
if os.environ.get("BAM_VERBOSE"):
logging.basicConfig(level=logging.DEBUG)
2014-11-20 12:29:29 +01:00
2014-11-05 10:42:59 +01:00
2014-10-16 16:10:25 +02:00
@auth.get_password
def get_password(username):
2014-11-07 15:19:09 +01:00
# Temporarily override API access
# TODO (fsiddi) check against users table
return ''
2014-10-16 16:10:25 +02:00
if username == 'bam':
return 'bam'
return None
2014-10-17 09:33:16 +02:00
2014-10-16 16:10:25 +02:00
@auth.error_handler
def unauthorized():
2014-10-17 09:33:16 +02:00
return make_response(jsonify({'message': 'Unauthorized access'}), 403)
# return 403 instead of 401 to prevent browsers from displaying
2014-10-16 16:10:25 +02:00
# the default auth dialog
2014-11-05 16:49:31 +01:00
api.add_resource(DirectoryAPI, '/<project_name>/file_list', endpoint='file_list')
2014-11-05 16:05:45 +01:00
api.add_resource(FileAPI, '/<project_name>/file', endpoint='file')