Skip to content

Commit

Permalink
Merge pull request #530 from opencybersecurityalliance/k2_apply
Browse files Browse the repository at this point in the history
Kestrel 2 Python Analytics support
  • Loading branch information
pcoccoli authored Jul 1, 2024
2 parents 4a9e176 + 77c50ac commit f0b8e6a
Show file tree
Hide file tree
Showing 37 changed files with 1,049 additions and 184 deletions.
4 changes: 4 additions & 0 deletions packages/kestrel_core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Homepage = "https://github.com/opencybersecurityalliance/kestrel-lang"
Documentation = "https://kestrel.readthedocs.io/"
Repository = "https://github.com/opencybersecurityalliance/kestrel-lang.git"

[project.scripts]
kestrel = "kestrel.cli:kestrel"
ikestrel = "kestrel.cli:ikestrel"

[tool.setuptools.packages.find]
where = ["src"]

Expand Down
2 changes: 1 addition & 1 deletion packages/kestrel_core/src/kestrel/__future__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from typeguard import typechecked

from typeguard import typechecked

"""Entrance to invoke any backward compatibility patch
Expand Down
1 change: 1 addition & 0 deletions packages/kestrel_core/src/kestrel/analytics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .interface import PythonAnalyticsInterface
51 changes: 51 additions & 0 deletions packages/kestrel_core/src/kestrel/analytics/config.py
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
Loading

0 comments on commit f0b8e6a

Please sign in to comment.