|
|
|
@ -4,10 +4,11 @@
|
|
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
import logging
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
from django.db import models
|
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
|
|
from common.utils import signer, validate_ssh_private_key
|
|
|
|
|
|
|
|
|
@ -24,15 +25,19 @@ def private_key_validator(value):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AdminUser(models.Model):
|
|
|
|
|
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'))
|
|
|
|
|
name = models.CharField(max_length=128, unique=True,
|
|
|
|
|
verbose_name=_('Name'))
|
|
|
|
|
username = models.CharField(max_length=16, verbose_name=_('Username'))
|
|
|
|
|
_password = models.CharField(max_length=256, blank=True, null=True, verbose_name=_('Password'))
|
|
|
|
|
_password = models.CharField(
|
|
|
|
|
max_length=256, blank=True, null=True, verbose_name=_('Password'))
|
|
|
|
|
_private_key = models.CharField(max_length=4096, blank=True, null=True, verbose_name=_('SSH private key'),
|
|
|
|
|
validators=[private_key_validator, ])
|
|
|
|
|
_public_key = models.CharField(max_length=4096, blank=True, verbose_name=_('SSH public key'))
|
|
|
|
|
_public_key = models.CharField(
|
|
|
|
|
max_length=4096, blank=True, verbose_name=_('SSH public key'))
|
|
|
|
|
comment = models.TextField(blank=True, verbose_name=_('Comment'))
|
|
|
|
|
date_created = models.DateTimeField(auto_now_add=True, null=True)
|
|
|
|
|
created_by = models.CharField(max_length=32, null=True, verbose_name=_('Created by'))
|
|
|
|
|
created_by = models.CharField(
|
|
|
|
|
max_length=32, null=True, verbose_name=_('Created by'))
|
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.name
|
|
|
|
@ -99,23 +104,33 @@ class SystemUser(models.Model):
|
|
|
|
|
('P', 'Password'),
|
|
|
|
|
('K', 'Public key'),
|
|
|
|
|
)
|
|
|
|
|
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'))
|
|
|
|
|
name = models.CharField(max_length=128, unique=True,
|
|
|
|
|
verbose_name=_('Name'))
|
|
|
|
|
username = models.CharField(max_length=16, verbose_name=_('Username'))
|
|
|
|
|
_password = models.CharField(max_length=256, blank=True, verbose_name=_('Password'))
|
|
|
|
|
protocol = models.CharField(max_length=16, choices=PROTOCOL_CHOICES, default='ssh', verbose_name=_('Protocol'))
|
|
|
|
|
_private_key = models.CharField(max_length=4096, blank=True, verbose_name=_('SSH private key'))
|
|
|
|
|
_public_key = models.CharField(max_length=4096, blank=True, verbose_name=_('SSH public key'))
|
|
|
|
|
_password = models.CharField(
|
|
|
|
|
max_length=256, blank=True, verbose_name=_('Password'))
|
|
|
|
|
protocol = models.CharField(
|
|
|
|
|
max_length=16, choices=PROTOCOL_CHOICES, default='ssh', verbose_name=_('Protocol'))
|
|
|
|
|
_private_key = models.CharField(
|
|
|
|
|
max_length=8192, blank=True, verbose_name=_('SSH private key'))
|
|
|
|
|
_public_key = models.CharField(
|
|
|
|
|
max_length=8192, blank=True, verbose_name=_('SSH public key'))
|
|
|
|
|
auth_method = models.CharField(choices=AUTH_METHOD_CHOICES, default='K',
|
|
|
|
|
max_length=1, verbose_name=_('Auth method'))
|
|
|
|
|
auto_push = models.BooleanField(default=True, verbose_name=_('Auto push'))
|
|
|
|
|
auto_update = models.BooleanField(default=True, verbose_name=_('Auto update pass/key'))
|
|
|
|
|
sudo = models.TextField(max_length=4096, default='/user/bin/whoami', verbose_name=_('Sudo'))
|
|
|
|
|
shell = models.CharField(max_length=64, default='/bin/bash', verbose_name=_('Shell'))
|
|
|
|
|
auto_update = models.BooleanField(
|
|
|
|
|
default=True, verbose_name=_('Auto update pass/key'))
|
|
|
|
|
sudo = models.TextField(
|
|
|
|
|
max_length=4096, default='/user/bin/whoami', verbose_name=_('Sudo'))
|
|
|
|
|
shell = models.CharField(
|
|
|
|
|
max_length=64, default='/bin/bash', verbose_name=_('Shell'))
|
|
|
|
|
home = models.CharField(max_length=64, blank=True, verbose_name=_('Home'))
|
|
|
|
|
uid = models.IntegerField(null=True, blank=True, verbose_name=_('Uid'))
|
|
|
|
|
date_created = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by'))
|
|
|
|
|
comment = models.TextField(max_length=128, blank=True, verbose_name=_('Comment'))
|
|
|
|
|
created_by = models.CharField(
|
|
|
|
|
max_length=32, blank=True, verbose_name=_('Created by'))
|
|
|
|
|
comment = models.TextField(
|
|
|
|
|
max_length=128, blank=True, verbose_name=_('Comment'))
|
|
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
|
return self.name
|
|
|
|
@ -156,7 +171,8 @@ class SystemUser(models.Model):
|
|
|
|
|
return assets
|
|
|
|
|
|
|
|
|
|
def get_assets(self):
|
|
|
|
|
assets = set(self.assets.all()) | self.get_assets_inherit_from_asset_groups()
|
|
|
|
|
assets = set(self.assets.all()
|
|
|
|
|
) | self.get_assets_inherit_from_asset_groups()
|
|
|
|
|
return list(assets)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@ -199,4 +215,3 @@ class SystemUser(models.Model):
|
|
|
|
|
except IntegrityError:
|
|
|
|
|
print('Error continue')
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|