Example #1
0
def save_services(services, args, parser):
    if services:
        print('Services:')
    for name, data in six.iteritems(services):
        if Service.objects.filter(username=name).exists():
            print('* %s: Already exists.' % name)
            continue

        service = Service(username=name)

        # set password:
        if 'password' in data:
            pwd = data['password']
            if isinstance(pwd, six.string_types):
                service.set_password(pwd)
            elif isinstance(pwd, dict):
                service.password = import_hash(**pwd)
            else:
                raise TypeError("'password' is neither string nor dictionary.")
            print('* %s: Set password from input data.' % name)
        elif args.gen_passwords:
            raw_passwd = Service.objects.make_random_password(length=32)
            service.set_password(raw_passwd)
            print('* %s: Generated password: %s' % (name, raw_passwd))
        else:
            print('* %s: Added service with no password.' % name)
        service.save()

        for host in data.get('hosts', []):
            address = ServiceAddress.objects.get_or_create(address=host)[0]
            service.hosts.add(address)
def save_services(services, args, parser):
    if services:
        print('Services:')
    for name, data in six.iteritems(services):
        if Service.objects.filter(username=name).exists():
            print('* %s: Already exists.' % name)
            continue

        service = Service(username=name)

        # set password:
        if 'password' in data:
            pwd = data['password']
            if isinstance(pwd, six.string_types):
                service.set_password(pwd)
            elif isinstance(pwd, dict):
                service.password = import_hash(**pwd)
            else:
                raise TypeError("'password' is neither string nor dictionary.")
            print('* %s: Set password from input data.' % name)
        elif args.gen_passwords:
            raw_passwd = Service.objects.make_random_password(length=32)
            service.set_password(raw_passwd)
            print('* %s: Generated password: %s' % (name, raw_passwd))
        else:
            print('* %s: Added service with no password.' % name)
        service.save()

        for host in data.get('hosts', []):
            address = ServiceAddress.objects.get_or_create(address=host)[0]
            service.hosts.add(address)
Example #3
0
    def set_password_hash(self, user, algorithm, hash):
        hash = import_hash(algorithm, hash)

        try:
            self._set_password(keys=[_USERS], args=[user, hash])
        except self.redis.ResponseError as e:
            if e.message == 'UserNotFound':
                raise UserNotFound(user)
            raise
Example #4
0
    def set_password_hash(self, username, algorithm, hash):
        assert isinstance(username, six.string_types)
        assert isinstance(algorithm, six.string_types)
        assert isinstance(hash, six.string_types)

        user = self._get_user(username, 'password')

        user.password = import_hash(algorithm=algorithm, hash=hash)
        user.save()
Example #5
0
 def set_password_hash(self, user, algorithm, hash):
     user = self._user(user, 'password')
     user.password = import_hash(algorithm=algorithm, hash=hash)
     user.save()
Example #6
0
 def set_password_hash(self, user, algorithm, hash):
     django_hash = import_hash(algorithm, hash)
     self._users[user]['password'] = django_hash