Beispiel #1
0
from run import api
from api import User, hello

# API註冊路由
api.add_resource(User.Users, '/users/')
api.add_resource(User.User, "/user/<string:name>")
api.add_resource(hello.helloworld, "/hello/")
Beispiel #2
0
                            required=True,
                            help="Missing the ID of the movie")
        args = parser.parse_args()

        try:
            MovieModel.delete_by_id(args.id)
        except sqlalchemy.exec.SQLAlchemyError:
            return {
                "data": None,
                "error": "Error during movie deletion, or it don't exists",
                "file": __name__,
                "cls": self.__class__.__name__,
                "args": args
            }, 404

        return {
            "data": None,
            "message": "Successfuly deleting the movie",
            "file": __name__,
            "cls": self.__class__.__name__,
            "args": args
        }, 200


#
# Adding resources:
api.add_resource(Movies, '/v1/movies')
api.add_resource(Movie, '/v1/movie')
api.add_resource(MoviesCount, '/v1/movies/count')
api.add_resource(MoviesSearch, '/v1/movies/search')
Beispiel #3
0
            args = self.parser.parse_args()

            if args['token'] not in app.config['MATTERMOST_GIPHY_TOKEN']:
                raise Exception(
                    'Tokens did not match, it is possible that this request came from somewhere other than Mattermost')

            if args['command']:
                slash_command = True
                response['response_type'] = 'in_channel'

            translate_text = args['text']
            if not slash_command:
                translate_text = args['text'][len(args['trigger_word']):]

            gif_url = giphy_translate(translate_text)
            if not gif_url:
                raise Exception('No gif url found for `{}`'.format(translate_text))

            response['text'] = gif_url

        except Exception as err:
            msg = err.message
            logging.error('unable to handle new post :: {}'.format(msg))
            response['text'] = msg

        finally:
            return response, 200


api.add_resource(NewGiphyPost, '/new_post', endpoint='new_giphy_post')
Beispiel #4
0
from run import api
from controllers import users

api.add_resource(users.UserRegistration, '/registration')
api.add_resource(users.UserLogin, '/login')
api.add_resource(users.UserLogoutAccess, '/logout/access')
api.add_resource(users.UserLogoutRefresh, '/logout/refresh')
api.add_resource(users.TokenRefresh, '/token/refresh')
api.add_resource(users.AllUsers, '/users')
api.add_resource(users.SecretResource, '/secret')
Beispiel #5
0

class AllUsers(Resource):
    # @swag_from('./../docs/all_users.yml')
    @jwt_required
    def get(self):
        current_user = get_jwt_identity()
        if current_user not in app.config['SUPERADMIN_USERS']:
            return {'message': "Your are'nt authorized to access this route"}, 401
        return UserModel.return_all()

    # @swag_from('./../docs/all_users.yml')
    @jwt_required
    def delete(self):
        current_user = get_jwt_identity()
        if current_user not in app.config['SUPERADMIN_USERS']:
            return {'message': "Your are'nt authorized to access this route"}, 401
        return UserModel.delete_all()


#
# Adding resources:
api.add_resource(Registration, '/v1/private/registration')
api.add_resource(AllUsers, '/v1/private/users')
api.add_resource(DevToken, '/v1/private/devtoken')

api.add_resource(Login, '/v1/login')
api.add_resource(LogoutAccess, '/v1/logout/access')
api.add_resource(LogoutRefresh, '/v1/logout/refresh')
api.add_resource(TokenRefresh, '/v1/token/refresh')
Beispiel #6
0
                low = genre.lower().strip()
                if low != '':
                    if low not in all_genres:
                        all_genres[low] = 0
                    all_genres[low] += 1

        stats['genres'] = {
            'count':  int(len(all_genres.keys())),
            'count_by_genres': all_genres
        }

        count_seen_q = MovieModel.query.filter(MovieModel.seen == True).statement.with_only_columns([func.count()])
        count_total_q = MovieModel.query.statement.with_only_columns([func.count()])
        stats['seen'] = {
            'total': int(MovieModel.query.session.execute(count_total_q).scalar()),
            'seen': int(MovieModel.query.session.execute(count_seen_q).scalar()),
        }

        return {
            "data": stats,
            "message": "Successfuly returning the global's statistics",
            "file": __name__,
            "cls": self.__class__.__name__,
            "args": None
        }, 200


#
# Adding resources:
api.add_resource(GlobalStatistics, '/v1/statistics')
Beispiel #7
0
from run import api
import views.auth as resources

