Beispiel #1
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)
Beispiel #2
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)