[go: up one dir, main page]

File: sp-users

package info (click to toggle)
securepass-tools 0.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 264 kB
  • ctags: 471
  • sloc: python: 1,786; sh: 19; makefile: 17
file content (77 lines) | stat: -rwxr-xr-x 2,264 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
##
## SecurePass CLI tools utilities
## Users list
##
## (c) 2013 Giuseppe Paterno' (gpaterno@gpaterno.com)
##          GARL Sagl (www.garl.ch)
##

from argparse import ArgumentParser
from securepass import utils
from securepass import securepass
import logging
import sys


parser = ArgumentParser(
    description="List SecurePass users",
    prog="sp-users",
)

parser.add_argument('-D', '--debug',
                    action='store_true', dest="debug_flag",
                    help="Enable debug output",)
parser.add_argument('-d', '--details',
                    action='store_true', dest="details_flag",
                    help="Show details",)
parser.add_argument('-H', '--noheaders',
                    action='store_true', dest="noheader_flag",
                    help="Don't print headers",)
parser.add_argument('-r', '--realm',
                    action='store', dest="realm",
                    default=None,
                    help="Set alternate realm",)

values = parser.parse_args()

## Set debug
FORMAT = '%(asctime)-15s %(levelname)s: %(message)s'
if values.debug_flag:
    logging.basicConfig(format=FORMAT, level=logging.DEBUG)
else:
    logging.basicConfig(format=FORMAT, level=logging.INFO)


## Load config
config = utils.loadConfig()

## Config the handler
sp_handler = securepass.SecurePass(app_id=config['app_id'],
                                   app_secret=config['app_secret'],
                                   endpoint=config['endpoint'])

## List all users
if values.details_flag and not values.noheader_flag:
    print "%-35s %-35s %s" % ("User ID", "Name and Surname", "Status")
    print "================================================================================"

try:
    for user in sp_handler.user_list(realm=values.realm):
        if values.details_flag:
            user_detail = sp_handler.user_info(user=user)
            fullname = "%s %s" % (user_detail['name'], user_detail['surname'])

            ## User status
            if user_detail['enabled']:
                status = "Active"
            else:
                status = 'Disabled'

            print "%-35s %-35s %s" % (user, fullname, status)
        else:
            print user


except Exception as e:
    sys.exit(e)