Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python
#
import sys
import cbapi.six as six
from cbapi.response.models import Watchlist
from cbapi.example_helpers import build_cli_parser, get_cb_response_object
import logging
import json
log = logging.getLogger(__name__)
if six.PY3:
confirm_input = input
else:
confirm_input = raw_input # noqa: F821
def confirm(watch_list):
prompt = 'Import watchlist {0}? y/n: '.format(watch_list)
while True:
answer = confirm_input(prompt)
if not answer:
return True
if answer not in ['y', 'Y', 'n', 'N']:
print('Please enter y or n.')
continue
if answer in ['Y', 'y']:
return True
def get_credentials(self, profile=None):
credential_profile = profile or "default"
if credential_profile not in self.get_profiles():
raise CredentialError("Cannot find credential profile '%s' after searching in these files: %s." %
(credential_profile, ", ".join(self.credential_search_path)))
retval = {}
for k, v in six.iteritems(default_profile):
retval[k] = self.credentials.get(credential_profile, k)
if not retval["url"] or not retval["token"]:
raise CredentialError("Token and/or URL not available for profile %s" % credential_profile)
return Credentials(retval)
#!/usr/bin/env python
import argparse
import contextlib
from cbapi.six import iteritems
from six.moves import input
import os
import getpass
import cbapi.six as six
if six.PY3:
from io import StringIO as StringIO
else:
from cStringIO import StringIO
from cbapi.response.rest_api import get_api_token
from six.moves.configparser import RawConfigParser
@contextlib.contextmanager
def temp_umask(umask):
oldmask = os.umask(umask)
try:
yield
finally:
os.umask(oldmask)
def _match_query(self, i):
for k, v in iteritems(self._query):
if isinstance(v, six.string_types):
v = v.lower()
target = getattr(i, k, None)
if target is None:
return False
if str(target).lower() != v:
return False
return True
#!/usr/bin/env python
import argparse
import contextlib
from cbapi.six import iteritems
from six.moves import input
import os
import getpass
import cbapi.six as six
if six.PY3:
from io import StringIO as StringIO
else:
from cStringIO import StringIO
from cbapi.response.rest_api import get_api_token
from six.moves.configparser import RawConfigParser
@contextlib.contextmanager
def temp_umask(umask):
oldmask = os.umask(umask)
try:
yield
finally:
os.umask(oldmask)
#!/usr/bin/env python
import argparse
import contextlib
from cbapi.six import iteritems
from six.moves import input
import os
import getpass
import cbapi.six as six
if six.PY3:
from io import StringIO as StringIO
else:
from cStringIO import StringIO
from cbapi.response.rest_api import get_api_token
from six.moves.configparser import RawConfigParser
@contextlib.contextmanager
def temp_umask(umask):
oldmask = os.umask(umask)
try:
yield
finally:
os.umask(oldmask)
from ..errors import InvalidObjectError, ApiError, TimeoutError
from ..oldmodels import BaseModel, immutable
from ..models import NewBaseModel, MutableBaseModel, CreatableModelMixin
from .utils import convert_from_cb, convert_from_solr, parse_42_guid, convert_event_time, parse_process_guid, \
convert_to_solr
from ..errors import ServerError, InvalidHashError, ObjectNotFoundError
from ..query import SimpleQuery, PaginatedQuery
from .query import Query
from cbapi.six import python_2_unicode_compatible, iteritems
# Get constants for decoding the Netconn events
import socket
if six.PY3:
long = int
from io import BytesIO as StringIO
else:
from cStringIO import StringIO
try:
from functools import total_ordering
except ImportError:
from total_ordering import total_ordering
log = logging.getLogger(__name__)
# class Process(NewBaseModel):
# swagger_meta_file = "response/models/process.yaml"
def __init__(self, product_name, **kwargs):
if product_name not in ("response", "protection", "psc"):
raise CredentialError("Product name {0:s} not valid".format(product_name))
self.credential_search_path = [
os.path.join(os.path.sep, "etc", "carbonblack", "credentials.%s" % product_name),
os.path.join(os.path.expanduser("~"), ".carbonblack", "credentials.%s" % product_name),
os.path.join(".", ".carbonblack", "credentials.%s" % product_name),
]
if "credential_file" in kwargs:
if isinstance(kwargs["credential_file"], six.string_types):
self.credential_search_path = [kwargs["credential_file"]]
elif type(kwargs["credential_file"]) is list:
self.credential_search_path = kwargs["credential_file"]
self.credentials = RawConfigParser(defaults=default_profile)
self.credential_files = self.credentials.read(self.credential_search_path)