(self, task: RebuildTask)
| 215 | return self._all_agents |
| 216 | |
| 217 | def build_data(self, task: RebuildTask) -> None: |
| 218 | enterprise = self.params.enterprise |
| 219 | tree_key = enterprise['unencrypted_tree_key'] |
| 220 | |
| 221 | self._deployments.clear() |
| 222 | deps: List[admin_types.PedmDeployment] = [] |
| 223 | for dep in self.storage.deployments.get_all_entities(): |
| 224 | try: |
| 225 | pd = self.load_deployment(dep, tree_key) |
| 226 | deps.append(pd) |
| 227 | except Exception as e: |
| 228 | self.logger.debug('Deployment "%s" decryption error: %s', dep.deployment_uid, e) |
| 229 | self._deployments.put_entities(deps) |
| 230 | |
| 231 | if task.full_rebuild: |
| 232 | self._agents.clear() |
| 233 | self._policies.clear() |
| 234 | self._collections.clear() |
| 235 | self._approvals.clear() |
| 236 | else: |
| 237 | if task.agents is not None: |
| 238 | self._agents.delete_uids(task.agents) |
| 239 | if task.policies is not None: |
| 240 | self._policies.delete_uids(task.policies) |
| 241 | if task.collections is not None: |
| 242 | self._collections.delete_uids(task.collections) |
| 243 | if task.approvals is not None: |
| 244 | self._approvals.delete_uids(task.approvals) |
| 245 | |
| 246 | def get_agents() -> Iterable[admin_storage.PedmStorageAgent]: |
| 247 | if task.full_rebuild: |
| 248 | yield from self.storage.agents.get_all_entities() |
| 249 | if task.agents is not None: |
| 250 | for agent_uid in task.agents: |
| 251 | a = self.storage.agents.get_entity(agent_uid) |
| 252 | if a is not None: |
| 253 | yield a |
| 254 | |
| 255 | ags: List[admin_types.PedmAgent] = [] |
| 256 | for agent_dto in get_agents(): |
| 257 | properties: Optional[Dict[str, Any]] = None |
| 258 | if agent_dto.data is not None and len(agent_dto.data) > 0: |
| 259 | try: |
| 260 | decrypted_data = crypto.decrypt_aes_v2(agent_dto.data, self.agent_key) |
| 261 | properties = json.loads(decrypted_data) |
| 262 | except Exception as e: |
| 263 | self.logger.debug('Agent "%s" decryption error: %s', agent_dto.agent_uid, e) |
| 264 | agent = admin_types.PedmAgent( |
| 265 | agent_uid=agent_dto.agent_uid, machine_id=agent_dto.machine_id, created=agent_dto.created, |
| 266 | deployment_uid=agent_dto.deployment_uid, disabled=agent_dto.disabled, public_key=agent_dto.public_key, |
| 267 | properties=properties) |
| 268 | ags.append(agent) |
| 269 | self._agents.put_entities(ags) |
| 270 | |
| 271 | self._deployment_agents.clear() |
| 272 | das: List[admin_types.PedmDeploymentAgent] = [] |
| 273 | for agent in self._agents.get_all_entities(): |
| 274 | if agent.deployment_uid: |
no test coverage detected