Ejemplo n.º 1
0
def cli(ctx, config_file, profile, endpoint_url, output, color, debug):
    """
    Alerta client unified command-line tool.
    """
    config = Config(config_file)
    config.get_config_for_profle(profile)
    config.get_remote_config(endpoint_url)

    ctx.obj = config.options

    # override current options with command-line options or environment variables
    ctx.obj['output'] = output or config.options['output']
    ctx.obj['color'] = color or os.environ.get('CLICOLOR',
                                               None) or config.options['color']
    endpoint = endpoint_url or config.options['endpoint']

    ctx.obj['client'] = Client(endpoint=endpoint,
                               key=config.options['key'],
                               token=get_token(endpoint),
                               username=config.options.get('username', None),
                               password=config.options.get('password', None),
                               timeout=float(config.options['timeout']),
                               ssl_verify=config.options['sslverify'],
                               debug=debug or os.environ.get('DEBUG', None)
                               or config.options['debug'])
Ejemplo n.º 2
0
def cli(ctx, config_file, profile, endpoint_url, output, color, debug):
    """
    Alerta client unified command-line tool.
    """
    config = Config(config_file)
    config.get_config_for_profle(profile)

    ctx.obj = dict()
    ctx.obj['timezone'] = config.options['timezone']
    ctx.obj['output'] = output or config.options['output']
    ctx.obj['color'] = color or os.environ.get('CLICOLOR', None) or config.options['color']
    endpoint = endpoint_url or config.options['endpoint']
    ctx.obj['provider'] = config.options['provider']
    ctx.obj['client_id'] = config.options['client_id']
    ctx.obj['github_url'] = config.options['github_url']
    ctx.obj['gitlab_url'] = config.options['gitlab_url']

    ctx.obj['client'] = Client(
        endpoint=endpoint,
        key=config.options['key'],
        token=get_token(endpoint),
        timeout=float(config.options['timeout']),
        ssl_verify=config.options['sslverify'],
        debug=debug or os.environ.get('DEBUG', None) or config.options['debug']
    )
Ejemplo n.º 3
0
def cli(obj, decode):
    """Display the auth token for logged in user, with option to decode it."""
    client = obj['client']
    token = get_token(client.endpoint)
    if decode:
        jwt = Jwt()
        for k, v in jwt.parse(token).items():
            if isinstance(v, list):
                v = ', '.join(v)
            click.echo(f'{k:20}: {v}')
    else:
        click.echo(token)
Ejemplo n.º 4
0
def cli(obj):
    """Display the auth token for logged in user."""
    client = obj['client']
    click.echo(get_token(client.endpoint))