Commit 4842bab6 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Make use of the credential states in the client responses

parent 31fbf598
......@@ -520,9 +520,29 @@ class NewDeploymentStateItem(models.Model):
self._set_state(DEPLOYMENT_PENDING, publish=False)
self.parent.publish_to_client()
def client_credential_states(self, credential_states):
LOGGER.debug('client_credential_states: %s', credential_states)
ssh_key_states = credential_states.get('ssh_key', None)
if ssh_key_states is not None:
for key_name in ssh_key_states:
try:
credential_state = self.credential_states.get(credential__name=key_name)
LOGGER.debug('RECEIVED update to credential state %s', credential_state)
credential_state.set(ssh_key_states[key_name])
except CredentialState.DoesNotExist:
LOGGER.error('Credential state for key %s and item %s does not exist', key_name, self)
LOGGER.error('selfs states: %s', self.credential_states.all())
# returns None on success, or a string describing an error
def client_response(self, output):
state = output.get('state', None)
credential_states = output.get('user_credential_states', None)
if credential_states is not None:
self.client_credential_states(credential_states)
self.message = output.get('message', '')
self.save()
......@@ -583,7 +603,7 @@ class NewDeploymentStateItem(models.Model):
self.set_onroute_credential_states(state)
self.state = state
self.save()
LOGGER.debug(self.msg('state: '+self.state))
LOGGER.debug(self.msg('State changed to '+self.state))
if publish:
self.parent.publish_to_user()
......@@ -628,8 +648,6 @@ class CredentialState(models.Model):
target=target,
)
except cls.DoesNotExist:
if settings.DEBUG_CREDENTIALS:
LOGGER.debug('new credential state for %s / %s', credential, target)
new_state = cls(
credential=credential,
......@@ -637,13 +655,20 @@ class CredentialState(models.Model):
state=NOT_DEPLOYED,
)
new_state.save()
if settings.DEBUG_CREDENTIALS:
LOGGER.debug(new_state.msg('State created'))
return new_state
def set(self, state):
self.state = state
self.save()
if settings.DEBUG_CREDENTIALS:
LOGGER.debug('%s state changed to: %s', self, state)
LOGGER.debug(self.msg('State changed to {}'.format(state)))
def msg(self, message):
return self.target.msg('Credential {}: {}'.format(self.credential, message))
def __str__(self):
return '{}@{}'.format(
......
......@@ -289,7 +289,6 @@ class User(AbstractUser):
return changed
# returns True if any keys changed
def update_userinfo_ssh_key(self, userinfo):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment