Coverage for appr/commands/login.py: 23%

# Coverage for appr/commands/login.py : 23%

## 57 statements 13 run 44 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

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 78 | from __future__ import absolute_import, division, print_function import argparse import getpass from builtins import input from appr.commands.command_base import CommandBase, PackageSplit class LoginCmd(CommandBase): name = 'login' help_message = "login" def __init__(self, options): super(LoginCmd, self).__init__(options) self.registry_host = options.registry_host self.signup = options.signup self.password = options.password self.email = options.email self.user = options.user self.status = None self.ssl_verify = options.cacert or not options.insecure self.package_parts = options.package_parts pname = self.package_parts.get('package', None) namespace = self.package_parts.get('namespace', None) self.package = None if pname: self.package = "%s/%s" % (namespace, pname) elif namespace: self.package = namespace @classmethod def _add_arguments(cls, parser): cls._add_registryhost_option(parser) parser.add_argument('registry', nargs='?', default=None, action=PackageSplit, help="registry url: quay.io[/namespace][/repo]\n" + "If namespace and/or repo are passed, creds only requested for it") parser.add_argument("-s", "--signup", action='store_true', default=False, help="Create a new account and login") parser.add_argument("-u", "--user", nargs="?", default=None, help="username") parser.add_argument("-p", "--password", nargs="?", default=None, help="password") parser.add_argument("-e", "--email", nargs="?", default=None, help="email for signup") def _call(self): client = self.RegistryClient(self.registry_host, requests_verify=self.ssl_verify) if self.user is not None: self.user = self.user else: self.user = input("Username: ") if self.password is not None: p1 = self.password else: p1 = getpass.getpass() if self.signup: if self.password is not None: p2 = p1 else: p2 = getpass.getpass('Password confirmation: ') if self.email is not None: email = self.email else: email = input("Email: ") if p1 != p2: raise argparse.ArgumentError("password", message="Error: password mismatch") client.signup(self.user, p1, p2, email) self.status = "Registration complete" else: client.login(self.user, p1, scope=self.package) self.status = "Login succeeded" def _render_dict(self): return {"user": self.user, "status": self.status, "host": self.registry_host, "scope": self.package} def _render_console(self): return " >>> %s" % self.status