kmip/services/server/monitor.py
def scan_policies(self):
        """
        Scan the policy directory for policy data.
        """
        policy_files = get_json_files(self.policy_directory)
        for f in set(policy_files) - set(self.policy_files):
            self.file_timestamps[f] = 0
        for f in set(self.policy_files) - set(policy_files):
            self.logger.info("Removing policies for file: {}".format(f))
            self.file_timestamps.pop(f, None)
            for p in self.policy_cache.keys():
                self.disassociate_policy_and_file(p, f)
            for p in [k for k, v in self.policy_map.items() if v == f]:
                self.restore_or_delete_policy(p)
        self.policy_files = policy_files

        for f in sorted(self.file_timestamps.keys()):
            t = os.path.getmtime(f)
            if t > self.file_timestamps[f]:
                self.logger.info("Loading policies for file: {}".format(f))
                self.file_timestamps[f] = t
                old_p = [k for k, v in self.policy_map.items() if v == f]
                try:
                    new_p = operation_policy.read_policy_from_file(f)
                except ValueError:
                    self.logger.error("Failure loading file: {}".format(f))
                    self.logger.debug("", exc_info=True)
                    continue
                for p in new_p.keys():
                    self.logger.info("Loading policy: {}".format(p))
                    if p in self.reserved_policies:
                        self.logger.warning(
                            "Policy '{}' overwrites a reserved policy and "
                            "will be thrown out.".format(p)
                        )
                        continue
                    if p in sorted(self.policy_store.keys()):
                        self.logger.debug(
                            "Policy '{}' overwrites an existing "
                            "policy.".format(p)
                        )
                        if f != self.policy_map.get(p):
                            self.policy_cache.get(p).append(
                                (
                                    time.time(),
                                    self.policy_map.get(p),
                                    self.policy_store.get(p)
                                )
                            )
                    else:
                        self.policy_cache[p] = []
                    self.policy_store[p] = new_p.get(p)
                    self.policy_map[p] = f
                for p in set(old_p) - set(new_p.keys()):
                    self.disassociate_policy_and_file(p, f)
                    self.restore_or_delete_policy(p)
def scan_policies(self):
        """
        Scan the policy directory for policy data.
        """
        policy_files = get_json_files(self.policy_directory)
        for f in set(policy_files) - set(self.policy_files):
            self.file_timestamps[f] = 0
        for f in set(self.policy_files) - set(policy_files):
            self.logger.info("Removing policies for file: {}".format(f))
            self.file_timestamps.pop(f, None)
            for p in self.policy_cache.keys():
                self.disassociate_policy_and_file(p, f)
            for p in [k for k, v in self.policy_map.items() if v == f]:
                self.restore_or_delete_policy(p)
        self.policy_files = policy_files

        for f in sorted(self.file_timestamps.keys()):
            t = os.path.getmtime(f)
            if t > self.file_timestamps[f]:
                self.logger.info("Loading policies for file: {}".format(f))
                self.file_timestamps[f] = t
                old_p = [k for k, v in self.policy_map.items() if v == f]
                try:
                    new_p = operation_policy.read_policy_from_file(f)
                except ValueError:
                    self.logger.error("Failure loading file: {}".format(f))
                    self.logger.debug("", exc_info=True)
                    continue
                for p in new_p.keys():
                    self.logger.info("Loading policy: {}".format(p))
                    if p in self.reserved_policies:
                        self.logger.warning(
                            "Policy '{}' overwrites a reserved policy and "
                            "will be thrown out.".format(p)
                        )
                        continue
                    if p in sorted(self.policy_store.keys()):
                        self.logger.debug(
                            "Policy '{}' overwrites an existing "
                            "policy.".format(p)
                        )
                        if f != self.policy_map.get(p):
                            self.policy_cache.get(p).append(
                                (
                                    time.time(),
                                    self.policy_map.get(p),
                                    self.policy_store.get(p)
                                )
                            )
                    else:
                        self.policy_cache[p] = []
                    self.policy_store[p] = new_p.get(p)
                    self.policy_map[p] = f
                for p in set(old_p) - set(new_p.keys()):
                    self.disassociate_policy_and_file(p, f)
                    self.restore_or_delete_policy(p)
def scan_policies ( self ) : policy_files = get_json_files ( self . policy_directory ) for f in set ( policy_files ) - set ( self . policy_files ) : self . file_timestamps [ f ] = 0 for f in set ( self . policy_files ) - set ( policy_files ) : self . logger . info ( "Removing policies for file: {}" . format ( f ) ) self . file_timestamps . pop ( f , None ) for p in self . policy_cache . keys ( ) : self . disassociate_policy_and_file ( p , f ) for p in [ k for k , v in self . policy_map . items ( ) if v == f ] : self . restore_or_delete_policy ( p ) self . policy_files = policy_files for f in sorted ( self . file_timestamps . keys ( ) ) : t = os . path . getmtime ( f ) if t > self . file_timestamps [ f ] : self . logger . info ( "Loading policies for file: {}" . format ( f ) ) self . file_timestamps [ f ] = t old_p = [ k for k , v in self . policy_map . items ( ) if v == f ] try : new_p = operation_policy . read_policy_from_file ( f ) except ValueError : self . logger . error ( "Failure loading file: {}" . format ( f ) ) self . logger . debug ( "" , exc_info = True ) continue for p in new_p . keys ( ) : self . logger . info ( "Loading policy: {}" . format ( p ) ) if p in self . reserved_policies : self . logger . warning ( "Policy '{}' overwrites a reserved policy and " "will be thrown out." . format ( p ) ) continue if p in sorted ( self . policy_store . keys ( ) ) : self . logger . debug ( "Policy '{}' overwrites an existing " "policy." . format ( p ) ) if f != self . policy_map . get ( p ) : self . policy_cache . get ( p ) . append ( ( time . time ( ) , self . policy_map . get ( p ) , self . policy_store . get ( p ) ) ) else : self . policy_cache [ p ] = [ ] self . policy_store [ p ] = new_p . get ( p ) self . policy_map [ p ] = f for p in set ( old_p ) - set ( new_p . keys ( ) ) : self . disassociate_policy_and_file ( p , f ) self . restore_or_delete_policy ( p )
Scan the policy directory for policy data.
Scan the policy directory for policy data .