def _validate_args(self): CliCommand._validate_args(self) if not (self.args.username or self.args.password or self.args.filename or self.args.ssh_passphrase or self.args.become_method or self.args.become_user or self.args.become_password): print(_(messages.CRED_EDIT_NO_ARGS % (self.args.name))) self.parser.print_help() sys.exit(1) # check for existence of credential response = request(parser=self.parser, method=GET, path=credential.CREDENTIAL_URI, params={'name': self.args.name}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() count = json_data.get('count', 0) if count == 1: cred_entry = json_data.get('results')[0] self.cred_type = cred_entry['cred_type'] self.req_path = self.req_path + str(cred_entry['id']) + '/' else: print(_(messages.CRED_DOES_NOT_EXIST % self.args.name)) sys.exit(1) else: print(_(messages.CRED_DOES_NOT_EXIST % self.args.name)) sys.exit(1)
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()
def _validate_args(self): CliCommand._validate_args(self) if 'filename' in self.args and self.args.filename: # check for file existence on system self.args.filename = validate_sshkeyfile(self.args.filename, self.parser)
def _validate_args(self): CliCommand._validate_args(self) if not (self.args.username or self.args.password or self.args.sudo_password or self.args.filename or self.args.ssh_passphrase): print(_(messages.CRED_EDIT_NO_ARGS % (self.args.name))) self.parser.print_help() sys.exit(1) if 'filename' in self.args and self.args.filename: # check for file existence on system self.args.filename = validate_sshkeyfile(self.args.filename, self.parser) # check for existence of credential response = request(parser=self.parser, method=GET, path=credential.CREDENTIAL_URI, params={'name': self.args.name}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() if len(json_data) == 1: cred_entry = json_data[0] self.cred_type = cred_entry['cred_type'] self.req_path = self.req_path + str(cred_entry['id']) + '/' else: print(_(messages.CRED_DOES_NOT_EXIST % self.args.name)) sys.exit(1) else: print(_(messages.CRED_DOES_NOT_EXIST % self.args.name)) sys.exit(1)
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)
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)
def _validate_args(self): CliCommand._validate_args(self) source_ids = [] if self.args.sources: # check for existence of sources not_found, source_ids = self._get_source_ids(self.args.sources) if not_found is True: sys.exit(1) self.source_ids = source_ids
def _validate_args(self): """Validate the scan job arguments.""" CliCommand._validate_args(self) if self.args.id and self.args.name: self.parser.print_usage() sys.exit(1) if self.args.id and self.args.status: print(_(messages.SCAN_JOB_ID_STATUS)) self.parser.print_usage() sys.exit(1)
def _validate_args(self): CliCommand._validate_args(self) if self.args.name: # check for existence of scan object found, scan_object_id = get_scan_object_id(self.parser, self.args.name) if found is False: sys.exit(1) else: self.req_path = scan.SCAN_URI + scan_object_id + 'jobs/'
def _validate_args(self): CliCommand._validate_args(self) delete_client_token() if 'username' in self.args and self.args.username: # check for file existence on system self.username = self.args.username else: self.username = input(_(messages.LOGIN_USERNAME_PROMPT)) self.password = getpass()
def _validate_args(self): CliCommand._validate_args(self) if ('hosts' in self.args and self.args.hosts and len(self.args.hosts) == 1): # check if a file and read in values try: self.args.hosts = read_in_file(self.args.hosts[0]) except ValueError: pass if ('exclude_hosts' in self.args and self.args.exclude_hosts and len(self.args.exclude_hosts) == 1): # check if a file and read in values try: self.args.exclude_hosts = \ read_in_file(self.args.exclude_hosts[0]) except ValueError: pass # check for valid cred values cred_list = ','.join(self.args.cred) response = request(parser=self.parser, method=GET, path=cred.CREDENTIAL_URI, params={'name': cred_list}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() count = json_data.get('count', 0) results = json_data.get('results', []) if count == len(self.args.cred): self.args.credentials = [] results_by_name_dict = {cred['name']: cred for cred in results} for cred_name in self.args.cred: self.args.credentials.append( results_by_name_dict[cred_name]['id']) else: for cred_entry in results: cred_name = cred_entry['name'] self.args.cred.remove(cred_name) not_found_str = ','.join(self.args.cred) print( _(messages.SOURCE_ADD_CREDS_NOT_FOUND % (not_found_str, self.args.name))) sys.exit(1) else: print(_(messages.SOURCE_ADD_CRED_PROCESS_ERR % self.args.name)) sys.exit(1)
def _validate_args(self): """Validate the edit arguments.""" CliCommand._validate_args(self) # Check to see if args were provided if not (self.args.sources or self.args.max_concurrency or (self.args.disabled_optional_products or self.args.disabled_optional_products == []) or (self.args.enabled_ext_product_search or self.args.enabled_ext_product_search == []) or (self.args.ext_product_search_dirs or self.args.ext_product_search_dirs == [])): print(_(messages.SCAN_EDIT_NO_ARGS % (self.args.name))) self.parser.print_help() sys.exit(1) # check for existence of scan exists = False response = request(parser=self.parser, method=GET, path=scan.SCAN_URI, params={'name': self.args.name}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() count = json_data.get('count', 0) results = json_data.get('results', []) if count >= 1: for result in results: if result['name'] == self.args.name: scan_entry = result self.req_path \ = self.req_path + str(scan_entry['id']) + '/' exists = True if not exists or count == 0: print(_(messages.SCAN_DOES_NOT_EXIST % self.args.name)) sys.exit(1) else: print(_(messages.SCAN_DOES_NOT_EXIST % self.args.name)) sys.exit(1) # check for valid source values source_ids = [] if self.args.sources: # check for existence of sources not_found, source_ids = get_source_ids(self.parser, self.args.sources) if not_found is True: sys.exit(1) self.source_ids = source_ids
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)
def _validate_args(self): CliCommand._validate_args(self) report_ids = [] if self.args.scan_job_ids: # check for existence of jobs & get report ids not_found, report_ids, job_not_found, report_not_found = \ self._get_report_ids() if not_found is True: if job_not_found: print(_(messages.REPORT_SJS_DO_NOT_EXIST % job_not_found)) if report_not_found: print(_(messages.REPORTS_REPORTS_DO_NOT_EXIST % report_not_found)) sys.exit(1) elif self.args.report_ids: report_ids = self.args.report_ids elif self.args.json_files: self._merge_json() self.report_ids = report_ids
def _validate_args(self): CliCommand._validate_args(self) found = False response = request(parser=self.parser, method=GET, path=scan.SCAN_URI, params={'name': self.args.name}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() count = json_data.get('count', 0) results = json_data.get('results', []) if count >= 1: for result in results: if result['name'] == self.args.name: self.req_path = self.req_path + str(result['id']) + '/' found = True if not found or count == 0: print(_(messages.SCAN_DOES_NOT_EXIST % self.args.name)) sys.exit(1)
def _validate_args(self): CliCommand._validate_args(self) if self.args.id: self.req_path = self.req_path + str(self.args.id) + '/restart/'
def _validate_args(self): CliCommand._validate_args(self) if self.args.id: self.req_path = self.req_path + str(self.args.id) + '/' if self.args.results: self.req_path += 'results/'
def _validate_args(self): CliCommand._validate_args(self) if not (self.args.hosts or self.args.exclude_hosts or self.args.cred or self.args.port or self.args.use_paramiko or self.args.ssl_cert_verify or self.args.disable_ssl or self.args.ssl_protocol): print(_(messages.SOURCE_EDIT_NO_ARGS % (self.args.name))) self.parser.print_help() sys.exit(1) if ('hosts' in self.args and self.args.hosts and len(self.args.hosts) == 1): # check if a file and read in values try: self.args.hosts = read_in_file(self.args.hosts[0]) except ValueError: pass if ('exclude_hosts' in self.args and self.args.exclude_hosts and len(self.args.exclude_hosts) == 1): # check if a file and read in values try: self.args.exclude_hosts = \ read_in_file(self.args.exclude_hosts[0]) except ValueError: pass # check for existence of source response = request(parser=self.parser, method=GET, path=source.SOURCE_URI, params={'name': self.args.name}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() count = json_data.get('count', 0) results = json_data.get('results', []) if count == 1: source_entry = results[0] self.req_path = self.req_path + str(source_entry['id']) + '/' else: print(_(messages.SOURCE_DOES_NOT_EXIST % self.args.name)) sys.exit(1) else: print(_(messages.SOURCE_DOES_NOT_EXIST % self.args.name)) sys.exit(1) # check for valid cred values if len(self.args.cred) > 0: # pylint: disable=len-as-condition cred_list = ','.join(self.args.cred) response = request(parser=self.parser, method=GET, path=cred.CREDENTIAL_URI, params={'name': cred_list}, payload=None) if response.status_code == codes.ok: # pylint: disable=no-member json_data = response.json() count = json_data.get('count', 0) results = json_data.get('results', []) if count == len(self.args.cred): self.args.credentials = [] for cred_entry in results: self.args.credentials.append(cred_entry['id']) else: for cred_entry in results: cred_name = cred_entry['name'] self.args.cred.remove(cred_name) not_found_str = ','.join(self.args.cred) print( _(messages.SOURCE_EDIT_CREDS_NOT_FOUND % (not_found_str, self.args.name))) sys.exit(1) else: print(_(messages.SOURCE_EDIT_CRED_PROCESS_ERR % self.args.name)) sys.exit(1)
def _validate_args(self): CliCommand._validate_args(self) if self.args.json_file: self._validate_create_json(self.args.json_file)