Example #1
0
    def on_patch(self, req: falcon.Request, resp: falcon.Response,
                 store_id: str, project_id: str, asset_id: str):
        validate_not_null(req.media, 'action')
        validate_not_null(req.media, 'data')
        validate_list(req.media.get('data'))

        action = req.media.get('action')
        data = req.media.get('data')

        if action not in ['add', 'remove']:
            raise ValidationError(
                title="Invalid action provided",
                description="The action should be either add or remove")

        meta = self._controller.get_asset_meta(store_id=store_id,
                                               project_id=project_id,
                                               asset_id=asset_id)

        new_tags = set(meta.tags)
        if action == 'add':
            new_tags.update(data)
        elif action == 'remove':
            new_tags.difference_update(data)
        meta.tags = list(new_tags)

        self._controller.edit_asset_meta(store_id=store_id,
                                         project_id=project_id,
                                         asset_id=asset_id,
                                         meta=meta)

        resp.media = meta.tags
        resp.status = falcon.HTTP_200
Example #2
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))
Example #3
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
Example #4
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
Example #5
0
    def on_delete(self, req: falcon.Request, resp: falcon.Response):
        _validate_is_admin(req)

        validate_not_null(req.media, 'user')

        self._auth.remove_user(user=req.media.get("user"))
        resp.media = {"result": "OK"}
        resp.status = falcon.HTTP_200
Example #6
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        validate_not_null(req.media, 'user')
        validate_not_null(req.media, 'password')

        token = self._auth.auth_token(user=req.media.get("user"),
                                      password=req.media.get("password"))
        resp.media = {"token": token}
        resp.status = falcon.HTTP_200 if token else falcon.HTTP_401
Example #7
0
    def on_patch(self, req: falcon.Request, resp: falcon.Response):
        validate_not_null(req.media, 'task_id')
        self._worker_manager.reset_task(task_id=req.media.get('task_id'),
                                        user=getattr(req, "user_access",
                                                     UserAccessMeta()))

        resp.media = {"status": "OK"}
        resp.status = falcon.HTTP_200
Example #8
0
    def on_delete(self, req: falcon.Request, resp: falcon.Response):
        _validate_is_admin(req)

        validate_not_null(req.media, 'name')
        self._worker_manager.remove_worker(name=req.media.get('name'))

        resp.media = {"status": "OK"}
        resp.status = falcon.HTTP_200
Example #9
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        _validate_is_admin(req)

        validate_not_null(req.media, 'user')
        validate_not_null(req.media, 'password')

        data = UserAccessMeta(**req.media)

        self._auth.edit_user(access=data,
                             password=req.media.get("password"),
                             add=True)
        resp.media = {"result": "OK"}
        resp.status = falcon.HTTP_200
Example #10
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str):
        _validate_is_admin(req)

        validate_not_null(req.media, 'groups')

        meta = OveProjectAccessMeta(groups=req.media.get("groups", []))
        self._controller.edit_project_access_meta(store_id=store_id,
                                                  project_id=project_id,
                                                  meta=meta)

        resp.media = meta.to_public_json()
        resp.status = falcon.HTTP_200
Example #11
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        validate_not_null(req.params, 'user')
        validate_not_null(req.params, 'password')

        token = self._controller.login(user=req.params.get("user", None),
                                       password=req.params.get(
                                           "password", None))
        if token:
            resp.set_cookie(FIELD_AUTH_TOKEN, token)
            raise falcon.HTTPSeeOther("/")
        else:
            raise ValidationError(title="Invalid login",
                                  description="Invalid username or password")
Example #12
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str):
        validate_not_null(req.media, 'id')
        validate_not_null(req.media, 'name')
        validate_no_slashes(req.media, 'id')

        asset_id = req.media.get('id')
        asset_name = req.media.get('name')

        meta = OveAssetMeta(id=asset_id, name=asset_name, project=project_id)
        self._controller.create_asset(store_id=store_id,
                                      project_id=project_id,
                                      meta=meta)

        resp.media = {'Asset': asset_id}
        resp.status = falcon.HTTP_200
Example #13
0
    def on_patch(self, req: falcon.Request, resp: falcon.Response):
        _validate_is_admin(req)

        validate_not_null(req.media, 'user')

        data = self._auth.get_user(user=req.media.get("user"))
        if not data:
            raise ValidationError(title="Invalid user",
                                  description="User not found")

        for field in UserAccessMeta.EDITABLE_FIELDS:
            if req.media.get(field, None):
                setattr(data, field, req.media.get(field))

        self._auth.edit_user(access=data)
        resp.media = {"result": "OK"}
        resp.status = falcon.HTTP_200
Example #14
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str):
        validate_not_null(req.media, 'name')

        meta = self._controller.get_project_meta(store_id=store_id,
                                                 project_id=project_id)

        for field in OveProjectMeta.EDITABLE_FIELDS:
            if field in req.media:
                setattr(meta, field, req.media.get(field))

        self._controller.edit_project_meta(store_id=store_id,
                                           project_id=project_id,
                                           meta=meta)

        resp.media = meta.to_public_json()
        resp.status = falcon.HTTP_200
Example #15
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str):
        validate_not_null(req.media, 'id')
        validate_not_null(req.media, 'name')
        validate_not_null(req.media, 'groups')

        project_id = req.media.get('id')
        project_name = req.media.get('name')
        project_groups = req.media.get('groups')

        access = getattr(req, "user_access", UserAccessMeta())
        _has_create_access(is_admin=access.admin_access,
                           access_groups=access.write_groups,
                           project_groups=project_groups)

        self._controller.create_project(store_id=store_id,
                                        project_id=project_id)
        self._controller.edit_project_access_meta(
            store_id=store_id,
            project_id=project_id,
            meta=OveProjectAccessMeta(groups=project_groups))

        meta = self._controller.get_project_meta(store_id=store_id,
                                                 project_id=project_id)
        meta.name = project_name
        self._controller.edit_project_meta(store_id=store_id,
                                           project_id=project_id,
                                           meta=meta)

        resp.media = {'Project': project_id}
        resp.status = falcon.HTTP_200
Example #16
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        validate_not_null(req.media, 'store_id')
        validate_not_null(req.media, 'project_id')
        validate_not_null(req.media, 'asset_id')
        validate_not_null(req.media, 'worker_type')

        user = getattr(req, "user_access", UserAccessMeta())
        store_id = req.media.get("store_id")
        project_id = req.media.get("project_id")
        asset_id = req.media.get("asset_id")
        worker_type = req.media.get("worker_type")

        if not self._controller.has_access(store_id=store_id,
                                           project_id=project_id,
                                           groups=user.write_groups,
                                           is_admin=user.admin_access):
            raise falcon.HTTPUnauthorized(
                title="Unable to process asset",
                description="Insufficient write access to process asset")

        store_config = self._controller.get_store_config(store_id=store_id)
        task_options = req.media.get("parameters", dict())
        priority = req.media.get("priority", 1)

        meta = self._controller.get_asset_meta(store_id=store_id,
                                               project_id=project_id,
                                               asset_id=asset_id)
        user = getattr(req, "user_access", UserAccessMeta())
        self._worker_manager.schedule_task(store_id=store_id,
                                           project_id=project_id,
                                           meta=meta,
                                           worker_type=worker_type,
                                           username=user.user,
                                           store_config=store_config,
                                           task_options=task_options,
                                           priority=priority)

        resp.media = {'Status': 'OK'}
        resp.status = falcon.HTTP_200