Exemplo n.º 1
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        resp.context = {"workers": []}

        validate_not_null(req.params, "name")
        validate_not_null(req.params, "action")
        action = req.params.get("action")
        name = req.params.get("name")
        try:
            resp.context["workers"] = self._controller.list_workers(
                auth_token=auth_token(req))
            self._controller.edit_worker(action=action,
                                         name=name,
                                         auth_token=auth_token(req))

            if action == "reset":
                report_success(resp=resp,
                               description="Worker status refreshed")
            elif action == "delete":
                report_success(resp=resp, description="Worker deleted")
            else:
                report_error(resp=resp, description="Invalid worker action")

            resp.context["workers"] = self._controller.list_workers(
                auth_token=auth_token(req))
        except:
            raise
Exemplo n.º 2
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str):
        def _get_groups():
            result = req.params.get("groups[]", None)
            if isinstance(result, str):
                result = [result]
            return result

        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "groups": []
        }
        try:
            meta = {"groups": _get_groups()}
            meta = self._controller.edit_access_meta(
                store_id=store_id,
                project_id=project_id,
                meta=meta,
                auth_token=auth_token(req))
            resp.context["groups"] = _groups(
                auth_groups=self._controller.get_auth_groups(
                    auth_token=auth_token(req)),
                project_groups=meta.get("groups", []))
        except:
            raise
Exemplo n.º 3
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str):
        validate_not_null(req.params, "project_id")
        validate_not_null(req.params, "project_name")

        project_id = req.params.get("project_id", None)
        project_name = req.params.get("project_name", None)

        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "project_name": project_name,
            "assets": [],
            "workers": {}
        }

        try:
            access = getattr(resp, "auth_user", {})
            self._controller.create_project(store_id=store_id,
                                            project_id=project_id,
                                            project_name=project_name,
                                            groups=access.get(
                                                "write_groups", []),
                                            auth_token=auth_token(req))
            report_success(resp=resp, description="Project created")
        except:
            raise
        finally:
            resp.context["projects"] = self._controller.list_projects(
                store_id, auth_token=auth_token(req))

        raise falcon.HTTPSeeOther('./%s/project/%s' % (store_id, project_id))
Exemplo n.º 4
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str):
        def _get_tags():
            result = req.params.get("tags[]", None)
            if isinstance(result, str):
                result = [result]
            return result

        project = {}
        for field in OveProjectMeta.EDITABLE_FIELDS:
            project[field] = req.params.get(field, "")
        project["tags"] = _get_tags()
        project["video_controller"] = to_bool(
            req.params.get("video_controller", False))
        project["html_controller"] = to_bool(
            req.params.get("html_controller", False))

        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "project": project
        }
        try:
            resp.context["project"] = self._controller.edit_project(
                store_id=store_id,
                project_id=project_id,
                project_data=project,
                auth_token=auth_token(req))
        except:
            raise
Exemplo n.º 5
0
 def on_get(self, req: falcon.Request, resp: falcon.Response, store_id: str,
            project_id: str):
     resp.context = {
         "store_id": store_id,
         "project_id": project_id,
         "assets": [],
         "workers": [],
         "project": {}
     }
     try:
         resp.context["project"] = self._controller.get_project(
             store_id=store_id,
             project_id=project_id,
             auth_token=auth_token(req))
         resp.context["assets"] = self._controller.list_assets(
             store_id=store_id,
             project_id=project_id,
             auth_token=auth_token(req))
         resp.context["workers"] = self._controller.get_worker_types(
             auth_token=auth_token(req))
         resp.context["objects"] = self._controller.check_objects(
             store_id=store_id,
             project_id=project_id,
             object_ids=["project"],
             auth_token=auth_token(req))
         resp.context["launcher_url"] = self._controller.launcher_url
     except:
         raise
Exemplo n.º 6
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        resp.context = {"tasks": []}

        validate_not_null(req.params, "task_id")
        validate_not_null(req.params, "action")
        action = req.params.get("action")
        task_id = req.params.get("task_id")
        try:
            resp.context["tasks"] = self._controller.list_tasks(
                auth_token=auth_token(req))
            self._controller.edit_task(action=action,
                                       task_id=task_id,
                                       auth_token=auth_token(req))

            if action == "reset":
                report_success(resp=resp, description="Task status reset")
            elif action == "cancel":
                report_success(resp=resp, description="Task cancelled")
            else:
                report_error(resp=resp, description="Invalid task action")

            resp.context["tasks"] = self._controller.list_tasks(
                auth_token=auth_token(req))
        except:
            raise
Exemplo n.º 7
0
 def on_get(self, req: falcon.Request, resp: falcon.Response):
     resp.context = {"tasks": []}
     try:
         resp.context["tasks"] = self._controller.list_tasks(
             auth_token=auth_token(req))
     except:
         raise
Exemplo n.º 8
0
    def on_get(self, req: falcon.Request, resp: falcon.Response, store_id: str,
               project_id: str, object_id: str):
        default_object = OBJECT_TEMPLATE.get(object_id, {})

        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "object_id": object_id,
            "object": default_object,
            "create": False
        }
        objects = self._controller.check_objects(store_id=store_id,
                                                 project_id=project_id,
                                                 object_ids=[object_id],
                                                 auth_token=auth_token(req))
        if len(objects) > 0:
            resp.context['file_url'] = objects[0]['index_file']

        try:
            resp.context["object"] = self._controller.get_object(
                store_id=store_id,
                project_id=project_id,
                object_id=object_id,
                auth_token=auth_token(req))
            resp.context["create"] = False
        except:
            resp.context["create"] = True
            resp.context["object"] = default_object
            raise ValidationError(
                title="Not found",
                description="This project does not have a '{}.json' object".
                format(object_id))
