From 5cae382b0335755eda68dab4f657d4037ca02182 Mon Sep 17 00:00:00 2001 From: Filipe Spencer Date: Thu, 16 Dec 2021 18:27:25 +0000 Subject: [PATCH] Wrap has_legacy_partition check with try/except --- src/cbapi/response/rest_api.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cbapi/response/rest_api.py b/src/cbapi/response/rest_api.py index 408bdc78..fd8143c8 100644 --- a/src/cbapi/response/rest_api.py +++ b/src/cbapi/response/rest_api.py @@ -7,7 +7,7 @@ from distutils.version import LooseVersion from ..connection import BaseAPI from .models import Process, Binary, Watchlist, Investigation, Alert, ThreatReport, StoragePartition -from ..errors import UnauthorizedError, ApiError +from ..errors import UnauthorizedError, ApiError, ClientError from .cblr import LiveResponseSessionManager from .query import Query @@ -49,10 +49,19 @@ def __init__(self, *args, **kwargs): raise ApiError("CbEnterpriseResponseAPI only supports Cb servers version >= 5.0.0") self._has_legacy_partitions = False - if self.cb_server_version >= LooseVersion('6.0'): - legacy_partitions = [p for p in self.select(StoragePartition) if p.info.get("isLegacy", False)] - if legacy_partitions: - self._has_legacy_partitions = True + try: + if self.cb_server_version >= LooseVersion('6.0'): + legacy_partitions = [p for p in self.select(StoragePartition) if p.info.get("isLegacy", False)] + if legacy_partitions: + self._has_legacy_partitions = True + except ClientError as ce: + # If we get a 403 on this endpoint, ignore during init, + # as we will not be able to work with StoragePartitions regardless + # https://github.com/carbonblack/cbapi-python/issues/303 + if ce.error_code == 403: + pass + else: + raise ce # no intervention self._lr_scheduler = None