Ejemplo n.º 1
0
    def test_common_config(self):

        confdefs = (
            ('foo', {'defval': 20}),
            ('bar', {'defval': 30}),
        )

        conf = s_common.config({'foo': 80}, confdefs)

        self.eq(80, conf.get('foo'))
        self.eq(30, conf.get('bar'))
Ejemplo n.º 2
0
    async def __anit__(self, dirn, readonly=False):

        await s_base.Base.__anit__(self)

        s_telepath.Aware.__init__(self)

        self.dirn = s_common.gendir(dirn)

        self.auth = None

        # each cell has a guid
        path = s_common.genpath(dirn, 'cell.guid')

        # generate a guid file if needed
        if not os.path.isfile(path):
            with open(path, 'w') as fd:
                fd.write(s_common.guid())

        # read our guid file
        with open(path, 'r') as fd:
            self.iden = fd.read().strip()

        boot = self._loadCellYaml('boot.yaml')
        self.boot = s_common.config(boot, bootdefs)

        conf = self._loadCellYaml('cell.yaml')
        self.conf = s_common.config(conf, self.confdefs + self.confbase)

        self.cmds = {}

        self.boss = await s_boss.Boss.anit()
        self.onfini(self.boss)

        self.cellname = self.boot.get('cell:name')
        if self.cellname is None:
            self.cellname = self.__class__.__name__

        await self._initCellAuth()
        await self._initCellSlab(readonly=readonly)
        await self._initCellHive()
Ejemplo n.º 3
0
    def __init__(self, core):

        self.core = core  # type: synapse.cortex.Cortex
        self.model = core.model  # type: synapse.datamodel.Model

        # Avoid getModPath / getConfPath during __init__ since these APIs
        # will create directories. We do not need that behavior by default.
        self._modpath = os.path.join(self.core.dirn, 'mods', self.getModName())
        self._confpath = os.path.join(self._modpath, 'conf.yaml')
        conf = {}
        if os.path.isfile(self._confpath):
            conf = s_common.yamlload(self._confpath)
        self.conf = s_common.config(conf, self.confdefs)
Ejemplo n.º 4
0
    def test_common_config(self):

        confdefs = (
            ('foo', {
                'defval': 20
            }),
            ('bar', {
                'defval': 30
            }),
        )

        conf = s_common.config({'foo': 80}, confdefs)

        self.eq(80, conf.get('foo'))
        self.eq(30, conf.get('bar'))
Ejemplo n.º 5
0
    def __init__(self, core, conf=None):

        self.core = core
        self.model = core.model
        if self.mod_name is None:
            self.mod_name = self.getModName()

        # Avoid getModPath / getConfPath during __init__ since these APIs
        # will create directories. We do not need that behavior by default.
        self._modpath = os.path.join(self.core.dirn, 'mods', self.getModName())
        self._confpath = os.path.join(self._modpath, 'conf.yaml')

        if conf is None:
            conf = {}

        if os.path.isfile(self._confpath):
            conf = s_common.yamlload(self._confpath)

        self.conf = s_common.config(conf, self.confdefs)
Ejemplo n.º 6
0
    async def __anit__(self, dirn=None, conf=None):

        await s_base.Base.__anit__(self)

        self.dirn = None
        if dirn is not None:
            self.dirn = s_common.gendir(dirn)

        self._shareLoopTasks = set()

        yaml = self._loadDmonYaml()
        if conf is not None:
            yaml.update(conf)

        self.conf = s_common.config(yaml, self.confdefs)
        self.certdir = s_certdir.CertDir(os.path.join(dirn, 'certs'))

        self.mods = {}  # keep refs to mods we load ( mostly for testing )
        self.televers = s_telepath.televers

        self.addr = None  # our main listen address
        self.cells = {}  # all cells are shared.  not all shared are cells.
        self.shared = {}  # objects provided by daemon
        self.listenservers = []  # the sockets we're listening on
        self.connectedlinks = []  # the links we're currently connected on

        self.sessions = {}

        self.mesgfuncs = {
            'tele:syn': self._onTeleSyn,
            'task:init': self._onTaskInit,
            'share:fini': self._onShareFini,

            # task version 2 API
            't2:init': self._onTaskV2Init,
        }

        self.onfini(self._onDmonFini)

        await self._loadDmonConf()
        await self._loadDmonCells()
