Пример #1
0
def help_command(ctx, config_dump=False):
    """Print some information on the system environment."""
    def banner(title):
        "Helper"
        click.echo('')
        click.secho('~~~ {} ~~~'.format(title), fg='green', bg='black', bold=True)

    if config_dump:
        ctx.obj.cfg.dump()
        sys.exit(0)

    app_name = ctx.find_root().info_name
    click.secho('*** "{}" Help & Information ***'.format(app_name), fg='white', bg='blue', bold=True)

    banner('Version Information')
    click.echo(config.version_info(ctx))

    banner('Configuration')
    locations = ctx.obj.cfg.locations(exists=False)
    locations = [(u'✔' if os.path.exists(i) else u'✘', click.pretty_path(i)) for i in locations]
    click.echo(u'The following configuration files are merged in order, if they exist:\n    {0}'.format(
        u'\n    '.join(u'{}   {}'.format(*i) for i in locations),
    ))

    banner('More Help')
    click.echo("Call '{} --help' to get a list of available commands & options.".format(app_name))
    click.echo("Call '{} «command» --help' to get help on a specific command.".format(app_name))
    click.echo("Call '{} --version' to get the above version information separately.".format(app_name))
    click.echo("Call '{} --license' to get licensing informatioon.".format(app_name))
Пример #2
0
 def banner(title):
     "Helper"
     click.echo('')
     click.secho('~~~ {} ~~~'.format(title),
                 fg='green',
                 bg='black',
                 bold=True)
Пример #3
0
def diagnostics(cause):
    """Display diagnostic info based on the given cause."""
    import pprint

    if not cause:
        return

    response = getattr(cause, 'response', None)
    request = getattr(response, 'request', None)
    # pprint.pprint(vars(response))
    # pprint.pprint(vars(request))

    method = 'HTTP {}'.format(request.method) if request else 'HTTP'
    try:
        data = pprint.pformat(response.json(), indent=4)
    except (AttributeError, TypeError, ValueError):
        try:
            data = response.content
        except AttributeError:
            data = ''
    if data:
        try:
            data = data.decode('ascii')
        except (AttributeError, UnicodeDecodeError):
            pass
        data = data.splitlines()
        if len(data) > MAX_ERROR_LINES:
            data = data[:MAX_ERROR_LINES] + ['...']
        data = '| RESPONSE BODY:\n' + '\n'.join(['|   ' + x for x in data])

    click.serror("{} ERROR: {}".format(method, cause))
    if data:
        click.secho(data)
Пример #4
0
def help_command(ctx, config_dump=False):
    """Print some information on the system environment."""
    def banner(title):
        "Helper"
        click.echo('')
        click.secho('~~~ {} ~~~'.format(title), fg='green', bg='black', bold=True)

    if config_dump:
        ctx.obj.cfg.dump()
        sys.exit(0)

    app_name = ctx.find_root().info_name
    click.secho('*** "{}" Help & Information ***'.format(app_name), fg='white', bg='blue', bold=True)

    banner('Version Information')
    click.echo(config.version_info(ctx))

    banner('Configuration')
    locations = ctx.obj.cfg.locations(exists=False)
    locations = [(u'✔' if os.path.exists(i) else u'✘', click.pretty_path(i)) for i in locations]
    click.echo(u'The following configuration files are merged in order, if they exist:\n    {0}'.format(
        u'\n    '.join(u'{}   {}'.format(*i) for i in locations),
    ))

    banner('Vault Information')
    try:
        conn = vault.Connection()
    except ValueError as cause:
        if "target" in str(cause):
            click.serror("{} -- forgot to edit configuration or set VAULT_ADDR?", cause)
        else:
            raise
    else:
        print(conn)
        policies = conn.api.list_policies()
        if 'root' in policies:
            click.secho("WARN: You are connected using a 'root' token!",
                fg='yellow', bg='black', bold=True, reverse=True)
        print("Policies: {}".format(', '.join(policies)))
        print("Auth Backends:")
        for mount, data in conn.api.list_auth_backends().items():
            print("    {mount:15s} {type:15s} {description}".format(mount=mount, **data))
        print("Storage:")
        for mount, data in conn.api.list_secret_backends().items():
            print("    {mount:15s} {type:15s} {description}".format(mount=mount, **data))

    banner('More Help')
    click.echo("Call '{} --help' to get a list of available commands & options.".format(app_name))
    click.echo("Call '{} «command» --help' to get help on a specific command.".format(app_name))
    click.echo("Call '{} --version' to get the above version information separately.".format(app_name))
    click.echo("Call '{} --license' to get licensing informatioon.".format(app_name))
