Commit b22c2c6b authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Expand credential state

parent a5a4daa4
# Generated by Django 2.1.3 on 2018-11-07 10:53
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0011_auto_20181029_1616'),
]
operations = [
migrations.AlterField(
model_name='credentialstate',
name='credential',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='credential_states', to='backend.SSHPublicKey'),
),
]
# Generated by Django 2.1.3 on 2018-11-07 10:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0012_auto_20181107_1153'),
]
operations = [
migrations.AddField(
model_name='credentialstate',
name='state_target',
field=models.CharField(choices=[('deployed', 'Deployed'), ('not_deployed', 'Not Deployed')], default='not_deployed', max_length=50),
),
]
......@@ -597,6 +597,11 @@ class NewDeploymentStateItem(models.Model):
class CredentialState(models.Model):
state_target = models.CharField(
max_length=50,
choices=TARGET_CHOICES,
default=NOT_DEPLOYED
)
state = models.CharField(
max_length=50,
choices=STATE_CHOICES,
......@@ -606,8 +611,7 @@ class CredentialState(models.Model):
credential = models.ForeignKey(
SSHPublicKey,
related_name='credential_states',
on_delete=models.SET_NULL,
null=True
on_delete=models.CASCADE,
)
target = models.ForeignKey(
......@@ -626,6 +630,7 @@ class CredentialState(models.Model):
except cls.DoesNotExist:
if settings.DEBUG_CREDENTIALS:
LOGGER.debug('new credential state for %s / %s', credential, target)
new_state = cls(
credential=credential,
target=target,
......
......@@ -449,13 +449,15 @@ class SSHPublicKey(models.Model):
editable=False,
)
# does not really delete the key
def delete_key(self):
LOGGER.info('Deleting SSH key %s', self.name)
for credential_state in self.credential_states.all():
credential_state.set('removal_pending')
self.delete()
LOGGER.debug('delete_key: %s', self.name)
self.user = None
self.key = ''
self.deleted = True
self.save()
# we do not update the user object from here: update_userinfo does that anyway
LOGGER.debug('delete_key: need to inform clients about deletion')
def __str__(self):
if self.deleted:
......
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