Esempio n. 1
0
class ApplicationController(MethodView):

    @applicationblp.response(200, SchemaWrapper(sla_schema), content_type="application/json")
    @jwt_required()
    def get(self, appid, *args, **kwargs):
        try:
            current_user = get_jwt_identity()
            return json_util.dumps(get_user_app(current_user, appid))
        except Exception as e:
            return abort(404, {"message": e})

    @jwt_required()
    def delete(self, appid, *args, **kwargs):
        try:
            current_user = get_jwt_identity()
            res = delete_app(appid, current_user)
            if res:
                return {"message": "Application Deleted"}
            else:
                abort(501, {"message": "User could not be deleted"})
        except ConnectionError as e:
            abort(404, {"message": e})

    @jwt_required()
    def put(self, appid, *args, **kwargs):
        print(request.get_json())
        try:
            current_user = get_jwt_identity()
            update_app(appid, current_user, request.get_json())
            return {"message": "Application is updated"}
        except ConnectionError as e:
            abort(404, {"message": e})
Esempio n. 2
0
class MultipleApplicationController(Resource):

    @applicationblp.response(200, SchemaWrapper(applications_schema), content_type="application/json")
    @jwt_required()
    @require_role(Role.ADMIN)
    def get(self, *args, **kwargs):
        return json_util.dumps(mongo_get_all_applications())
Esempio n. 3
0
class ServiceController(MethodView):
    @serviceblp.response(200,
                         SchemaWrapper(sla.schema.sla_microservice_schema),
                         content_type="application/json")
    @jwt_auth_required()
    def get(self, serviceid):
        """Get service for specific ID

        Requires user to own the service
        ---
        """
        username = get_jwt_auth_identity()
        job = service_management.get_service(serviceid, username)
        if job is not None:
            return json_util.dumps(job)
        else:
            return abort(404, "not found")

    @jwt_auth_required()
    @serviceblp.response(200, content_type="application/json")
    def delete(self, serviceid):
        """Remove service with ID

        Requires user to own the service
        ---
        """
        try:
            username = get_jwt_auth_identity()
            if service_management.delete_service(username, serviceid):
                return {"message": "Job deleted"}
            else:
                abort(500, "Job not deleted")
        except ConnectionError as e:
            abort(500, e)

    @serviceblp.arguments(schema=sla.schema.sla_schema,
                          location="json",
                          validate=False,
                          unknown=True)
    @serviceblp.response(200, content_type="application/json")
    @jwt_auth_required()
    def put(self, *args, serviceid):
        """Update service with ID

        Requires user to own the service
        ---
        """
        try:
            username = get_jwt_auth_identity()
            job = (request.get_json()['applications'][0])['microservices'][0]
            if "_id" in job:
                del job['_id']
            result, status = service_management.update_service(
                username, job, serviceid)
            if status != 200:
                abort(status, result)
            return {}
        except ConnectionError as e:
            abort(404, {"message": e})
Esempio n. 4
0
class MultipleServicesController(Resource):
    @serviceblp.response(200,
                         SchemaWrapper(sla.schema.sla_microservices_schema),
                         content_type="application/json")
    @jwt_auth_required()
    @require_role(Role.ADMIN)
    def get(self, *args, **kwargs):
        return json_util.dumps(service_management.get_all_services())
Esempio n. 5
0
class MultipleApplicationControllerUser(Resource):

    @applicationblp.response(200, SchemaWrapper(applications_schema), content_type="application/json")
    @jwt_required()
    def get(self, userid):
        current_user = get_jwt_identity()
        user = mongo_get_user_by_name(current_user)
        if userid != str(user['_id']):
            abort(401, {"message": "Unauthorized"})
        return json_util.dumps(users_apps(current_user))
Esempio n. 6
0
class MultipleServicesControllerUser(Resource):
    @serviceblp.response(200,
                         SchemaWrapper(sla.schema.sla_microservices_schema),
                         content_type="application/json")
    @jwt_auth_required()
    def get(self, appid):
        username = get_jwt_auth_identity()
        result, status = service_management.user_services(appid, username)
        if status != 200:
            abort(status, result)
        return json_util.dumps(result)
Esempio n. 7
0
class ApplicationController(Resource):
    @applicationblp.arguments(schema=sla_schema, location="json", validate=False, unknown=True)
    @applicationblp.response(200, SchemaWrapper(applications_schema), content_type="application/json")
    @jwt_required()
    def post(self, *args, **kwargs):
        data = request.get_json()
        current_user = get_jwt_identity()
        result, code = register_app(data, current_user)
        if code != 200:
            abort(code, result)
        return json_util.dumps(result)
Esempio n. 8
0
class UserPermissionController(MethodView):
    @permissionbp.response(200,
                           schema=SchemaWrapper(auth_schema),
                           content_type="application/json")
    @jwt_auth_required()
    @identity_is_username()
    def get(self, username):
        user = user_get_roles(username)
        print(user)
        if user is not None:
            return {"roles": user['roles']}
        else:
            return abort(404, {"message": "User does not exist."})