-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #530 from opencybersecurityalliance/k2_apply
Kestrel 2 Python Analytics support
- Loading branch information
Showing
37 changed files
with
1,049 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .interface import PythonAnalyticsInterface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
|
||
from kestrel.config.utils import CONFIG_DIR_DEFAULT, load_user_config | ||
from kestrel.exceptions import InvalidAnalytics | ||
|
||
PROFILE_PATH_DEFAULT = CONFIG_DIR_DEFAULT / "pythonanalytics.yaml" | ||
PROFILE_PATH_ENV_VAR = "KESTREL_PYTHON_ANALYTICS_CONFIG" | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def load_profiles(): | ||
config = load_user_config(PROFILE_PATH_ENV_VAR, PROFILE_PATH_DEFAULT) | ||
if config and "profiles" in config: | ||
_logger.debug(f"python analytics profiles found in config file") | ||
profiles = config["profiles"] | ||
else: | ||
_logger.info("no python analytics config with profiles found") | ||
profiles = {} | ||
_logger.debug(f"profiles loaded: {profiles}") | ||
return profiles | ||
|
||
|
||
def get_profile(profile_name, profiles): | ||
if profile_name not in profiles: | ||
raise InvalidAnalytics( | ||
profile_name, | ||
"python", | ||
f"no {profile_name} configuration found", | ||
) | ||
else: | ||
profile = profiles[profile_name] | ||
_logger.debug(f"profile to use: {profile}") | ||
if "module" not in profile: | ||
raise InvalidAnalytics( | ||
profile_name, | ||
"python", | ||
f"no {profile_name} module defined", | ||
) | ||
else: | ||
module_name = profile["module"] | ||
if "func" not in profile: | ||
raise InvalidAnalytics( | ||
profile_name, | ||
"python", | ||
f"no {profile_name} func defined", | ||
) | ||
else: | ||
func_name = profile["func"] | ||
|
||
return module_name, func_name |
Oops, something went wrong.