Ejemplo n.º 1
0
def default_object(ds):
    backend = MagicMock()
    ds.return_value = backend

    obj = SearchHandler("random")
    obj.init_with_config("random")

    return obj, backend
Ejemplo n.º 2
0
def test_default(ds):
    ds.return_value = "random_drive_store"

    sh = SearchHandler("random_subcommand")
    sh.init_with_config("random_config")

    assert sh.subcommand == "random_subcommand"
    assert sh.backend == "random_drive_store"
    ds.assert_called_once_with("random_config")
    print(ds.return_value)
Ejemplo n.º 3
0
class TagHandler(BaseHandler):
    """
    This class is used to tag *uploaded* files. Tags currently are just strings
    that are added in the file's description field.
    These tags are of the form: "<tag>:<value>"

    This has two main drawbacks as of now,
        1. No control over the tag types. User can upload any data as tag.
        2. Updating tags is not implemented.

    NOTE: Mechanism to tag file while uploading has not yet been implemented.
    """
    def init_with_config(self, config: Configuration):
        super().init_with_config(config)

        self.backend = DriveStorage(config)
        self.search = SearchHandler(config=config)

    def init_args(self, subparser: _SubParsersAction) -> None:
        parser = super().init_args(subparser)

        parser.add_argument(
            "--for_name",
            action="store",
            metavar="NAME",
            help="Search for items with NAME",
        )
        parser.add_argument(
            "--add_tags",
            action="store",
            nargs="+",
            help="add the provided tags to the search results",
        )

    def execute_command(self, fileId, tags):
        self.backend.tag(fileId, tags)

    def run(self, args: Namespace):

        relevant_files = self.search.execute_command(name=args.for_name,
                                                     tags=None,
                                                     do_and=False)

        filenames = [x[0] for x in relevant_files]
        logger.debug("The following files were found: {}".format(filenames))
        logger.debug("The following tags are going to be added: {}".format(
            args.add_tags))

        file_ids = [x[1] for x in relevant_files]

        for fid in file_ids:
            self.backend.tag(fid, args.add_tags)
Ejemplo n.º 4
0
    def init_with_config(self, config: Configuration):
        super().init_with_config(config)

        self.backend = DriveStorage(config)
        self.db = DBStorage(config)
        self.search = SearchHandler(config=config)
Ejemplo n.º 5
0
class PermissionHandler(BaseHandler):
    """
    This class handles adding permissions to uploaded files.

    This has two main drawbacks as of now,
        1. No control over the tag types. User can upload any data as tag.
        2. Updating tags is not implemented.

    NOTE: Mechanism to tag file while uploading has not yet been implemented.
    """

    def init_with_config(self, config: Configuration):
        super().init_with_config(config)

        self.backend = DriveStorage(config)
        self.db = DBStorage(config)
        self.search = SearchHandler(config=config)

    def init_args(self, subparser: _SubParsersAction) -> None:
        parser = super().init_args(subparser)

        parser.add_argument(
            "action", help="Define what action to take.", choices=["list", "add"]
        )
        parser.add_argument(
            "--for_tags", help="Define which tags to add permissions for ", nargs="+"
        )
        parser.add_argument(
            "--share_with", help="email id of the person to share with."
        )
        parser.add_argument(
            "--not_persistent",
            action="store_true",
            help="If provided, future uploads wont be shared.",
        )

    def execute_command(self):
        pass

    def run(self, args: Namespace):
        if args.action == "add":
            if not args.for_tags:
                logger.critical("--for_tags is required. Try again.")
            elif not args.share_with:
                logger.critical("--share_with is required. Try again.")
            else:
                tags = args.for_tags
                email = args.share_with
                role = "reader"

                if not args.not_persistent:
                    self.db.add_permissions(tags, email, role)
                response = self.search.execute_command(
                    name=None, tags=tags, do_and=False
                )

                for item in response:
                    id = item[1]
                    self.backend.add_permissions_user(fileid=id, email=email, role=role)

        if args.action == "list":
            if args.for_tags is None:
                print(self.db.get_permissions())
            else:
                for tag in args.for_tags:
                    print(self.db.get_permissions(tag))
Ejemplo n.º 6
0
import logging

from ProjectNephos.config import Configuration, CONFIG_FULL_PATH_DEFAULT

from ProjectNephos.handlers.upload import UploadHandler
from ProjectNephos.handlers.search import SearchHandler
from ProjectNephos.handlers.tag import TagHandler
from ProjectNephos.handlers.process import ProcessHandler
from ProjectNephos.handlers.init import InitHandler
from ProjectNephos.handlers.permissions import PermissionHandler
from ProjectNephos.handlers.channels import ChannelHandler
from ProjectNephos.handlers.jobs import JobHandler

ActionHandlers = [
    UploadHandler("upload"),
    SearchHandler("search"),
    TagHandler("tag"),
    ProcessHandler("process"),
    InitHandler("init"),
    PermissionHandler("permission"),
    ChannelHandler("channel"),
    JobHandler("job"),
]


def main():

    # TODO: More information can be added to the definitions below
    parser = argparse.ArgumentParser(prog="nephos")
    parser.add_argument(
        "-v",