Esempio n. 1
0
    def create_namespace(self, name, user, permissions=None):
        uid = str(uuid.uuid4()).replace('-', '')
        try:
            self.create(name, {
                'uuid': uid,
                'permissions': {**(permissions or {}), user: Permissions.ADMIN},
                'logger': {
                    'backend': settings.NAMESPACE_BACKENDS['logger'],
                    'settings': get_backend(settings.NAMESPACE_BACKENDS['logger']).settings_for(self.uuid, uid, 'logger')
                },
                'state': {
                    'backend': settings.NAMESPACE_BACKENDS['state'],
                    'settings': get_backend(settings.NAMESPACE_BACKENDS['state']).settings_for(self.uuid, uid, 'state')
                },
                'storage': {
                    'backend': settings.NAMESPACE_BACKENDS['storage'],
                    'settings': get_backend(settings.NAMESPACE_BACKENDS['storage']).settings_for(self.uuid, uid, 'storage')
                }
            }, user)
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code='N409',
                title='Namespace already exists',
                detail='Namespace "{}" already exists'.format(name)
            )

        return self.get_namespace(name)
Esempio n. 2
0
    def __init__(self, name=None):
        self.uuid = self.name = name or 'jam'
        storage_backend = get_backend(
            settings.NAMESPACEMANAGER_BACKENDS['storage'])
        logger_backend = get_backend(
            settings.NAMESPACEMANAGER_BACKENDS['logger'])
        state_backend = get_backend(
            settings.NAMESPACEMANAGER_BACKENDS['state'])

        super().__init__(jam.Storage(
            storage_backend(**storage_backend.settings_for(
                'manager', self.uuid, 'storage'))),
                         jam.Logger(
                             logger_backend(**logger_backend.settings_for(
                                 'manager', self.uuid, 'logger'))),
                         jam.State(
                             state_backend(**state_backend.settings_for(
                                 'manager', self.uuid, 'state'))),
                         schema={
                             'type': 'jsonschema',
                             'schema': Namespace.SCHEMA
                         },
                         permissions={
                             'system-system-*': Permissions.CREATE,
                             'system-system-system': Permissions.ADMIN,
                         })
Esempio n. 3
0
    def create_collection(self, name, user, logger=None, storage=None, state=None, permissions=None, schema=None, plugins=None, **kwargs):
        if kwargs:
            raise exceptions.InvalidFields(kwargs.keys())

        uid = str(uuid.uuid4()).replace('-', '')
        state = state or settings.COLLECTION_BACKENDS['state']
        logger = logger or settings.COLLECTION_BACKENDS['logger']
        storage = storage or settings.COLLECTION_BACKENDS['storage']

        if isinstance(permissions or {}, dict):
            try:
                permissions = {
                    key: Permissions.from_string(value)
                    for key, value in (permissions or {}).items()
                }
                permissions[user] = Permissions.ADMIN
            except KeyError as e:
                raise exceptions.InvalidPermission(e.args[0])
            except AttributeError:
                pass  # Schema validation will catch issues

        collection_dict = {
            'uuid': uid,
            'plugins': plugins or {},
            'schema': schema,
            'permissions': permissions,
            'logger': {
                'backend': logger,
                'settings': get_backend(logger).settings_for(self.uuid, uid, 'logger')
            },
            'state': {
                'backend': state,
                'settings': get_backend(state).settings_for(self.uuid, uid, 'state')
            },
            'storage': {
                'backend': storage,
                'settings': get_backend(storage).settings_for(self.uuid, uid, 'storage')
            }
        }

        # Validate that our inputs can actually be deserialized to a collection
        Collection(Document(
            ref=name,
            log_ref=None,
            data_ref=None,
            created_on=0,
            created_by='',
            modified_on=0,
            modified_by='',
            data=collection_dict,
        ))

        try:
            return Collection(self.create(name, collection_dict, user))
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code='C409',
                title='Collection already exists',
                detail='Collection "{}" already exists in namespace "{}"'.format(name, self.ref)
            )
Esempio n. 4
0
    def create_namespace(self, name, user, permissions=None):
        uid = str(uuid.uuid4()).replace("-", "")
        try:
            self.create(
                name,
                {
                    "uuid": uid,
                    "permissions": {**(permissions or {}), user: Permissions.ADMIN},
                    "logger": {
                        "backend": settings.NAMESPACE_BACKENDS["logger"],
                        "settings": get_backend(settings.NAMESPACE_BACKENDS["logger"]).settings_for(
                            self.uuid, uid, "logger"
                        ),
                    },
                    "state": {
                        "backend": settings.NAMESPACE_BACKENDS["state"],
                        "settings": get_backend(settings.NAMESPACE_BACKENDS["state"]).settings_for(
                            self.uuid, uid, "state"
                        ),
                    },
                    "storage": {
                        "backend": settings.NAMESPACE_BACKENDS["storage"],
                        "settings": get_backend(settings.NAMESPACE_BACKENDS["storage"]).settings_for(
                            self.uuid, uid, "storage"
                        ),
                    },
                },
                user,
            )
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code="N409", title="Namespace already exists", detail='Namespace "{}" already exists'.format(name)
            )

        return self.get_namespace(name)