Ejemplo n.º 7
0
    def __init__(self, core, conf=None):

        self.core = core        # type: synapse.cortex.Cortex
        self.model = core.model # type: synapse.datamodel.Model
        if self.mod_name is None:
            self.mod_name = self.getModName()

        # Avoid getModPath / getConfPath during __init__ since these APIs
        # will create directories. We do not need that behavior by default.
        self._modpath = os.path.join(self.core.dirn,
                                     'mods',
                                     self.getModName())
        self._confpath = os.path.join(self._modpath, 'conf.yaml')

        if conf is None:
            conf = {}

        if os.path.isfile(self._confpath):
            conf = s_common.yamlload(self._confpath)

        self.conf = s_common.config(conf, self.confdefs)
Ejemplo n.º 8
0
    async def __anit__(self, dirn, conf=None, readonly=False):

        await s_base.Base.__anit__(self)

        s_telepath.Aware.__init__(self)

        self.dirn = s_common.gendir(dirn)

        self.auth = None

        # each cell has a guid
        path = s_common.genpath(dirn, 'cell.guid')

        # generate a guid file if needed
        if not os.path.isfile(path):
            with open(path, 'w') as fd:
                fd.write(s_common.guid())

        # read our guid file
        with open(path, 'r') as fd:
            self.iden = fd.read().strip()

        boot = self._loadCellYaml('boot.yaml')
        self.boot = s_common.config(boot, bootdefs)

        await self._initCellDmon()

        if conf is None:
            conf = {}

        [conf.setdefault(k, v) for (k, v) in self._loadCellYaml('cell.yaml').items()]

        self.conf = s_common.config(conf, self.confdefs + self.confbase)

        self.cmds = {}
        self.insecure = self.boot.get('insecure', False)

        self.sessions = {}
        self.httpsonly = self.conf.get('https:only', False)

        self.boss = await s_boss.Boss.anit()
        self.onfini(self.boss)

        await self._initCellSlab(readonly=readonly)

        self.hive = await self._initCellHive()
        self.auth = await self._initCellAuth()

        # check and migrate old cell auth
        oldauth = s_common.genpath(self.dirn, 'auth')
        if os.path.isdir(oldauth):
            await s_compat.cellAuthToHive(oldauth, self.auth)
            os.rename(oldauth, oldauth + '.old')

        admin = self.boot.get('auth:admin')
        if admin is not None:

            name, passwd = admin.split(':', 1)

            user = self.auth.getUserByName(name)
            if user is None:
                user = await self.auth.addUser(name)

            await user.setAdmin(True)
            await user.setPasswd(passwd)
            self.insecure = False

        await self._initCellHttp()

        # self.cellinfo, a HiveDict for general purpose persistent storage
        node = await self.hive.open(('cellinfo',))
        self.cellinfo = await node.dict()
        self.onfini(node)

        self._health_funcs = []
        self.addHealthFunc(self._cellHealth)

        async def fini():
            [await s.fini() for s in self.sessions.values()]

        self.onfini(fini)
Ejemplo n.º 9
0
    async def __anit__(self, dirn, conf=None, readonly=False):

        await s_base.Base.__anit__(self)

        s_telepath.Aware.__init__(self)

        self.dirn = s_common.gendir(dirn)

        self.auth = None

        # each cell has a guid
        path = s_common.genpath(dirn, 'cell.guid')

        # generate a guid file if needed
        if not os.path.isfile(path):
            with open(path, 'w') as fd:
                fd.write(s_common.guid())

        # read our guid file
        with open(path, 'r') as fd:
            self.iden = fd.read().strip()

        boot = self._loadCellYaml('boot.yaml')
        self.boot = s_common.config(boot, bootdefs)

        await self._initCellDmon()

        if conf is None:
            conf = {}

        [conf.setdefault(k, v) for (k, v) in self._loadCellYaml('cell.yaml').items()]

        self.conf = s_common.config(conf, self.confdefs + self.confbase)

        self.cmds = {}
        self.insecure = self.boot.get('insecure', False)

        self.sessions = {}
        self.httpsonly = self.conf.get('https:only', False)

        self.boss = await s_boss.Boss.anit()
        self.onfini(self.boss)

        await self._initCellSlab(readonly=readonly)

        self.hive = await self._initCellHive()
        self.auth = await self._initCellAuth()

        # check and migrate old cell auth
        oldauth = s_common.genpath(self.dirn, 'auth')
        if os.path.isdir(oldauth):
            await s_compat.cellAuthToHive(oldauth, self.auth)
            os.rename(oldauth, oldauth + '.old')

        admin = self.boot.get('auth:admin')
        if admin is not None:

            name, passwd = admin.split(':', 1)

            user = self.auth.getUserByName(name)
            if user is None:
                user = await self.auth.addUser(name)

            await user.setAdmin(True)
            await user.setPasswd(passwd)
            self.insecure = False

        await self._initCellHttp()

        async def fini():
            [await s.fini() for s in self.sessions.values()]

        self.onfini(fini)