async def _load_all(self): ''' Load all the appointments from persistent storage ''' to_delete = [] for iden, val in self._hivedict.items(): try: appt = _Appt.unpack(self, val) if appt.iden != iden: raise s_exc.InconsistentStorage(mesg='iden inconsistency') self._addappt(iden, appt) self._next_indx = max(self._next_indx, appt.indx + 1) except (s_exc.InconsistentStorage, s_exc.BadStorageVersion, s_exc.BadTime, TypeError, KeyError, UnicodeDecodeError) as e: logger.warning( 'Invalid appointment %r found in storage: %r. Removing.', iden, e) to_delete.append(iden) continue for iden in to_delete: await self._hivedict.pop(iden) # Make sure we don't assign the same index to 2 appointments if self.appts: maxindx = max(appt.indx for appt in self.appts.values()) self._next_indx = maxindx + 1
async def _load_all(self): ''' Load all the appointments from persistent storage ''' # Clear existing appointments before loading self.apptheap = [] self.appts = {} to_delete = [] for iden, node in iter(self._hivenode): val = node.valu try: appt = _Appt.unpack(self, val) if appt.iden != iden: raise s_exc.InconsistentStorage(mesg='iden inconsistency') self._addappt(iden, appt) self._next_indx = max(self._next_indx, appt.indx + 1) except (s_exc.InconsistentStorage, s_exc.BadStorageVersion, s_exc.BadTime, TypeError, KeyError, UnicodeDecodeError) as e: logger.warning('Invalid appointment %r found in storage: %r. Removing.', iden, e) to_delete.append(iden) continue for iden in to_delete: node = self._hivenode.get(iden) if node is not None: await node.hive.pop(node.full) # Make sure we don't assign the same index to 2 appointments if self.appts: maxindx = max(appt.indx for appt in self.appts.values()) self._next_indx = maxindx + 1
async def addAuthGate(self, iden, authgatetype): ''' Retrieve AuthGate by iden. Create if not present. Returns: (HiveAuthGate) ''' gate = self.getAuthGate(iden) if gate is not None: if gate.type != authgatetype: raise s_exc.InconsistentStorage(mesg=f'Stored AuthGate is of type {gate.type}, not {authgatetype}') return gate path = self.node.full + ('authgates', iden) node = await self.node.hive.open(path) await self.node.hive.set(path, authgatetype) return await self._addAuthGate(node)