Esempio n. 5
0
    def create_namespace(self, name, user, permissions=None, **kwargs):
        if kwargs:
            raise exceptions.InvalidFields(kwargs.keys())

        uid = str(uuid.uuid4()).replace('-', '')

        if isinstance(permissions or {}, dict):
            try:
                permissions = {
                    key: Permissions.from_string(value)
                    for key, value in (permissions or {}).items()
                }
                permissions[user] = Permissions.ADMIN
            except KeyError as e:
                raise exceptions.InvalidPermission(e.args[0])
            except AttributeError:
                pass  # Schema validation will catch issues

        try:
            self.create(
                name, {
                    'uuid': uid,
                    'permissions': {
                        **(permissions or {}), user: Permissions.ADMIN
                    },
                    'logger': {
                        'backend':
                        settings.NAMESPACE_BACKENDS['logger'],
                        'settings':
                        get_backend(settings.NAMESPACE_BACKENDS['logger']).
                        settings_for(self.uuid, uid, 'logger')
                    },
                    'state': {
                        'backend':
                        settings.NAMESPACE_BACKENDS['state'],
                        'settings':
                        get_backend(
                            settings.NAMESPACE_BACKENDS['state']).settings_for(
                                self.uuid, uid, 'state')
                    },
                    'storage': {
                        'backend':
                        settings.NAMESPACE_BACKENDS['storage'],
                        'settings':
                        get_backend(settings.NAMESPACE_BACKENDS['storage']).
                        settings_for(self.uuid, uid, 'storage')
                    }
                }, user)
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code='N409',
                title='Namespace already exists',
                detail='Namespace "{}" already exists'.format(name))

        return self.get_namespace(name)
Esempio n. 6
0
    def __init__(self, name=None):
        self.uuid = self.name = name or "jam"
        storage_backend = get_backend(settings.NAMESPACEMANAGER_BACKENDS["storage"])
        logger_backend = get_backend(settings.NAMESPACEMANAGER_BACKENDS["logger"])
        state_backend = get_backend(settings.NAMESPACEMANAGER_BACKENDS["state"])

        super().__init__(
            jam.Storage(storage_backend(**storage_backend.settings_for("manager", self.uuid, "storage"))),
            jam.Logger(logger_backend(**logger_backend.settings_for("manager", self.uuid, "logger"))),
            jam.State(state_backend(**state_backend.settings_for("manager", self.uuid, "state"))),
        )
Esempio n. 7
0
    def __init__(self, name=None):
        self.uuid = self.name = name or 'jam'
        storage_backend = get_backend(settings.NAMESPACEMANAGER_BACKENDS['storage'])
        logger_backend = get_backend(settings.NAMESPACEMANAGER_BACKENDS['logger'])
        state_backend = get_backend(settings.NAMESPACEMANAGER_BACKENDS['state'])

        super().__init__(
            jam.Storage(storage_backend(**storage_backend.settings_for('manager', self.uuid, 'storage'))),
            jam.Logger(logger_backend(**logger_backend.settings_for('manager', self.uuid, 'logger'))),
            jam.State(state_backend(**state_backend.settings_for('manager', self.uuid, 'state'))),
            schema={'type': 'jsonschema', 'schema': Namespace.SCHEMA}
        )
Esempio n. 8
0
    def create_namespace(self, name, user, permissions=None, **kwargs):
        if kwargs:
            raise exceptions.InvalidFields(kwargs.keys())

        uid = str(uuid.uuid4()).replace('-', '')

        if isinstance(permissions or {}, dict):
            try:
                permissions = {
                    key: Permissions.from_string(value)
                    for key, value in (permissions or {}).items()
                }
                permissions[user] = Permissions.ADMIN
            except KeyError as e:
                raise exceptions.InvalidPermission(e.args[0])
            except AttributeError:
                pass  # Schema validation will catch issues

        try:
            self.create(name, {
                'uuid': uid,
                'permissions': {**(permissions or {}), user: Permissions.ADMIN},
                'logger': {
                    'backend': settings.NAMESPACE_BACKENDS['logger'],
                    'settings': get_backend(settings.NAMESPACE_BACKENDS['logger']).settings_for(self.uuid, uid, 'logger')
                },
                'state': {
                    'backend': settings.NAMESPACE_BACKENDS['state'],
                    'settings': get_backend(settings.NAMESPACE_BACKENDS['state']).settings_for(self.uuid, uid, 'state')
                },
                'storage': {
                    'backend': settings.NAMESPACE_BACKENDS['storage'],
                    'settings': get_backend(settings.NAMESPACE_BACKENDS['storage']).settings_for(self.uuid, uid, 'storage')
                }
            }, user)
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code='N409',
                title='Namespace already exists',
                detail='Namespace "{}" already exists'.format(name)
            )

        return self.get_namespace(name)
