コード例 #1
0
ファイル: core.py プロジェクト: jbfeldman/connectors
 def _get_configuration(
     cls, config: Dict[str, Any], config_name: str, is_number: bool = False
 ) -> Any:
     yaml_path = cls._get_yaml_path(config_name)
     env_var_name = cls._get_environment_variable_name(yaml_path)
     config_value = get_config_variable(
         env_var_name, yaml_path, config, isNumber=is_number
     )
     return config_value
コード例 #2
0
ファイル: worker.py プロジェクト: timmytimj/opencti
    def __post_init__(self) -> None:
        # Get configuration
        config_file_path = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "config.yml")
        if os.path.isfile(config_file_path):
            with open(config_file_path, "r") as f:
                config = yaml.load(f, Loader=yaml.FullLoader)
        else:
            config = {}

        # Load API config
        self.opencti_url = get_config_variable("OPENCTI_URL",
                                               ["opencti", "url"], config)
        self.opencti_token = get_config_variable("OPENCTI_TOKEN",
                                                 ["opencti", "token"], config)
        self.opencti_ssl_verify = get_config_variable(
            "OPENCTI_SSL_VERIFY", ["opencti", "ssl_verify"], config, False,
            False)
        self.opencti_json_logging = get_config_variable(
            "OPENCTI_JSON_LOGGING", ["opencti", "json_logging"], config)
        # Load worker config
        self.log_level = get_config_variable("WORKER_LOG_LEVEL",
                                             ["worker", "log_level"], config)

        # Check if openCTI is available
        self.api = OpenCTIApiClient(
            url=self.opencti_url,
            token=self.opencti_token,
            log_level=self.log_level,
            ssl_verify=self.opencti_ssl_verify,
            json_logging=self.opencti_json_logging,
        )

        # Configure logger
        numeric_level = getattr(logging, self.log_level.upper(), None)
        if not isinstance(numeric_level, int):
            raise ValueError(f"Invalid log level: {self.log_level}")
        logging.basicConfig(level=numeric_level)

        # Initialize variables
        self.connectors: List[Any] = []
        self.queues: List[Any] = []