Exemplo n.º 9
0
 def on_get(self, req: falcon.Request, resp: falcon.Response,
            store_id: str):
     resp.context = {"store_id": store_id, "projects": []}
     try:
         resp.context["projects"] = self._controller.list_projects(
             store_id, auth_token=auth_token(req))
     except:
         raise
Exemplo n.º 10
0
 def on_get(self, req: falcon.Request, resp: falcon.Response):
     if req.params.get("store-name", None):
         raise falcon.HTTPPermanentRedirect(
             "/view/store/" + req.params.get("store-name", None))
     else:
         resp.context = {
             "stores":
             self._controller.list_stores(auth_token=auth_token(req))
         }
Exemplo n.º 11
0
 def on_get(self, _: falcon.Request, resp: falcon.Response,
            worker_doc: str):
     resp.context = {"worker_doc": worker_doc, "content": ""}
     try:
         with open(self.docs_folder + worker_doc) as fin:
             resp.context["content"] = markdown2.markdown(fin.read())
     except:
         raise falcon.HTTPNotFound(
             title="Docs not found",
             description="'{}' is not available".format(worker_doc))
Exemplo n.º 12
0
 def on_get(self, req: falcon.Request, resp: falcon.Response, store_id: str,
            project_id: str):
     resp.context = {
         "store_id": store_id,
         "project_id": project_id,
         "project": {
             "name": project_id
         }
     }
     try:
         resp.context["project"] = self._controller.get_project(
             store_id=store_id,
             project_id=project_id,
             auth_token=auth_token(req))
     except:
         raise
Exemplo n.º 13
0
 def on_get(self, req: falcon.Request, resp: falcon.Response, store_id: str,
            project_id: str):
     resp.context = {
         "store_id": store_id,
         "project_id": project_id,
         "groups": []
     }
     try:
         meta = self._controller.get_access_meta(
             store_id=store_id,
             project_id=project_id,
             auth_token=auth_token(req)) or {}
         resp.context["groups"] = _groups(
             auth_groups=self._controller.get_auth_groups(
                 auth_token=auth_token(req)),
             project_groups=meta.get("groups", []))
     except:
         raise
Exemplo n.º 14
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str, asset_id: str):
        def _get_tags():
            result = req.params.get("tags[]", None)
            if isinstance(result, str):
                result = [result]
            return result

        asset = {
            "id": req.params.get("id", ""),
            "name": req.params.get("name", ""),
            "project": req.params.get("project", "")
        }
        for field in OveAssetMeta.EDITABLE_FIELDS:
            asset[field] = req.params.get(field, "")
        asset["tags"] = _get_tags()

        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "asset_id": asset_id,
            "create": False,
            "asset": asset
        }

        if asset_id == "new":
            resp.context["create"] = True
            resp.context["asset"] = self._controller.create_asset(
                store_id=store_id,
                project_id=project_id,
                asset=asset,
                auth_token=auth_token(req))
            raise falcon.HTTPPermanentRedirect(
                location="/view/store/{}/project/{}/asset/{}".format(
                    store_id, project_id, asset.get("id")))
        else:
            resp.context["asset"] = self._controller.edit_asset(
                store_id=store_id,
                project_id=project_id,
                asset=asset,
                auth_token=auth_token(req))
Exemplo n.º 15
0
 def on_get(self, req: falcon.Request, resp: falcon.Response, store_id: str,
            project_id: str, asset_id: str):
     resp.context = {
         "store_id": store_id,
         "project_id": project_id,
         "asset_id": asset_id,
         "create": asset_id == "new",
         "asset": {
             "id": asset_id,
             "name": asset_id,
             "project": project_id
         }
     }
     if asset_id != "new":
         try:
             resp.context["asset"] = self._controller.get_asset(
                 store_id=store_id,
                 project_id=project_id,
                 asset_id=asset_id,
                 auth_token=auth_token(req))
         except:
             resp.context["create"] = True
             raise
Exemplo n.º 16
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str, object_id: str):
        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "object_id": object_id,
            "create": False,
            "object": json.loads(req.params.get("object", ""))
        }

        self._controller.set_object(store_id=store_id,
                                    project_id=project_id,
                                    object_id=object_id,
                                    object_data=json.loads(
                                        req.params.get("object", "")),
                                    auth_token=auth_token(req))

        objects = self._controller.check_objects(store_id=store_id,
                                                 project_id=project_id,
                                                 object_ids=[object_id],
                                                 auth_token=auth_token(req))
        if len(objects) > 0:
            resp.context['file_url'] = objects[0]['index_file']
Exemplo n.º 17
0
 def on_get(self, req, resp: Response):
     resp.content_type = MEDIA_JS
     resp.content_type = MEDIA_HTML
     resp.context = {'framework': 'Falcon'}
Exemplo n.º 18
0
 def on_get(self, _: falcon.Request, resp: falcon.Response):
     resp.context = {"backend_url": self._controller.backend_url}