Esempio n. 9
0
    def create_collection(self, name, user, logger=None, storage=None, state=None, permissions=None, schema=None):
        uid = str(uuid.uuid4()).replace('-', '')
        state = state or settings.COLLECTION_BACKENDS['state']
        logger = logger or settings.COLLECTION_BACKENDS['logger']
        storage = storage or settings.COLLECTION_BACKENDS['storage']
        if isinstance(permissions or {}, dict):
            permissions = {**(permissions or {}), user: Permissions.ADMIN}

        collection_dict = {
            'uuid': uid,
            'schema': schema,
            'permissions': permissions,
            'logger': {
                'backend': logger,
                'settings': get_backend(logger).settings_for(self.uuid, uid, 'logger')
            },
            'state': {
                'backend': state,
                'settings': get_backend(state).settings_for(self.uuid, uid, 'state')
            },
            'storage': {
                'backend': storage,
                'settings': get_backend(storage).settings_for(self.uuid, uid, 'storage')
            }
        }

        # Validate that our inputs can actually be deserialized to a collection
        collection = Collection.from_dict(collection_dict)

        try:
            self.create(name, collection_dict, user)
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code='C409',
                title='Collection already exists',
                detail='Collection "{}" already exists in namespace "{}"'.format(name, self.name)
            )

        return collection
Esempio n. 10
0
 def prerequisite_check(self):
     super().prerequisite_check()
     if not isinstance(self.collection._state._backend.raw_backend(),
                       get_backend('elasticsearch')):
         raise exceptions.BadRequest(
             detail='This collection does not support searching')
Esempio n. 11
0
    def create_collection(self,
                          name,
                          user,
                          logger=None,
                          storage=None,
                          state=None,
                          permissions=None,
                          schema=None,
                          plugins=None,
                          **kwargs):
        if kwargs:
            raise exceptions.InvalidFields(kwargs.keys())

        uid = str(uuid.uuid4()).replace('-', '')
        state = state or settings.COLLECTION_BACKENDS['state']
        logger = logger or settings.COLLECTION_BACKENDS['logger']
        storage = storage or settings.COLLECTION_BACKENDS['storage']

        if isinstance(permissions or {}, dict):
            try:
                permissions = {
                    key: Permissions.from_string(value)
                    for key, value in (permissions or {}).items()
                }
                permissions[user] = Permissions.ADMIN
            except KeyError as e:
                raise exceptions.InvalidPermission(e.args[0])
            except AttributeError:
                pass  # Schema validation will catch issues

        collection_dict = {
            'uuid': uid,
            'plugins': plugins or {},
            'schema': schema,
            'permissions': permissions,
            'logger': {
                'backend':
                logger,
                'settings':
                get_backend(logger).settings_for(self.uuid, uid, 'logger')
            },
            'state': {
                'backend':
                state,
                'settings':
                get_backend(state).settings_for(self.uuid, uid, 'state')
            },
            'storage': {
                'backend':
                storage,
                'settings':
                get_backend(storage).settings_for(self.uuid, uid, 'storage')
            }
        }

        # Validate that our inputs can actually be deserialized to a collection
        Collection(
            Document(
                ref=name,
                log_ref=None,
                data_ref=None,
                created_on=0,
                created_by='',
                modified_on=0,
                modified_by='',
                data=collection_dict,
            ))

        try:
            return Collection(self.create(name, collection_dict, user))
        except exceptions.KeyExists:
            raise exceptions.KeyExists(
                code='C409',
                title='Collection already exists',
                detail='Collection "{}" already exists in namespace "{}"'.
                format(name, self.ref))
Esempio n. 12
0
 def prerequisite_check(self):
     super().prerequisite_check()
     if not isinstance(self.collection._state._backend.raw_backend(), get_backend('elasticsearch')):
         raise exceptions.BadRequest(detail='This collection does not support searching')