@cryptotaxi247 / CoPilot / commits / 36732e12

Create universal.py

taylor_socfortress committed Jul 10, 2023 at 16:44 UTC 36732e12219e9a06bd80fcacf5c3db6d82a9829c
1 file changed +46
backend/app/services/Shuffle/universal.py new
+46
@@ -0,0 +1,46 @@
1 +from app.models.agents import (
2 + AgentMetadata,
3 + agent_metadata_schema,
4 + agent_metadatas_schema,
5 +)
6 +from typing import Dict, List
7 +from app import db
8 +from datetime import datetime
9 +import requests
10 +from loguru import logger
11 +from elasticsearch7 import Elasticsearch
12 +from app.models.connectors import connector_factory, Connector
13 +
14 +
15 +class UniversalService:
16 + """
17 + A service class that encapsulates the logic for polling messages from the Wazuh-Indexer.
18 + """
19 +
20 + def __init__(self) -> None:
21 + self.collect_shuffle_details("Shuffle")
22 + (
23 + self.connector_url,
24 + self.connector_api_key,
25 + ) = self.collect_shuffle_details("Shuffle")
26 +
27 + def collect_shuffle_details(self, connector_name: str):
28 + """
29 + Collects the details of the Shuffle connector.
30 +
31 + Args:
32 + connector_name (str): The name of the Shuffle connector.
33 +
34 + Returns:
35 + tuple: A tuple containing the connection URL, and api key.
36 + """
37 + connector_instance = connector_factory.create(connector_name, connector_name)
38 + connection_successful = connector_instance.verify_connection()
39 + if connection_successful:
40 + connection_details = Connector.get_connector_info_from_db(connector_name)
41 + return (
42 + connection_details.get("connector_url"),
43 + connection_details.get("connector_api_key"),
44 + )
45 + else:
46 + return None, None