Skip to content

Commit

Permalink
Merge branch 'master' into issues/710
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelee committed Feb 13, 2018
2 parents 959d03f + 8b15512 commit edb91ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions qpc/source/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ def _validate_args(self):
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'])
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']
Expand Down
5 changes: 5 additions & 0 deletions quipucords/api/credential/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class Credential(models.Model):
become_user = models.CharField(max_length=64, null=True)
become_password = models.CharField(max_length=1024, null=True)

def __str__(self):
"""Convert to string."""
return '{ id:%s, name:%s, type:%s}' %\
(self.id, self.name, self.cred_type)

@staticmethod
def is_encrypted(field):
"""Check to see if the password is already encrypted."""
Expand Down
18 changes: 15 additions & 3 deletions quipucords/scanner/network/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ def record_result(self, name, credential, status):
self.conn_result.save()

if status == SystemConnectionResult.SUCCESS:
self.scan_task.increment_stats(name, increment_sys_scanned=True)
message = '%s with %s' % (name, credential.name)
self.scan_task.increment_stats(message, increment_sys_scanned=True)
else:
self.scan_task.increment_stats(name, increment_sys_failed=True)
if credential is not None:
message = '%s with %s' % (name, credential.name)
else:
message = '%s has no valid credentials' % name

self.scan_task.increment_stats(message, increment_sys_failed=True)

self._remaining_hosts.remove(name)

Expand Down Expand Up @@ -140,10 +146,16 @@ def run_with_result_store(self, result_store):
remaining_hosts = result_store.remaining_hosts()

for cred_id in credentials:
credential = Credential.objects.get(pk=cred_id)
if not remaining_hosts:
message = 'Skipping credential %s. No remaining hosts.' % \
credential.name
self.scan_task.log_message(message)
break

credential = Credential.objects.get(pk=cred_id)
message = 'Attempting credential %s.' % credential.name
self.scan_task.log_message(message)

cred_data = CredentialSerializer(credential).data
callback = ConnectResultCallback(result_store, credential)
try:
Expand Down

0 comments on commit edb91ff

Please sign in to comment.