Skip to content

Commit 6916896

Browse files
authored
CM-37862 - Integrate Sentry (#235)
1 parent 45a2360 commit 6916896

28 files changed

+291
-13
lines changed

cycode/cli/commands/auth/auth_command.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from cycode.cli.exceptions.custom_exceptions import AuthProcessError, HttpUnauthorizedError, NetworkError
55
from cycode.cli.models import CliError, CliErrors, CliResult
66
from cycode.cli.printers import ConsolePrinter
7+
from cycode.cli.sentry import add_breadcrumb, capture_exception
78
from cycode.cli.user_settings.credentials_manager import CredentialsManager
9+
from cycode.cli.utils.jwt_utils import get_user_and_tenant_ids_from_access_token
810
from cycode.cyclient import logger
911
from cycode.cyclient.cycode_token_based_client import CycodeTokenBasedClient
1012

@@ -15,6 +17,8 @@
1517
@click.pass_context
1618
def auth_command(context: click.Context) -> None:
1719
"""Authenticates your machine."""
20+
add_breadcrumb('auth')
21+
1822
if context.invoked_subcommand is not None:
1923
# if it is a subcommand, do nothing
2024
return
@@ -37,9 +41,10 @@ def auth_command(context: click.Context) -> None:
3741
@click.pass_context
3842
def authorization_check(context: click.Context) -> None:
3943
"""Validates that your Cycode account has permission to work with the CLI."""
44+
add_breadcrumb('check')
45+
4046
printer = ConsolePrinter(context)
4147

42-
passed_auth_check_res = CliResult(success=True, message='Cycode authentication verified')
4348
failed_auth_check_res = CliResult(success=False, message='Cycode authentication failed')
4449

4550
client_id, client_secret = CredentialsManager().get_credentials()
@@ -48,9 +53,21 @@ def authorization_check(context: click.Context) -> None:
4853
return
4954

5055
try:
51-
if CycodeTokenBasedClient(client_id, client_secret).get_access_token():
52-
printer.print_result(passed_auth_check_res)
56+
access_token = CycodeTokenBasedClient(client_id, client_secret).get_access_token()
57+
if not access_token:
58+
printer.print_result(failed_auth_check_res)
5359
return
60+
61+
user_id, tenant_id = get_user_and_tenant_ids_from_access_token(access_token)
62+
printer.print_result(
63+
CliResult(
64+
success=True,
65+
message='Cycode authentication verified',
66+
data={'user_id': user_id, 'tenant_id': tenant_id},
67+
)
68+
)
69+
70+
return
5471
except (NetworkError, HttpUnauthorizedError):
5572
ConsolePrinter(context).print_exception()
5673

@@ -78,4 +95,6 @@ def _handle_exception(context: click.Context, e: Exception) -> None:
7895
if isinstance(e, click.ClickException):
7996
raise e
8097

98+
capture_exception(e)
99+
81100
raise click.ClickException(str(e))

cycode/cli/commands/configure/configure_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import click
44

55
from cycode.cli import config, consts
6+
from cycode.cli.sentry import add_breadcrumb
67
from cycode.cli.user_settings.configuration_manager import ConfigurationManager
78
from cycode.cli.user_settings.credentials_manager import CredentialsManager
89
from cycode.cli.utils.string_utils import obfuscate_text
@@ -26,6 +27,8 @@
2627
@click.command(short_help='Initial command to configure your CLI client authentication.')
2728
def configure_command() -> None:
2829
"""Configure your CLI client authentication manually."""
30+
add_breadcrumb('configure')
31+
2932
global_config_manager = _CONFIGURATION_MANAGER.global_config_file_manager
3033

3134
current_api_url = global_config_manager.get_api_url()

cycode/cli/commands/ignore/ignore_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from cycode.cli import consts
77
from cycode.cli.config import config, configuration_manager
8+
from cycode.cli.sentry import add_breadcrumb
89
from cycode.cli.utils.path_utils import get_absolute_path
910
from cycode.cli.utils.string_utils import hash_string_to_sha256
1011
from cycode.cyclient import logger
@@ -67,6 +68,8 @@ def ignore_command(
6768
by_value: str, by_sha: str, by_path: str, by_rule: str, by_package: str, scan_type: str, is_global: bool
6869
) -> None:
6970
"""Ignores a specific value, path or rule ID."""
71+
add_breadcrumb('ignore')
72+
7073
if not by_value and not by_sha and not by_path and not by_rule and not by_package:
7174
raise click.ClickException('ignore by type is missing')
7275

cycode/cli/commands/report/report_command.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import click
22

33
from cycode.cli.commands.report.sbom.sbom_command import sbom_command
4+
from cycode.cli.sentry import add_breadcrumb
45
from cycode.cli.utils.progress_bar import SBOM_REPORT_PROGRESS_BAR_SECTIONS, get_progress_bar
56

67

@@ -15,5 +16,6 @@ def report_command(
1516
context: click.Context,
1617
) -> int:
1718
"""Generate report."""
19+
add_breadcrumb('report')
1820
context.obj['progress_bar'] = get_progress_bar(hidden=False, sections=SBOM_REPORT_PROGRESS_BAR_SECTIONS)
1921
return 1

cycode/cli/commands/report/sbom/path/path_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from cycode.cli.files_collector.path_documents import get_relevant_documents
99
from cycode.cli.files_collector.sca.sca_code_scanner import perform_pre_scan_documents_actions
1010
from cycode.cli.files_collector.zip_documents import zip_documents
11+
from cycode.cli.sentry import add_breadcrumb
1112
from cycode.cli.utils.get_api_client import get_report_cycode_client
1213
from cycode.cli.utils.progress_bar import SbomReportProgressBarSection
1314

@@ -16,6 +17,8 @@
1617
@click.argument('path', nargs=1, type=click.Path(exists=True, resolve_path=True), required=True)
1718
@click.pass_context
1819
def path_command(context: click.Context, path: str) -> None:
20+
add_breadcrumb('path')
21+
1922
client = get_report_cycode_client()
2023
report_parameters = context.obj['report_parameters']
2124
output_format = report_parameters.output_format

cycode/cli/commands/report/sbom/repository_url/repository_url_command.py

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

55
from cycode.cli.commands.report.sbom.common import create_sbom_report, send_report_feedback
66
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
7+
from cycode.cli.sentry import add_breadcrumb
78
from cycode.cli.utils.get_api_client import get_report_cycode_client
89
from cycode.cli.utils.progress_bar import SbomReportProgressBarSection
910

@@ -12,6 +13,8 @@
1213
@click.argument('uri', nargs=1, type=str, required=True)
1314
@click.pass_context
1415
def repository_url_command(context: click.Context, uri: str) -> None:
16+
add_breadcrumb('repository_url')
17+
1518
progress_bar = context.obj['progress_bar']
1619
progress_bar.start()
1720
progress_bar.set_section_length(SbomReportProgressBarSection.PREPARE_LOCAL_FILES)

cycode/cli/commands/report/sbom/sbom_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from cycode.cli.commands.report.sbom.path.path_command import path_command
77
from cycode.cli.commands.report.sbom.repository_url.repository_url_command import repository_url_command
88
from cycode.cli.config import config
9+
from cycode.cli.sentry import add_breadcrumb
910
from cycode.cyclient.report_client import ReportParameters
1011

1112

@@ -64,6 +65,8 @@ def sbom_command(
6465
include_dev_dependencies: bool,
6566
) -> int:
6667
"""Generate SBOM report."""
68+
add_breadcrumb('sbom')
69+
6770
sbom_format_parts = format.split('-')
6871
if len(sbom_format_parts) != 2:
6972
raise click.ClickException('Invalid SBOM format.')

cycode/cli/commands/scan/commit_history/commit_history_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from cycode.cli.commands.scan.code_scanner import scan_commit_range
44
from cycode.cli.exceptions.handle_scan_errors import handle_scan_exception
5+
from cycode.cli.sentry import add_breadcrumb
56
from cycode.cyclient import logger
67

78

@@ -18,6 +19,8 @@
1819
@click.pass_context
1920
def commit_history_command(context: click.Context, path: str, commit_range: str) -> None:
2021
try:
22+
add_breadcrumb('commit_history')
23+
2124
logger.debug('Starting commit history scan process, %s', {'path': path, 'commit_range': commit_range})
2225
scan_commit_range(context, path=path, commit_range=commit_range)
2326
except Exception as e:

cycode/cli/commands/scan/path/path_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import click
44

55
from cycode.cli.commands.scan.code_scanner import scan_disk_files
6+
from cycode.cli.sentry import add_breadcrumb
67
from cycode.cyclient import logger
78

89

910
@click.command(short_help='Scan the files in the path provided in the command.')
1011
@click.argument('paths', nargs=-1, type=click.Path(exists=True, resolve_path=True), required=True)
1112
@click.pass_context
1213
def path_command(context: click.Context, paths: Tuple[str]) -> None:
14+
add_breadcrumb('path')
15+
1316
progress_bar = context.obj['progress_bar']
1417
progress_bar.start()
1518

cycode/cli/commands/scan/pre_commit/pre_commit_command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_diff_file_path,
1212
)
1313
from cycode.cli.models import Document
14+
from cycode.cli.sentry import add_breadcrumb
1415
from cycode.cli.utils.git_proxy import git_proxy
1516
from cycode.cli.utils.path_utils import (
1617
get_path_by_os,
@@ -22,6 +23,8 @@
2223
@click.argument('ignored_args', nargs=-1, type=click.UNPROCESSED)
2324
@click.pass_context
2425
def pre_commit_command(context: click.Context, ignored_args: List[str]) -> None:
26+
add_breadcrumb('pre_commit')
27+
2528
scan_type = context.obj['scan_type']
2629

2730
progress_bar = context.obj['progress_bar']

0 commit comments

Comments
 (0)