mirror of
https://github.com/ansible/awx.git
synced 2026-03-17 17:07:33 -02:30
testable playbook w/ state wanted pattern
* remove complicated redis config assembly * backup and restore discover credentials rather than requiring * backup strategy no longer drops the db. This allows awx user to restore without creatdb persmission. * removed mongo from backup/restore * added password change support for redis, pg, munin * added update_password command and respective tests * tests for munin, pg, redis password change * unit tests for munin, redis password change * tests for postgres host (ip and socket) change * tests for postgres backup/restore on remote db
This commit is contained in:
45
awx/main/management/commands/update_password.py
Normal file
45
awx/main/management/commands/update_password.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2016 Ansible, Inc.
|
||||
# All Rights Reserved
|
||||
|
||||
# Python
|
||||
from optparse import make_option
|
||||
|
||||
# Django
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import CommandError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class UpdatePassword(object):
|
||||
def update_password(self, username, password):
|
||||
changed = False
|
||||
u = User.objects.get(username=username)
|
||||
if not u:
|
||||
raise RuntimeError("User not found")
|
||||
check = u.check_password(password)
|
||||
if not check:
|
||||
u.set_password(password)
|
||||
u.save()
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--username', dest='username', action='store', type='string', default=None,
|
||||
help='username to change the password for'),
|
||||
make_option('--password', dest='password', action='store', type='string', default=None,
|
||||
help='new password for user'),
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not options['username']:
|
||||
raise CommandError('username required')
|
||||
if not options['password']:
|
||||
raise CommandError('password required')
|
||||
|
||||
cp = UpdatePassword()
|
||||
res = cp.update_password(options['username'], options['password'])
|
||||
if res:
|
||||
return "Password updated"
|
||||
return "Password not updated"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user