Пример #5
0
    def dump_diff(self, changed):
        """Dump a diff to terminal between changed and stored body."""
        if self.body == changed:
            click.secho('=== No changes to "{0}"'.format(self.title), fg='green')
            return

        diff = difflib.unified_diff(
            _pretty_xml(self.body, self.markup),
            _pretty_xml(changed, self.markup),
            u'v. {0} of "{1}"'.format(self.version, self.title).encode('utf8'),
            u'v. {0} of "{1}"'.format(self.version + 1, self.title).encode('utf8'),
            arrow.get(self._data.version.when).replace(microsecond=0).isoformat(sep=b' '),
            arrow.now().replace(microsecond=0).isoformat(sep=b' '),
            lineterm='', n=2)
        for line in diff:
            click.secho(line, fg=self.DIFF_COLS.get(line and line[0], None))
Пример #6
0
    def dump_diff(self, changed):
        """Dump a diff to terminal between changed and stored body."""
        if self.body == changed:
            click.secho('=== No changes to "{0}"'.format(self.title), fg='green')
            return

        diff = difflib.unified_diff(
            _pretty_xml(self.body, self.markup),
            _pretty_xml(changed, self.markup),
            u'v. {0} of "{1}"'.format(self.version, self.title).encode('utf8'),
            u'v. {0} of "{1}"'.format(self.version + 1, self.title).encode('utf8'),
            arrow.get(self._data.version.when).replace(microsecond=0).isoformat(sep=b' '),
            arrow.now().replace(microsecond=0).isoformat(sep=b' '),
            lineterm='', n=2)
        for line in diff:
            click.secho(line, fg=self.DIFF_COLS.get(line and line[0], None))
Пример #7
0
def login(ctx):
    """Set or change Vault login credentials in your keyring."""
    if not keyring:
        raise UsageError("'keyring' support is not available, please read"
            " 'https://config-sesame.readthedocs.io/en/latest/deploy.html'!", ctx=ctx)
    url, user, token, _ = vault.default_credentials()
    if not url:
        raise UsageError("You MUST provide a VAULT_ADDR!", ctx=ctx)
    if token:
        click.secho("WARN: You have a VAULT_TOKEN variable in your environment,"
                    " which will override any keyring credentials!",
                    fg='yellow', bg='black', bold=True, reverse=True)

    click.echo("Please enter credentials for storing in {}.{}..."
               .format(keyring.get_keyring().__class__.__module__, keyring.get_keyring().__class__.__name__))
    access = security.Credentials(url)
    user, token = access.auth_pair(force_console=True)  # Prompt for new password
    keyring.set_password(url, user, token)
    click.echo("Updated {}'s password (token) for {}".format(user, url))
Пример #8
0
def help_command(ctx, config_dump=False):
    """Print some information on the system environment."""
    def banner(title):
        "Helper"
        click.echo('')
        click.secho('~~~ {} ~~~'.format(title), fg='green', bg='black', bold=True)

    if config_dump:
        ctx.obj.cfg.dump()
        sys.exit(0)

    app_name = ctx.find_root().info_name
    click.secho('*** "{}" Help & Information ***'.format(app_name), fg='white', bg='blue', bold=True)

    banner('Version Information')
    click.echo(config.version_info(ctx))

    banner('Configuration')
    locations = ctx.obj.cfg.locations(exists=False)
    locations = [(u'✔' if os.path.exists(i) else u'✘', click.pretty_path(i)) for i in locations]
    click.echo(u'The following configuration files are merged in order, if they exist:\n    {0}'.format(
        u'\n    '.join(u'{}   {}'.format(*i) for i in locations),
    ))

    banner('Confluence Stats')
    with api.context() as cf:
        try:
            spaces = list(cf.getall('space'))
        except api.ERRORS as cause:
            # Just log and otherwise ignore any errors
            click.serror("API ERROR: {}", cause)
        else:
            click.echo(u'{} spaces found.'.format(len(spaces)))
            click.echo(u'\nMost recently created:')
            for space in itertools.islice(sorted(spaces, key=lambda i: i.id, reverse=True), 5):
                click.echo(u'    {:10} {:>15} {}'.format(space.type, space.key, space.name))

    banner('More Help')
    click.echo("Call '{} --help' to get a list of available commands & options.".format(app_name))
    click.echo("Call '{} «command» --help' to get help on a specific command.".format(app_name))
    click.echo("Call '{} --version' to get the above version information separately.".format(app_name))
    click.echo("Call '{} --license' to get licensing informatioon.".format(app_name))
