Skip to content

Commit

Permalink
Fixing requirements for certain functions (#385)
Browse files Browse the repository at this point in the history
* Enforcing API token requirement better.

* Auto-format files

* Version bump.

---------

Co-authored-by: panther-bot-automation <github-service-account-automation@panther.io>
  • Loading branch information
grantjoy and panther-bot-automation committed Oct 19, 2023
1 parent d1c7f48 commit 7e7798e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.30.1
0.30.2
2 changes: 1 addition & 1 deletion panther_analysis_tool/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

PACKAGE_NAME: Final = "panther_analysis_tool"

VERSION_STRING: Final = "0.30.1"
VERSION_STRING: Final = "0.30.2"

CONFIG_FILE = ".panther_settings.yml"
DATA_MODEL_LOCATION = "./data_models"
Expand Down
4 changes: 2 additions & 2 deletions panther_analysis_tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ def setup_parser() -> argparse.ArgumentParser:
validate_parser.add_argument(filter_name, **filter_arg)
validate_parser.add_argument(ignore_files_name, **ignore_files_arg)
validate_parser.add_argument(path_name, **path_arg)
validate_parser.set_defaults(func=pat_utils.func_with_backend(validate.run))
validate_parser.set_defaults(func=pat_utils.func_with_api_backend(validate.run))

# -- zip command

Expand Down Expand Up @@ -1871,7 +1871,7 @@ def setup_parser() -> argparse.ArgumentParser:
help="Required if the rule supports multiple log types, optional otherwise. Must be one of the rule's log"
" types.",
)
benchmark_parser.set_defaults(func=pat_utils.func_with_backend(benchmark.run))
benchmark_parser.set_defaults(func=pat_utils.func_with_api_backend(benchmark.run))

# -- enrich-test-data command
enrich_test_data_parser = subparsers.add_parser(
Expand Down
30 changes: 21 additions & 9 deletions panther_analysis_tool/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def get_client(aws_profile: str, service: str) -> boto3.client:
return client


def func_with_api_backend(
func: Callable[[BackendClient, argparse.Namespace], Any]
) -> Callable[[argparse.Namespace], Tuple[int, str]]:
return lambda args: func(get_api_backend(args), args)


def func_with_backend(
func: Callable[[BackendClient, argparse.Namespace], Any]
) -> Callable[[argparse.Namespace], Tuple[int, str]]:
Expand All @@ -136,6 +142,15 @@ def get_optional_backend(args: argparse.Namespace) -> Optional[BackendClient]:
return None


def get_api_backend(args: argparse.Namespace) -> BackendClient:
if not args.api_token:
raise BackendNotFoundException("This function requires an API token. API token not found.")

return PublicAPIClient(
PublicAPIClientOptions(token=args.api_token, user_id=PANTHER_USER_ID, host=args.api_host)
)


def get_backend(args: argparse.Namespace) -> BackendClient:
if args.api_token:
return PublicAPIClient(
Expand All @@ -146,16 +161,13 @@ def get_backend(args: argparse.Namespace) -> BackendClient:

datalake_lambda = get_datalake_lambda(args)

if hasattr(args, "aws_profile") and args.aws_profile is not None:
return LambdaClient(
LambdaClientOpts(
user_id=PANTHER_USER_ID,
aws_profile=args.aws_profile,
datalake_lambda=datalake_lambda,
)
return LambdaClient(
LambdaClientOpts(
user_id=PANTHER_USER_ID,
aws_profile=args.aws_profile,
datalake_lambda=datalake_lambda,
)

raise BackendNotFoundException("Backend not found.")
)


def get_datalake_lambda(args: argparse.Namespace) -> str:
Expand Down

0 comments on commit 7e7798e

Please sign in to comment.