Exemple #1
0
    def _validate_args(self):
        print(_(messages.INSIGHTS_REQUIRE_SUDO))
        CliCommand._validate_args(self)

        # Validate target report output location
        try:
            validate_write_file(self.tmp_tar_name, 'tmp_tar_name')
        except ValueError:
            print(_(messages.INSIGHTS_TMP_ERROR % self.tmp_tar_name))
            sys.exit(1)

        # Validate Insights client
        if self.args.no_gpg:
            self.insights_command = InsightsCommands(no_gpg=True)
        else:
            self.insights_command = InsightsCommands()
        self._check_insights_install()
        self._check_insights_version()
        print(_(messages.INSIGHTS_IS_VERIFIED))

        # obtaining the report as tar.gz
        if self.args.json_file:
            self._obtain_insights_report_from_local_file()
        else:
            self._obtain_insights_report_from_qpc_server()
Exemple #2
0
    def _validate_args(self):
        CliCommand._validate_args(self)
        if self.args.output_json:
            self.req_headers = {'Accept': 'application/json'}
        if self.args.output_csv:
            self.req_headers = {'Accept': 'text/csv'}

        try:
            validate_write_file(self.args.path, 'output-file')
        except ValueError as error:
            print(error)
            sys.exit(1)

        # Lookup scan job id
        response = request(parser=self.parser, method=GET,
                           path='%s%s' % (scan.SCAN_URI, self.args.scan_id),
                           payload=None)
        if response.status_code == codes.ok:  # pylint: disable=no-member
            json_data = response.json()
            self.fact_collection_id = json_data.get('fact_collection_id')
            if self.fact_collection_id:
                self.req_path = '%s%s' % (
                    self.req_path, self.fact_collection_id)
            else:
                print(_(messages.REPORT_NO_REPORT_FOR_SJ %
                        self.args.scan_id))
                sys.exit(1)
        else:
            print(_(messages.REPORT_SJ_DOES_NOT_EXIST %
                    self.args.scan_id))
            sys.exit(1)
Exemple #3
0
 def _validate_args(self):
     self.req_headers = {'Accept': 'application/gzip'}
     try:
         validate_write_file(self.args.path, 'output-file')
     except ValueError as error:
         print(error)
         sys.exit(1)
     check_extension('tar.gz', self.args.path)
     if self.args.report_id is None:
         # Lookup scan job id
         response = request(parser=self.parser, method=GET,
                            path='%s%s' % (scan.SCAN_JOB_URI,
                                           self.args.scan_job_id),
                            payload=None)
         if response.status_code == codes.ok:  # pylint: disable=no-member
             json_data = response.json()
             self.report_id = json_data.get('report_id')
             if self.report_id:
                 self.req_path = '%s%s' % (self.req_path, self.report_id)
             else:
                 print(_(messages.DOWNLOAD_NO_REPORT_FOR_SJ %
                         self.args.scan_job_id))
                 sys.exit(1)
         else:
             print(_(messages.DOWNLOAD_SJ_DOES_NOT_EXIST %
                     self.args.scan_job_id))
             sys.exit(1)
     else:
         self.report_id = self.args.report_id
         self.req_path = '%s%s' % (self.req_path, self.report_id)
Exemple #4
0
 def _validate_args(self):
     CliCommand._validate_args(self)
     if self.args.path:
         try:
             validate_write_file(self.args.path, 'output-file')
         except ValueError as error:
             print(error)
             sys.exit(1)
Exemple #5
0
    def _validate_args(self):
        CliCommand._validate_args(self)
        extension = None
        if self.args.output_json:
            extension = '.json'
            self.req_headers = {'Accept': 'application/json+gzip'}
        if self.args.output_csv:
            extension = '.csv'
            self.req_headers = {'Accept': 'text/csv'}
        if self.args.mask:
            self.req_params = {'mask': True}
        if extension:
            check_extension(extension, self.args.path)

        try:
            validate_write_file(self.args.path, 'output-file')
        except ValueError as error:
            print(error)
            sys.exit(1)

        if self.args.report_id is None:
            # Lookup scan job id
            response = request(parser=self.parser, method=GET,
                               path='%s%s' % (scan.SCAN_JOB_URI,
                                              self.args.scan_job_id),
                               payload=None)
            if response.status_code == codes.ok:  # pylint: disable=no-member
                json_data = response.json()
                self.report_id = json_data.get('report_id')
                if self.report_id:
                    self.req_path = '%s%s%s' % (
                        self.req_path, self.report_id,
                        report.DEPLOYMENTS_PATH_SUFFIX)
                else:
                    print(_(messages.REPORT_NO_DEPLOYMENTS_REPORT_FOR_SJ %
                            self.args.scan_job_id))
                    sys.exit(1)
            else:
                print(_(messages.REPORT_SJ_DOES_NOT_EXIST %
                        self.args.scan_job_id))
                sys.exit(1)
        else:
            self.report_id = self.args.report_id
            self.req_path = '%s%s%s' % (
                self.req_path, self.report_id,
                report.DEPLOYMENTS_PATH_SUFFIX)