Exemple #1
0
from rift.data.handler import get_handler
from rift import log

LOG = log.get_logger()
TENANT_COLLECTION = "tenants"


class Tenant(object):
    def __init__(self, tenant_id, name=None):
        self.tenant_id = tenant_id
        self.name = name

    def as_dict(self):
        return {
            "tenant_id": self.tenant_id,
            "name": self.name,
        }

    @classmethod
    def build_tenant_from_dict(cls, tenant_dict):
        kwargs = {
            'tenant_id': tenant_dict.get("tenant_id"),
            'name': tenant_dict.get("name")
        }
        return Tenant(**kwargs)

    @classmethod
    def save_tenant(cls, tenant):
        db_handler = get_handler()
        db_handler.insert_document(
            object_name=TENANT_COLLECTION, document=tenant.as_dict()
Exemple #2
0
from rift.data.handler import get_handler
from rift import log

LOG = log.get_logger()
TENANT_COLLECTION = "tenants"


class Tenant(object):
    def __init__(self, tenant_id, name=None):
        self.tenant_id = tenant_id
        self.name = name

    def as_dict(self):
        return {
            "tenant_id": self.tenant_id,
            "name": self.name,
        }

    @classmethod
    def build_tenant_from_dict(cls, tenant_dict):
        kwargs = {
            'tenant_id': tenant_dict.get("tenant_id"),
            'name': tenant_dict.get("name")
        }
        return Tenant(**kwargs)

    @classmethod
    def save_tenant(cls, tenant):
        db_handler = get_handler()
        db_handler.insert_document(object_name=TENANT_COLLECTION,
                                   document=tenant.as_dict())
Exemple #3
0
from rift.data.adapters import mongodb
from rift import log

_db_handler = mongodb.MongoDB()

try:
    _db_handler.connect()
except Exception as e:
    log.get_logger().error("Problem connecting to MongoDB: %s", e)


def get_handler():
    return _db_handler