# Auth API
api.add_resource(resources.UserRegistration, '/registration')
api.add_resource(resources.UserLogin, '/login')
api.add_resource(resources.UserLogoutAccess, '/logout/access')
api.add_resource(resources.UserLogoutRefresh, '/logout/refresh')
api.add_resource(resources.TokenRefresh, '/token/refresh')
Beispiel #8
0
    @jwt_required
    def delete(self):
        parser = reqparse.RequestParser()
        parser.add_argument('id', type=int, required=True, help="Missing the ID of the actor")
        args = parser.parse_args()

        if True: #try:
            ActorModel.delete_by_id(args.id)
        else: # except:
            return {
                "data": None,
                "error": "Error during actor deletion, or it don't exists",
                "file": __name__,
                "cls": self.__class__.__name__,
                "args": args
                }, 404

        return {
            "data": None,
            "message": "Successfuly deleting the actor",
            "file": __name__,
            "cls": self.__class__.__name__,
            "args": args
            }, 200


#
# Adding resources:
api.add_resource(Actors, '/v1/actors')
api.add_resource(Actor, '/v1/actor')
Beispiel #9
0
            response['channel'] = channel
            response['username'] = app.config['GITHUB_BOT_USERNAME']
            response['icon_url'] = app.config['GITHUB_BOT_ICON_URL']

            pprint(response)

            headers = {'Content-Type': 'application/json'}
            r = requests.post(url, headers=headers, data=json.dumps(response), verify=False)

            if r.status_code is not requests.codes.ok:
                print 'Encountered error posting to Mattermost URL %s, status=%d, response_body=%s' % (
                url, r.status_code, r.json())
            return "Ok", 200
        else:
            return "Not implemented", 400


def get_hook_info(data):
    if 'repository' in data:
        repo = data['repository']['full_name']
        if repo in app.config['MATTERMOST_WEBHOOK_URLS']:
            return app.config['MATTERMOST_WEBHOOK_URLS'][repo]
    if 'organization' in data:
        org = data['organization']['login']
        if org in app.config['MATTERMOST_WEBHOOK_URLS']:
            return app.config['MATTERMOST_WEBHOOK_URLS'][org]
    return app.config['MATTERMOST_WEBHOOK_URLS']['default']


api.add_resource(GithubHook, '/git', endpoint='github_hook')
Beispiel #10
0
        parser.add_argument('id',
                            type=int,
                            required=True,
                            help="Missing the ID of the realisator")
        args = parser.parse_args()

        try:
            RealisatorModel.delete_by_id(args.id)
        except:
            return {
                "data": None,
                "error":
                "Error during realisator deletion, or it don't exists",
                "file": __name__,
                "cls": self.__class__.__name__,
                "args": args
            }, 404

        return {
            "data": None,
            "message": "Successfuly deleting the realisator",
            "file": __name__,
            "cls": self.__class__.__name__,
            "args": args
        }, 200


#
# Adding resources:
api.add_resource(Realisators, '/v1/realisators')
api.add_resource(Realisator, '/v1/realisator')
Beispiel #11
0
            if args['token'] not in app.config['MATTERMOST_GIPHY_TOKEN']:
                raise Exception(
                    'Tokens did not match, it is possible that this request came from somewhere other than Mattermost'
                )

            if args['command']:
                slash_command = True
                response['response_type'] = 'in_channel'

            translate_text = args['text']
            if not slash_command:
                translate_text = args['text'][len(args['trigger_word']):]

            gif_url = giphy_translate(translate_text)
            if not gif_url:
                raise Exception(
                    'No gif url found for `{}`'.format(translate_text))

            response['text'] = gif_url

        except Exception as err:
            msg = err.message
            logging.error('unable to handle new post :: {}'.format(msg))
            response['text'] = msg

        finally:
            return response, 200


api.add_resource(NewGiphyPost, '/new_post', endpoint='new_giphy_post')
from run import app, api, global_var
import resources
from flask import jsonify, render_template, session, request, flash, redirect, url_for
from package.global_variable.variables import *
from copy import deepcopy
from flask_jwt_extended import jwt_required
from package.security.decorators import mode_superuser
from passlib.hash import pbkdf2_sha256 as sha256


api.add_resource(resources.XyzResource, '/xyz')
api.add_resource(resources.XyzLedResource, '/xyzled')
api.add_resource(resources.CubeResource, '/cube')
api.add_resource(resources.FaceResource, '/face')
api.add_resource(resources.SquareResource, '/square')
api.add_resource(resources.LedstripResource, '/ledstrip')
api.add_resource(resources.LedResource, '/led')
api.add_resource(resources.ChangeMode, '/changemode')
api.add_resource(resources.Token, '/token')
api.add_resource(resources.Sequence, '/seq')
api.add_resource(resources.StartSequence, '/startseq')
api.add_resource(resources.Fps, '/fps')
api.add_resource(resources.Network, '/network')


@app.route('/start')
@jwt_required
@mode_superuser
def start():
    """function for /start