Пример #9
0
def help_command(ctx, config_dump=False):
    """Print some information on the system environment."""
    def banner(title):
        "Helper"
        click.echo('')
        click.secho('~~~ {} ~~~'.format(title),
                    fg='green',
                    bg='black',
                    bold=True)

    if config_dump:
        ctx.obj.cfg.dump()
        sys.exit(0)

    app_name = ctx.find_root().info_name
    click.secho('*** "{}" Help & Information ***'.format(app_name),
                fg='white',
                bg='blue',
                bold=True)

    banner('Version Information')
    click.echo(config.version_info(ctx))

    banner('Configuration')
    locations = ctx.obj.cfg.locations(exists=False)
    locations = [(u'✔' if os.path.exists(i) else u'✘', click.pretty_path(i))
                 for i in locations]
    click.echo(
        u'The following configuration files are merged in order, if they exist:\n    {0}'
        .format(u'\n    '.join(u'{}   {}'.format(*i) for i in locations), ))

    banner('Confluence Stats')
    with api.context() as cf:
        try:
            user = cf.user()
            spaces = list(cf.getall('space'))
        except api.ERRORS as cause:
            # Just log and otherwise ignore any errors
            api.diagnostics(cause)
        else:
            click.echo(
                u'Confluence API [{u._info.server} / {u._info.sen}]'
                u' accessed as {u.displayName} [{u.username}].'.format(u=user))
            click.echo(u'{} spaces found.'.format(len(spaces)))
            click.echo(u'\nMost recently created:')
            for space in itertools.islice(
                    sorted(spaces, key=lambda i: i.id, reverse=True), 5):
                click.echo(u'    {:10} {:>15} {}'.format(
                    space.type, space.key, space.name))

    banner('More Help')
    click.echo(
        "Call '{} --help' to get a list of available commands & options.".
        format(app_name))
    click.echo(
        "Call '{} «command» --help' to get help on a specific command.".format(
            app_name))
    click.echo(
        "Call '{} --version' to get the above version information separately.".
        format(app_name))
    click.echo(
        "Call '{} --license' to get licensing informatioon.".format(app_name))
Пример #10
0
 def banner(title):
     "Helper"
     click.echo('')
     click.secho('~~~ {} ~~~'.format(title), fg='green', bg='black', bold=True)
Пример #11
0
def help_command(ctx, config_dump=False):
    """Print some information on the system environment."""
    def banner(title):
        "Helper"
        click.echo('')
        click.secho('~~~ {} ~~~'.format(title),
                    fg='green',
                    bg='black',
                    bold=True)

    if config_dump:
        ctx.obj.cfg.dump()
        sys.exit(0)

    app_name = ctx.find_root().info_name
    click.secho('*** "{}" Help & Information ***'.format(app_name),
                fg='white',
                bg='blue',
                bold=True)

    banner('Version Information')
    click.echo(config.version_info(ctx))

    banner('Configuration')
    locations = ctx.obj.cfg.locations(exists=False)
    locations = [(u'✔' if os.path.exists(i) else u'✘', click.pretty_path(i))
                 for i in locations]
    click.echo(
        u'The following configuration files are merged in order, if they exist:\n    {0}'
        .format(u'\n    '.join(u'{}   {}'.format(*i) for i in locations), ))

    banner('Active Login')
    try:
        api = github.api(config=None)  # TODO: config object
    except AssertionError as cause:
        click.serror("AUTH: {}", cause)
    else:
        try:
            dump_user(api, api.gh_config.user)
            limit = api.ratelimit_remaining
            fgcol = 'yellow' if limit >= 100 else 'cyan'
            click.secho('\n{} calls remaining in this hour.'.format(limit),
                        fg=fgcol,
                        bg='black',
                        bold=True)
        except ConnectionError as cause:
            click.serror("HTTP: {}", cause)
        except github.GitHubError as cause:
            click.serror(github.pretty_cause(cause, "API"))

    banner('More Help')
    click.echo(
        "Call '{} --help' to get a list of available commands & options.".
        format(app_name))
    click.echo(
        "Call '{} «command» --help' to get help on a specific command.".format(
            app_name))
    click.echo(
        "Call '{} --version' to get the above version information separately.".
        format(app_name))
    click.echo(
        "Call '{} --license' to get licensing informatioon.".format(app_name))