Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Add password-prompt, list-partners function #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions tolinoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,28 @@

import configparser
import argparse
import json
import sys
import datetime
import logging
from os.path import expanduser
import getpass

from tolinocloud import TolinoCloud


class PasswordPromptAction(argparse.Action):
'''
class to prompt for password if none is specified on the command line
'''
def __call__(self, parser, args, values, option_string=None):
# If no value is given on the commandline prompt for password.
if values:
# Ideally a security warning could be generated here.
setattr(args, self.dest, values)
else:
setattr(args, self.dest, getpass.getpass())


def inventory(args):
c = TolinoCloud(args.partner)
c.login(args.user, args.password)
Expand Down Expand Up @@ -92,6 +106,12 @@ def delete(args):
print('deleted {} from tolino cloud.'.format(args.document_id))


def list_partners(args):
print('List of partner ids available:')
for partner_id in sorted(TolinoCloud.partner_settings.keys()):
print('{} : {}'.format(partner_id, TolinoCloud.partner_name[partner_id]))
sys.exit(0)

parser = argparse.ArgumentParser(
description='cmd line client to access personal tolino cloud storage space.'
)
Expand All @@ -105,9 +125,9 @@ def delete(args):
defaults = dict(c.items('Defaults'))
parser.set_defaults(**defaults)

parser.add_argument('--user', type=str, help='username (usually an email address)')
parser.add_argument('--password', type=str, help='password')
parser.add_argument('--partner', type=int, help='shop / partner id (use 0 for list)')
parser.add_argument('--user', '-u', type=str, help='username (usually an email address)')
parser.add_argument('--password', '-p', action=PasswordPromptAction, type=str, help='password. Leave empty for a password prompt', nargs='?')
parser.add_argument('--partner', type=int, help='shop / partner id')
parser.add_argument('--debug', action="store_true", help='log additional debugging info')

subparsers = parser.add_subparsers()
Expand Down Expand Up @@ -135,16 +155,13 @@ def delete(args):
s.add_argument('device_id')
s.set_defaults(func=unregister)

s = subparsers.add_parser('list-partners', help='list devices registered to cloud account')
s.set_defaults(func=list_partners)

args = parser.parse_args(remaining_argv)

if args.debug:
logging.basicConfig(level=logging.DEBUG)

if args.partner == 0:
print('List of partner ids available:')
for partner_id in sorted(TolinoCloud.partner_settings.keys()):
print('{} : {}'.format(partner_id, TolinoCloud.partner_name[partner_id]))
sys.exit(1)

if (not args.user) or (not args.password):
print('Login credentials user/password required.')
Expand Down