コード例 #1
0
ファイル: auto_acquire.py プロジェクト: meeehow/GiftStick
    def _ParseLoggingArguments(self, options):
        """Parses the --logging flag.

    Args:
      options (argparse.Namespace): the parsed command-line arguments.
    Raises:
      errors.BadConfigOption: if the options are invalid.
    """
        logging.basicConfig(
            level=logging.INFO,
            format='%(asctime)s - %(levelname)s - %(name)s - %(message)s')
        self._logger = logging.getLogger(self.__class__.__name__)

        if 'stackdriver' in options.logging:
            if not self._gcs_settings:
                raise errors.BadConfigOption(
                    'Please provide a valid --gs_keyfile to enable StackDriver '
                    'logging')
            gcp_credentials = service_account.Credentials.from_service_account_file(
                options.gs_keyfile)
            project_id = self._gcs_settings.get('project_id', None)

            gcp_logging_client = google_logging.Client(
                project=project_id, credentials=gcp_credentials)
            self._stackdriver_handler = CloudLoggingHandler(gcp_logging_client,
                                                            name='GiftStick')
            self._logger.addHandler(self._stackdriver_handler)

        if options.log_progress:
            if 'stackdriver' not in options.logging:
                raise errors.BadConfigOption(
                    'Progress logging requires Stackdriver logging to be enabled'
                )
            self._progress_logger = google_logging.logger.Logger(
                'GiftStick', gcp_logging_client)
コード例 #2
0
    def _MakeUploader(self, options):
        """Creates a new Uploader object.

    This instantiates the proper Uploader object to handle the destination URL
    argument.

    Args:
      options (argparse.Namespace): the parsed command-line arguments.
    Returns:
      Uploader: an uploader object.
    Raises:
      errors.BadConfigOption: if the options are invalid.
    """

        stamp_manager = manager.StampManager()

        if options.destination.startswith('gs://'):
            if not self._gcs_settings:
                raise errors.BadConfigOption(
                    'Please provide a valid GCS json file. '
                    'See --gs_keyfile option')

            client_id = self._gcs_settings.get('client_id', None)

            if not client_id:
                raise errors.BadConfigOption(
                    'The provided GCS json file lacks a "client_id" key.')

            return uploader.GCSUploader(options.destination,
                                        options.gs_keyfile, client_id,
                                        stamp_manager)

        return None
コード例 #3
0
ファイル: auto_acquire.py プロジェクト: meeehow/GiftStick
    def ParseArguments(self, args):
        """Parses the arguments.

    Args:
      args (list): list of arguments.
    Returns:
      argparse.Namespace: parsed command line arguments.
    Raises:
      BadConfigOption: if the arguments are not specified properly.
    """
        parser = self._CreateParser()
        options = parser.parse_args(args)

        self._ParseRecipes(options)
        self._gcs_settings = self._ParseGCSJSON(options)
        self._ParseLoggingArguments(options)

        if options.select_disks and 'disk' not in options.acquire:
            raise errors.BadConfigOption(
                ('--select_disks needs the disk recipe ('
                 'current recipes : {0:s})').format(', '.join(
                     options.acquire)))

        if not options.no_zenity:
            # force no_zenity to True if zenity is not installed
            zenity_path = hostinfo.Which('zenity')
            if not zenity_path:
                options.no_zenity = True

        return options
コード例 #4
0
  def __init__(self, recipes=None):
    """Instantiates the AutoForensicate object.

    Args:
      recipes (dict[str, BaseRecipe]): the dict listing available recipes.
    Raises:
      errors.BadConfigOption: if no available recipes dict is passed.
    """
    if recipes is None:
      raise errors.BadConfigOption('The recipes argument must not be None')

    self._errors = []
    self._gcs_settings = None
    self._logger = None
    self._recipes = recipes
    self._uploader = None
    self._should_retry = False  # True when a recoverable error occurred.
    self._stackdriver_handler = None  # Stackdriver backed logging handler.
コード例 #5
0
ファイル: auto_acquire.py プロジェクト: rcpklmc/GiftStick
    def ParseArguments(self, args):
        """Parses the arguments.

    Args:
      args (list): list of arguments.
    Returns:
      argparse.Namespace: parsed command line arguments.
    """
        parser = self._CreateParser()
        options = parser.parse_args(args)

        self._ParseRecipes(options)
        self._gcs_settings = self._ParseGCSJSON(options)
        self._ParseLoggingArguments(options)

        if options.select_disks and 'disk' not in options.acquire:
            raise errors.BadConfigOption(
                '--select_disks needs the disk recipe (current recipes : {0})'.
                format(', '.join(options.acquire)))

        return options