Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setPasswd(self, passwd):
salt = s_common.guid()
hashed = s_common.guid((salt, passwd))
self.shadow = (salt, hashed)
self.info['shadow'] = self.shadow
self.save()
def seedOrgAlias(self, prop, valu, **props):
node = self.core.getTufoByProp('ou:org:alias', valu)
if node is None:
node = self.core.formTufoByProp('ou:org', guid(), alias=valu, **props)
return node
async def __anit__(self, link, item):
await s_share.Share.__anit__(self, link, item)
self.doneevent = asyncio.Event(loop=self.loop)
self.exitok = False
self.chunknum = 0
self.wcid = s_common.guid()
self._needfinish = True
async def fini():
if self._needfinish:
await self.finish()
self.doneevent.set()
self.onfini(fini)
def __init__(self, sock, **info):
EventBus.__init__(self)
self.sock = sock # type: socket.socket
self.unpk = msgpack.Unpacker(use_list=False, encoding='utf8',
unicode_errors='surrogatepass')
self.iden = s_common.guid()
self.info = info
self.blocking = True # sockets are blocking by default
if self.info.get('nodelay', True):
self._tryTcpNoDelay()
self.txbuf = None # the remainder of a partially sent byts
self.txque = collections.deque()
self.rxque = collections.deque()
self.onfini(self._finiSocket)
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)
tick = s_common.now()
iden = s_common.guid()
props.update(subs)
# create a "full" props dict which includes defaults
fulls = self._normTufoProps(prop, props)
self._addDefProps(prop, fulls)
fulls[prop] = valu
# Set universal node values
fulls['tufo:form'] = prop
fulls['node:created'] = s_common.now()
fulls['node:ndef'] = s_common.guid((prop, valu))
# fulls['node:ndef'] = self.reqPropNorm('node:ndef', (prop, valu))[0]
# Examine the fulls dictionary and identify any props which are
# themselves forms, and extract the form/valu/subs from the fulls
# dictionary so we can later make those nodes
toadds = None
if self.autoadd:
toadds = self._formToAdd(prop, fulls)
# Remove any non-model props present in the props and fulls
# dictionary which may have been added during _normTufoProps
self._pruneFulls(prop, fulls, props, isadd=True)
# update our runtime form counters
self.formed[prop] += 1
def _getSyncIden(self):
iden = s_common.guid()
evnt = asyncio.Event()
self.syncevents[iden] = evnt
return iden, evnt
Note:
This changes directories and hive data, not existing View or Layer objects
TODO: due to our migration policy, remove in 0.3.0
'''
# pre-hive -> hive layer directory migration first
self._migrOrigLayer()
defiden = self.cellinfo.get('defaultview')
if defiden is not None:
# No need for migration; we're up-to-date
return
oldlayriden = self.iden
newlayriden = s_common.guid()
oldviewiden = self.iden
newviewiden = s_common.guid()
if not await self.hive.exists(('cortex', 'views', oldviewiden)):
# No view info present; this is a fresh cortex
return
await self.hive.rename(('cortex', 'views', oldviewiden), ('cortex', 'views', newviewiden))
logger.info('Migrated view from duplicate iden %s to new iden %s', oldviewiden, newviewiden)
# Move view/layer metadata
await self.hive.rename(('cortex', 'layers', oldlayriden), ('cortex', 'layers', newlayriden))
logger.info('Migrated layer from duplicate iden %s to new iden %s', oldlayriden, newlayriden)
# Move layer data
def _normPyStr(self, valu):
if valu == '*':
valu = s_common.guid()
return valu, {}
valu = valu.lower()
if not s_common.isguid(valu):
raise s_exc.BadTypeValu(name=self.name, valu=valu,
mesg='valu is not a guid.')
return valu, {}
TODO: due to our migration policy, remove in 0.3.0
'''
# pre-hive -> hive layer directory migration first
self._migrOrigLayer()
defiden = self.cellinfo.get('defaultview')
if defiden is not None:
# No need for migration; we're up-to-date
return
oldlayriden = self.iden
newlayriden = s_common.guid()
oldviewiden = self.iden
newviewiden = s_common.guid()
if not await self.hive.exists(('cortex', 'views', oldviewiden)):
# No view info present; this is a fresh cortex
return
await self.hive.rename(('cortex', 'views', oldviewiden), ('cortex', 'views', newviewiden))
logger.info('Migrated view from duplicate iden %s to new iden %s', oldviewiden, newviewiden)
# Move view/layer metadata
await self.hive.rename(('cortex', 'layers', oldlayriden), ('cortex', 'layers', newlayriden))
logger.info('Migrated layer from duplicate iden %s to new iden %s', oldlayriden, newlayriden)
# Move layer data
oldpath = os.path.join(self.dirn, 'layers', oldlayriden)
newpath = os.path.join(self.dirn, 'layers', newlayriden)
os.rename(oldpath, newpath)