Exemplo n.º 1
0
def main():
    p = argparse.ArgumentParser()

    class PrintAction(argparse.Action):
        def __call__(self, parser, namespace, values, option_string=None):
            setattr(namespace, 'print', True)
            setattr(namespace, 'dotfile', None)

    sp = p.add_subparsers(dest='cmd')
    pprov = sp.add_parser('provision', help='Provision a new VIP Access credential')
    pprov.set_defaults(func=provision)
    m = pprov.add_mutually_exclusive_group()
    m.add_argument('-p', '--print', action=PrintAction, nargs=0,
                   help="Print the new credential, but don't save it to a file")
    m.add_argument('-o', '--dotfile', type=PathType(type='file', exists=False), default=os.path.expanduser('~/.vipaccess'),
                   help="File in which to store the new credential (default ~/.vipaccess")
    pprov.add_argument('-t', '--token-model', default='VSST',
                      help="VIP Access token model. Should be VSST (desktop token, default) or VSMT (mobile token). Some clients only accept one or the other.")

    pshow = sp.add_parser('show', help="Show the current 6-digit token")
    m = pshow.add_mutually_exclusive_group()
    m.add_argument('-s', '--secret',
                   help="Specify the token secret on the command line (base32 encoded)")
    m.add_argument('-f', '--dotfile', type=PathType(exists=True), default=os.path.expanduser('~/.vipaccess'),
                   help="File in which the credential is stored (default ~/.vipaccess")
    pshow.add_argument('-v', '--verbose', action='store_true')
    pshow.set_defaults(func=show)

    p.set_default_subparser('show')
    args = p.parse_args()
    return args.func(p, args)
Exemplo n.º 2
0
def main():
    p = argparse.ArgumentParser()

    class PrintAction(argparse.Action):
        def __call__(self, parser, namespace, values, option_string=None):
            setattr(namespace, 'print', True)
            setattr(namespace, 'dotfile', None)

    sp = p.add_subparsers(dest='cmd')

    pprov = sp.add_parser('provision', help='Provision a new VIP Access credential')
    pprov.set_defaults(func=provision)
    m = pprov.add_mutually_exclusive_group()
    m.add_argument('-p', '--print', action=PrintAction, nargs=0,
                   help="Print the new credential, but don't save it to a file")
    m.add_argument('-o', '--dotfile', type=PathType(type='file', exists=False), default=os.path.expanduser('~/.vipaccess'),
                   help="File in which to store the new credential (default ~/.vipaccess)")
    pprov.add_argument('-i', '--issuer', default="Symantec", action='store',
                       help="Specify the issuer name to use (default: Symantec)")
    pprov.add_argument('-t', '--token-model', default='VSST',
                      help="VIP Access token model. Normally VSST (desktop token, default) or VSMT (mobile token). "
                           "Some clients only accept one or the other. Other more obscure token types also exist: "
                           "https://support.symantec.com/en_US/article.TECH239895.html")

    pshow = sp.add_parser('show', help="Show the current 6-digit token")
    m = pshow.add_mutually_exclusive_group()
    m.add_argument('-s', '--secret',
                   help="Specify the token secret on the command line (base32 encoded)")
    m.add_argument('-f', '--dotfile', type=PathType(exists=True), default=os.path.expanduser('~/.vipaccess'),
                   help="File in which the credential is stored (default ~/.vipaccess)")
    pshow.add_argument('-v', '--verbose', action='store_true')
    pshow.set_defaults(func=show)

    puri = sp.add_parser('uri', help="Export the credential as a URI (otpauth://)")
    m = puri.add_mutually_exclusive_group()
    m.add_argument('-s', '--secret',
                   help="Specify the token secret on the command line (base32 encoded)")
    m.add_argument('-f', '--dotfile', type=PathType(exists=True), default=os.path.expanduser('~/.vipaccess'),
                   help="File in which the credential is stored (default ~/.vipaccess)")
    puri.add_argument('-i', '--issuer', default="Symantec", action='store',
                       help="Specify the issuer name to use (default: Symantec)")
    puri.set_defaults(func=uri)

    p.set_default_subparser('show')
    args = p.parse_args()
    return args.func(p, args)
