summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/auth.py
blob: 6f512313590950bf066f6e5e338c9aa8d06ba85f (plain)
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
import logging
from cliff.command import Command
from authHandler import AuthHandler


class Auth(Command):
    "Handle Authentication for users"

    log = logging.getLogger(__name__)

    def get_parser(self, prog_name):
        parser = super(Auth, self).get_parser(prog_name)
        parser.add_argument('-u',
                            type=str,
                            required=True,
                            help='Username for authentication')
        parser.add_argument('-p',
                            type=str,
                            required=True,
                            help='Password for authentication')
        return parser

    def take_action(self, parsed_args):
        response = AuthHandler.authenticate(parsed_args.u, parsed_args.p)
        if "login" in response.text:
            print "Authentication has failed."
        else:
            print "Authentication has been successful!"