summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/cli/provider.py
blob: 7c30df37746a8e165cde4b0d4e0ba30f924570b2 (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
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
# -*- coding: utf-8 -*-
# provider
# Copyright (C) 2017 LEAP
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Bitmask Command Line interface: provider
"""
import argparse
import sys

from colorama import Fore

from leap.bitmask.cli import command


class Provider(command.Command):
    service = 'bonafide'
    usage = '''{name} provider <subcommand>

Bitmask bonafide provider service

SUBCOMMANDS:

   list       List providers
   read       Read provider
   delete     Delete the provider

'''.format(name=command.appname)

    def __init__(self, *args, **kwargs):
        super(Provider, self).__init__(*args, **kwargs)
        self.data.append('provider')

    def list(self, raw_args):
        self.data += ['list']
        return self._send(printer=self._print_domains)

    def read(self, raw_args):
        parser = argparse.ArgumentParser(
            description='Bitmask provider read',
            prog='%s %s %s' % tuple(sys.argv[:3]))
        parser.add_argument('domain', nargs=1,
                            help='provider to gather info from')
        subargs = parser.parse_args(raw_args)

        self.data += ['read', subargs.domain[0]]
        return self._send(printer=command.default_dict_printer)

    def delete(self, raw_args):
        parser = argparse.ArgumentParser(
            description='Bitmask provider delete',
            prog='%s %s %s' % tuple(sys.argv[:3]))
        parser.add_argument('domain', nargs=1,
                            help='provider to delete')
        subargs = parser.parse_args(raw_args)

        self.data += ['delete', subargs.domain[0]]
        return self._send()

    def _print_domains(self, result):
        for i in result:
            print(Fore.GREEN + i['domain'] + Fore.RESET)