From cb1b5fcfd0ab573c9655480cccd0570f72bc3a45 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Thu, 11 May 2017 20:24:02 +0200 Subject: [feat] add provider to the cli --- src/leap/bitmask/cli/bitmask_cli.py | 6 ++- src/leap/bitmask/cli/provider.py | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/leap/bitmask/cli/provider.py (limited to 'src/leap') diff --git a/src/leap/bitmask/cli/bitmask_cli.py b/src/leap/bitmask/cli/bitmask_cli.py index b418f1af..2483d476 100755 --- a/src/leap/bitmask/cli/bitmask_cli.py +++ b/src/leap/bitmask/cli/bitmask_cli.py @@ -18,7 +18,6 @@ """ Bitmask Command Line interface: zmq client. """ -import json import sys import signal import traceback @@ -30,6 +29,7 @@ from leap.bitmask.cli import command from leap.bitmask.cli.keys import Keys from leap.bitmask.cli.logs import Logs from leap.bitmask.cli.mail import Mail +from leap.bitmask.cli.provider import Provider from leap.bitmask.cli.user import User from leap.bitmask.cli.vpn import VPN from leap.bitmask.cli.webui import WebUI @@ -67,6 +67,10 @@ OPTIONAL ARGUMENTS: epilog = ("Use 'bitmaskctl help' to learn more " "about each command.") + def provider(self, raw_args): + provider = Provider(self.cfg, self.print_json) + return provider.execute(raw_args) + def user(self, raw_args): user = User(self.cfg, self.print_json) return user.execute(raw_args) diff --git a/src/leap/bitmask/cli/provider.py b/src/leap/bitmask/cli/provider.py new file mode 100644 index 00000000..7c30df37 --- /dev/null +++ b/src/leap/bitmask/cli/provider.py @@ -0,0 +1,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 . +""" +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 + +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) -- cgit v1.2.3