uus_mng 1.01 KB
Newer Older
1
#!/usr/bin/env python3
Davide Depau's avatar
Davide Depau committed
2
3
import crypt
import click
4
5
6
7
8
9
import redis
import os

redis_store = None
default_redis_url = os.environ.get('REDIS_URL', 'redis://127.0.0.1:6379/0')

Davide Depau's avatar
Davide Depau committed
10

11
12
13
14
15
@click.group()
@click.option("--redisurl", "-u", help="Redis DB url", default=default_redis_url)
def cli(redisurl):
    global redis_store
    redis_store = redis.from_url(redisurl)
Davide Depau's avatar
Davide Depau committed
16
17


18
@cli.command()
Davide Depau's avatar
Davide Depau committed
19
20
21
22
23
@click.argument("username")
@click.option("--passwd", "-p", prompt="Password", help="Password", hide_input=True)
def adduser(username, passwd):
    """Add UUS admin user"""
    cryptpwd = crypt.crypt(passwd)
24
    redis_store.set('usr.' + username, cryptpwd)
Davide Depau's avatar
Davide Depau committed
25
26


27
@cli.command()
Davide Depau's avatar
Davide Depau committed
28
29
30
31
32
33
34
@click.argument("username")
@click.option("--passwd", "-p", prompt="Password", help="Password", hide_input=True)
def passwd(username, passwd):
    """Change UUS admin user password"""
    adduser(username, passwd)


35
@cli.command()
Davide Depau's avatar
Davide Depau committed
36
37
38
@click.argument("username")
def deluser(username):
    """Delete UUS admin user"""
39
40
41
42
43
    redis_store.delete('usr.' + username)


if __name__ == '__main__':
    cli()