Skip to content

Commit 52345b3

Browse files
author
João Silva
committed
!38 feat(many): [#72 #71 #36 #9] Improve base_api_url, improve README, check package without config, check cofig args Closes #72, #71, #36, and #9
1 parent 03fefaa commit 52345b3

24 files changed

Lines changed: 162 additions & 70 deletions

README.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,57 @@
1-
# probely_cli
1+
# probely
22

3-
## So far this is more like
3+
### Package level api key setup:
44

5-
Generate docs:
5+
* Config File:
6+
Create `~/.probely/config` and add:
67

7-
* go to docs/
8-
* make clean
9-
* make markdown
8+
```
9+
[AUTH]
10+
api_key = <your_api_key>
11+
```
12+
13+
* Environment Variables
14+
```
15+
export PROBELY_API_BASE_URL=<your_api_key>
16+
```
17+
* Tool specific config (see below)
18+
19+
## CLI
20+
21+
### Usage
22+
23+
* Use `-h/--help` for available options
24+
* General usage
25+
`Probely <context> <action> [positional_params ...] [--optinal params ...] -- [positional_params ...]`
26+
* `--` allows you to add positional args after optional
27+
* add `--api-key` for command specific api key
28+
29+
## SDK
30+
31+
* Init `Probely` for specific config
32+
```
33+
from probely_cli import Probely
34+
35+
Probely.init(api_key=<your_api_key>)
36+
37+
...
38+
```
39+
* Import `probely_cli` for public interface
40+
41+
```
42+
import probely_cli
43+
44+
target = probely_cli.add_target("http://target_url.com")
45+
```
1046

1147
### Development guidelines:
1248

1349
* Command structure: `Probely <context> <action> params [--optinal params]`
14-
* Follow CLI output good practices. Valid output to `stdout`, erros to `stderr`
15-
* Check list every step of the MR template(todo)
16-
* Tests
17-
* Docs
18-
* Multiple version CI
50+
* Follow CLI output good practices. Valid output to `stdout`, errors to `stderr`
1951
* Custom tooling, developers should be aware
20-
* `probely_cli` fixture (to test CLI OUTPUT)
2152
* `rich.console` is always available on the `args`
53+
* `probely_cli` fixture (to test CLI OUTPUT)
2254
* Error message should have the following structure: `{cmd}: error: {message}`,
2355
following the default implementation of argparse
2456
* eg: `probely targets get: error: filters and target ids are mutually exclusive.`
25-
* TBD how to handle json errors list
26-
27-
### Usage tips:
2857

29-
* When using multiple values optional arguments you can use `--` to indicate that next
30-
values are positional arguments

examples/call_targets_sdk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import json
22
from typing import List
33

4-
from probely_cli import Probely, list_targets
5-
from probely_cli.exceptions import ProbelyException
4+
from probely_cli import Probely, ProbelyException, list_targets
65

76
if __name__ == "__main__":
87

9-
# You can config programmatically
108
Probely.init(api_key="your_api_key")
119

1210
try:

probely_cli/__init__.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1+
from .exceptions import (
2+
ProbelyApiUnavailable,
3+
ProbelyException,
4+
ProbelyMissConfig,
5+
ProbelyObjectNotFound,
6+
ProbelyRequestFailed,
7+
)
18
from .sdk.client import Probely
9+
from .sdk.enums import (
10+
FindingSeverityEnum,
11+
FindingStateEnum,
12+
ScanStatusEnum,
13+
TargetRiskEnum,
14+
TargetTypeEnum,
15+
)
16+
from .sdk.findings import list_findings, retrieve_finding, retrieve_findings
17+
from .sdk.scans import (
18+
cancel_scan,
19+
cancel_scans,
20+
list_scans,
21+
pause_scan,
22+
pause_scans,
23+
resume_scan,
24+
resume_scans,
25+
retrieve_scan,
26+
retrieve_scans,
27+
start_scan,
28+
start_scans,
29+
)
230
from .sdk.targets import (
331
add_target,
432
delete_target,
@@ -9,7 +37,6 @@
937
update_target,
1038
update_targets,
1139
)
12-
from .version import __version__
1340

1441
__all__ = [
1542
"Probely",
@@ -21,4 +48,29 @@
2148
"delete_targets",
2249
"update_target",
2350
"update_targets",
51+
"list_scans",
52+
"retrieve_scan",
53+
"retrieve_scans",
54+
"start_scan",
55+
"start_scans",
56+
"cancel_scan",
57+
"cancel_scans",
58+
"resume_scan",
59+
"resume_scans",
60+
"pause_scan",
61+
"pause_scans",
62+
"list_findings",
63+
"retrieve_finding",
64+
"retrieve_findings",
65+
"ProbelyException",
66+
"ProbelyObjectNotFound",
67+
"ProbelyMissConfig",
68+
"ProbelyApiUnavailable",
69+
"ProbelyRequestFailed",
70+
"TargetRiskEnum",
71+
"TargetTypeEnum",
72+
"TargetAPISchemaTypeEnum",
73+
"FindingSeverityEnum",
74+
"FindingStateEnum",
75+
"ScanStatusEnum",
2476
]

probely_cli/cli/commands/targets/add.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from probely_cli.cli.common import validate_and_retrieve_yaml_content
1010
from probely_cli.cli.enums import OutputEnum
1111
from probely_cli.exceptions import ProbelyCLIValidation
12-
from probely_cli.sdk.enums import APISchemaTypeEnum, TargetTypeEnum
12+
from probely_cli.sdk.enums import TargetAPISchemaTypeEnum, TargetTypeEnum
1313
from probely_cli.sdk.targets import add_target
1414

1515
logger = logging.getLogger(__name__)
@@ -76,7 +76,7 @@ def get_target_type(args, file_input):
7676

7777
def get_api_schema_type(args, file_input):
7878
if args.api_schema_type:
79-
return APISchemaTypeEnum[args.api_schema_type]
79+
return TargetAPISchemaTypeEnum[args.api_schema_type]
8080

8181
api_schema_type_from_file: Optional[str] = (
8282
file_input.get("site", {})
@@ -86,7 +86,7 @@ def get_api_schema_type(args, file_input):
8686

8787
if api_schema_type_from_file:
8888
try:
89-
return APISchemaTypeEnum.get_by_api_response_value(
89+
return TargetAPISchemaTypeEnum.get_by_api_response_value(
9090
api_schema_type_from_file
9191
)
9292
except ValueError:

probely_cli/cli/commands/targets/get.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
from probely_cli.cli.enums import OutputEnum
1212
from probely_cli.cli.renderers import (
1313
get_printable_date,
14+
get_printable_enum_value,
15+
get_printable_labels,
1416
)
15-
from probely_cli.cli.renderers import get_printable_enum_value, get_printable_labels
1617
from probely_cli.exceptions import ProbelyCLIValidation
1718
from probely_cli.sdk.enums import TargetRiskEnum
1819
from probely_cli.sdk.targets import list_targets, retrieve_targets

probely_cli/cli/commands/targets/parsers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from probely_cli.cli.commands.targets.start_scan import start_scans_command_handler
99
from probely_cli.cli.commands.targets.update import update_targets_command_handler
1010
from probely_cli.cli.common import show_help
11-
from probely_cli.sdk.enums import APISchemaTypeEnum, TargetRiskEnum, TargetTypeEnum
11+
from probely_cli.sdk.enums import (
12+
TargetAPISchemaTypeEnum,
13+
TargetRiskEnum,
14+
TargetTypeEnum,
15+
)
1216
from probely_cli.settings import FALSY_VALUES, TRUTHY_VALUES
1317

1418

@@ -134,7 +138,7 @@ def build_targets_parser(commands_parser, configs_parser, file_parser, output_pa
134138
targets_add_parser.add_argument(
135139
"--api-schema-type",
136140
type=str.upper,
137-
choices=APISchemaTypeEnum.cli_input_choices(),
141+
choices=TargetAPISchemaTypeEnum.cli_input_choices(),
138142
help="Type of schema for API Targets",
139143
)
140144
targets_add_parser.add_argument(

probely_cli/cli/commands/targets/update.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
from probely_cli.cli.common import validate_and_retrieve_yaml_content
1010
from probely_cli.cli.enums import OutputEnum
1111
from probely_cli.exceptions import ProbelyCLIValidation
12-
from probely_cli.sdk.targets import (
13-
update_targets,
14-
list_targets,
15-
update_target,
16-
)
12+
from probely_cli.sdk.targets import list_targets, update_target, update_targets
1713

1814
logger = logging.getLogger(__name__)
1915

probely_cli/cli/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
23
from probely_cli.sdk.enums import ProbelyCLIEnum
34

45

probely_cli/cli/renderers.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import json
22
import sys
33
import textwrap
4-
from typing import Dict, Generator, List, Optional, Type
4+
from typing import Dict, Generator, List, Optional, Type, Union
55

6-
from dateutil import parser
76
import yaml
7+
from dateutil import parser
88
from rich.console import Console
99
from rich.live import Live
1010

1111
from probely_cli.cli.enums import EntityTypeEnum, OutputEnum
1212
from probely_cli.sdk.enums import ProbelyCLIEnum
1313

14-
from typing import Union
15-
16-
1714
UNKNOWN_VALUE_REP = "UNKNOWN"
1815

1916

@@ -57,9 +54,9 @@ def _render_yaml(self) -> None:
5754
self.console.print(yaml.dump([record], indent=2, width=sys.maxsize))
5855

5956
def _render_table(self) -> None:
60-
from probely_cli.cli.tables.table_factory import (
57+
from probely_cli.cli.tables.table_factory import ( # Avoid circular import
6158
TableFactory,
62-
) # Avoid circular import
59+
)
6360

6461
table_cls = TableFactory.get_table_class(self.entity_type)
6562
table = table_cls().create_table(show_header=True)

probely_cli/cli/tables/finding_table.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
from probely_cli.cli.renderers import (
44
get_printable_date,
5+
get_printable_enum_value,
6+
get_printable_labels,
57
)
6-
from probely_cli.cli.renderers import get_printable_enum_value, get_printable_labels
78
from probely_cli.cli.tables.base_table import BaseOutputTable
89
from probely_cli.sdk.enums import FindingSeverityEnum
910

0 commit comments

Comments
 (0)