Exemplo n.º 3
0
def main():
    p = argparse.ArgumentParser()

    class UnsetDotfileAndStore(argparse.Action):
        def __call__(self, parser, namespace, values, option_string=None):
            # We need to unset dotfile so that PathType() doesn't try to check for its existence/nonexistence
            setattr(namespace, 'dotfile', None)
            setattr(
                namespace, self.dest, True
                if not values else values[0] if len(values) == 1 else values)

    sp = p.add_subparsers(dest='cmd')

    pprov = sp.add_parser('provision',
                          help='Provision a new VIP Access credential')
    pprov.set_defaults(func=provision)
    m = pprov.add_mutually_exclusive_group()
    m.add_argument(
        '-p',
        '--print',
        action=UnsetDotfileAndStore,
        nargs=0,
        help="Print the new credential, but don't save it to a file")
    m.add_argument(
        '-o',
        '--dotfile',
        type=PathType(type='file', exists=False),
        default=os.path.expanduser('~/.vipaccess'),
        help="File in which to store the new credential (default ~/.vipaccess)"
    )
    pprov.add_argument(
        '-i',
        '--issuer',
        default="VIP Access",
        action='store',
        help="Specify the issuer name to use (default: %(default)s)")
    pprov.add_argument(
        '-t',
        '--token-model',
        default='VSMT',
        help=
        'VIP Access token model. Often SYMC/VSMT ("mobile" token, default) or '
        'SYDC/VSST ("desktop" token). Some clients only accept one or the other. '
        "Other more obscure token types also exist: "
        "https://support.symantec.com/en_US/article.TECH239895.html")

    pcheck = sp.add_parser('check',
                           help='Check if a VIP Access credential is working')
    m = pcheck.add_mutually_exclusive_group()
    m.add_argument(
        '-f',
        '--dotfile',
        type=PathType(type='file', exists=True),
        default=os.path.expanduser('~/.vipaccess'),
        help="File in which the credential is stored (default ~/.vipaccess)")
    m.add_argument('-s',
                   '--secret',
                   action=UnsetDotfileAndStore,
                   nargs=1,
                   help="Specify the token secret to test (base32 encoded)")
    pcheck.add_argument(
        '-I',
        '--identity',
        help=
        "Specify the ID of the token to test (normally starts with VS or SYMC)"
    )
    pcheck.set_defaults(func=check)

    pshow = sp.add_parser('show', help="Show the current 6-digit token")
    m = pshow.add_mutually_exclusive_group()
    m.add_argument(
        '-s',
        '--secret',
        action=UnsetDotfileAndStore,
        nargs=1,
        help="Specify the token secret on the command line (base32 encoded)")
    m.add_argument(
        '-f',
        '--dotfile',
        type=PathType(type='file', exists=True),
        default=os.path.expanduser('~/.vipaccess'),
        help="File in which the credential is stored (default ~/.vipaccess)")
    pshow.add_argument('-v', '--verbose', action='store_true')
    pshow.set_defaults(func=show)

    puri = sp.add_parser('uri',
                         help="Export the credential as a URI (otpauth://)")
    m = puri.add_mutually_exclusive_group()
    m.add_argument(
        '-s',
        '--secret',
        action=UnsetDotfileAndStore,
        nargs=1,
        help="Specify the token secret on the command line (base32 encoded)")
    m.add_argument(
        '-f',
        '--dotfile',
        type=PathType(type='file', exists=True),
        default=os.path.expanduser('~/.vipaccess'),
        help="File in which the credential is stored (default ~/.vipaccess)")
    puri.add_argument(
        '-i',
        '--issuer',
        default="Symantec",
        action='store',
        help="Specify the issuer name to use (default: Symantec)")
    puri.add_argument(
        '-I',
        '--identity',
        action='store',
        help="Specify the ID of the token to use (required with --secret))")
    puri.set_defaults(func=uri)

    p.set_default_subparser('show')
    args = p.parse_args()
    return args.func(p, args)