Skip to content

Commit b7267fc

Browse files
author
João Silva
committed
!32 feat(ProbelyAPIClient): [#32] Add user-agent to requests Closes #32
1 parent ae87254 commit b7267fc

35 files changed

Lines changed: 527 additions & 342 deletions

examples/call_targets_sdk.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
from typing import List
3+
4+
from probely_cli import list_targets, Probely
5+
from probely_cli.exceptions import ProbelyException
6+
7+
if __name__ == "__main__":
8+
9+
# You can config programmatically
10+
Probely.init(api_key="your_api_key")
11+
12+
targets_list: List[dict]
13+
14+
try:
15+
targets_list = list_targets()
16+
17+
for target in targets_list:
18+
print(json.dumps(target, indent=4))
19+
20+
except ProbelyException as probely_exception:
21+
print("Probely sdk error:", probely_exception)

examples/targets.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

probely_cli/__init__.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
# from probely_cli.sdk.targets import list_targets
2-
#
3-
# from .exceptions import *
4-
# from .sdk.client import Probely
1+
from .sdk.client import Probely
2+
from .sdk.targets import (
3+
list_targets,
4+
retrieve_target,
5+
retrieve_targets,
6+
delete_targets,
7+
add_target,
8+
update_target,
9+
update_targets,
10+
)
11+
from .version import __version__
512

6-
# __all__ = [
7-
# # defines behaviour of "from probely_cli import *"
8-
# # TODO: seems to be a good practice
9-
# ]
13+
__all__ = [
14+
"Probely",
15+
"add_target",
16+
"list_targets",
17+
"retrieve_target",
18+
"retrieve_targets",
19+
# "delete_target",
20+
"delete_targets",
21+
"update_target",
22+
"update_targets",
23+
]

probely_cli/cli/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from rich.console import Console
66

7-
from .app import CliApp
7+
from .app import CLIApp
88
from .commands.parsers import build_cli_parser
99

1010
logger = logging.getLogger(__name__)
@@ -25,7 +25,7 @@ def app():
2525
args.console = console
2626
args.err_console = err_console
2727

28-
cli_app = CliApp(args)
28+
cli_app = CLIApp(args)
2929

3030
from .. import settings
3131

probely_cli/cli/app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import argparse
22
import logging
33

4-
from probely_cli import settings
4+
from probely_cli import settings, Probely
55
from probely_cli.exceptions import ProbelyException, ProbelyCLIValidation
66

77
logger = logging.getLogger(__name__)
88

99

10-
class CliApp:
10+
class CLIApp:
1111
args: argparse.Namespace
1212

1313
def __init__(self, args: argparse.Namespace):
14+
settings.IS_CLI = True
15+
1416
args_dict = vars(args)
1517
if args_dict.get("api_key"):
16-
settings.PROBELY_API_KEY = args.api_key
18+
Probely.init(api_key=args_dict.get("api_key"))
1719

1820
if args_dict.get("debug"):
1921
settings.IS_DEBUG_MODE = True

probely_cli/cli/commands/apply/apply.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import logging
2-
from pathlib import Path
32

4-
from rich.console import Console
5-
from probely_cli.sdk.targets import add_target
3+
from probely_cli.cli.commands.apply.schemas import ApplyFileSchema
4+
from probely_cli.cli.common import validate_and_retrieve_yaml_content
65
from probely_cli.exceptions import (
76
ProbelyException,
87
ProbelyBadRequest,
98
)
10-
from probely_cli.cli.commands.apply.schemas import ApplyFileSchema
11-
from probely_cli.cli.common import validate_and_retrieve_yaml_content
12-
9+
from probely_cli.sdk.targets import add_target
1310

1411
logger = logging.getLogger(__name__)
1512

probely_cli/cli/commands/findings/get.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
from rich.table import Table
1111

1212
from probely_cli.cli.commands.findings.schemas import FindingsApiFiltersSchema
13-
from probely_cli.cli.common import (
14-
FindingSeverityEnum,
15-
OutputEnum,
16-
)
13+
from probely_cli.cli.common import OutputEnum
1714
from probely_cli.cli.formatters import (
1815
get_printable_enum_value,
1916
get_printable_date,
2017
get_printable_labels,
2118
)
2219
from probely_cli.exceptions import ProbelyCLIValidation
20+
from probely_cli.sdk.common import FindingSeverityEnum
2321
from probely_cli.sdk.findings import list_findings
2422
from probely_cli.sdk.findings import retrieve_findings
2523

probely_cli/cli/commands/findings/parsers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from probely_cli.cli.commands.findings.get import findings_get_command_handler
66
from probely_cli.cli.common import (
77
show_help,
8-
FindingSeverityEnum,
9-
FindingStateEnum,
108
)
9+
from probely_cli.sdk.common import FindingSeverityEnum, FindingStateEnum
1110
from probely_cli.settings import TRUTHY_VALUES, FALSY_VALUES
1211

1312

probely_cli/cli/commands/findings/schemas.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
from probely_cli.cli.common import (
44
ProbelyCLIEnumField,
5-
FindingSeverityEnum,
65
ProbelyCLIBaseFiltersSchema,
7-
FindingStateEnum,
86
)
7+
from probely_cli.sdk.common import FindingSeverityEnum, FindingStateEnum
98

109

1110
class FindingsApiFiltersSchema(ProbelyCLIBaseFiltersSchema):

probely_cli/cli/commands/scans/parsers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import argparse
2+
23
from rich_argparse import RichHelpFormatter
34

45
from probely_cli.cli.commands.scans.cancel import scans_cancel_command_handler
56
from probely_cli.cli.commands.scans.get import scans_get_command_handler
6-
from probely_cli.cli.commands.scans.resume import scans_resume_command_handler
77
from probely_cli.cli.commands.scans.pause import scans_pause_command_handler
8-
from probely_cli.cli.common import ScanStatusEnum, show_help
8+
from probely_cli.cli.commands.scans.resume import scans_resume_command_handler
9+
from probely_cli.cli.common import show_help
10+
from probely_cli.sdk.common import ScanStatusEnum
911

1012

1113
def build_scan_filters_parser() -> argparse.ArgumentParser:

0 commit comments

Comments
 (0)