Example #1
0
File: cli.py Project: jmcs/kio-cli
def list_versions(config, application_id, output, since):
    '''List application versions'''
    url = get_url(config)
    token = get_token()

    since_str = parse_since(since)

    params = {}
    r = request(url, '/apps/{}/versions'.format(application_id), token, params=params)
    r.raise_for_status()
    data = r.json()

    rows = []
    for row in data:
        if row['last_modified'] < since_str:
            continue
        r = request(url, '/apps/{}/versions/{}/approvals'.format(application_id, row['id']), token)
        row['approvals'] = ', '.join(['{}: {}'.format(x['approval_type'], x['user_id']) for x in r.json()])
        row['last_modified_time'] = parse_time(row['last_modified'])
        rows.append(row)

    # we get the newest violations first, but we want to print them in order
    rows.sort(key=lambda r: r['last_modified_time'])

    with OutputFormat(output):
        print_table(['application_id', 'id', 'artifact', 'approvals', 'last_modified_time'],
                    rows, titles={'last_modified_time': 'Modified'})
Example #2
0
File: cli.py Project: jmcs/kio-cli
def list_apps(config, output, since, team, **kwargs):
    '''List applications'''
    url = get_url(config)
    token = get_token()

    since_str = parse_since(since) if since else ''

    params = {}
    r = request(url, '/apps', token, params=params)
    r.raise_for_status()
    data = r.json()

    rows = []
    for row in data:
        if not row['active'] and not kwargs['all']:
            continue

        if team and row['team_id'] != team:
            continue

        if row['last_modified'] < since_str:
            continue

        row['last_modified_time'] = parse_time(row['last_modified'])
        rows.append(row)

    # we get the newest violations first, but we want to print them in order
    rows.sort(key=lambda r: r['id'])

    with OutputFormat(output):
        print_table(['id', 'team_id', 'name', 'subtitle', 'last_modified_time'],
                    rows, titles={'last_modified_time': 'Modified'}, max_column_widths={'name': 32, 'subtitle': 32})
Example #3
0
File: cli.py Project: jmcs/kio-cli
def update(config, application_id, key_val_pairs):
    '''Update a single application

    kio app up APPLICATION_ID KEY1=VAL1 ..'''
    url = get_url(config)
    token = get_token()

    r = request(url, '/apps/{}'.format(application_id), token)
    r.raise_for_status()
    data = r.json()
    for key_val in key_val_pairs:
        key, sep, val = key_val.partition('=')
        if key not in data:
            raise click.UsageError('Field "{}" does not exist'.format(key))
        if not val:
            raise click.UsageError('Value missing for field "{}". You must provide KEY=VAL pairs.'.format(key))
        if isinstance(data[key], bool):
            val = val == 'true'
        data[key] = val
    # remove fields which we can't update
    for key in ('id', 'last_modified', 'last_modified_by', 'criticality_level', 'created', 'created_by'):
        del data[key]
    with Action('Updating application {}..'.format(application_id)):
        r = session.put('{}/apps/{}'.format(url, application_id),
                        headers={'Authorization': 'Bearer {}'.format(token),
                                 'Content-Type': 'application/json'},
                        timeout=10,
                        data=json.dumps(data))
        r.raise_for_status()
Example #4
0
File: cli.py Project: jmcs/kio-cli
def show_version(config, application_id, version, output):
    '''Show version details'''
    url = get_url(config)
    token = get_token()

    r = request(url, '/apps/{}/versions/{}'.format(application_id, version), token)
    r.raise_for_status()

    rows = [{'key': k, 'value': v} for k, v in sorted(r.json().items())]

    r = request(url, '/apps/{}/versions/{}/approvals'.format(application_id, version), token)
    r.raise_for_status()

    for approval in r.json():
        txt = '{approval_type} by {user_id} on {approved_at}'.format(**approval)
        rows.append({'key': 'approvals', 'value': txt})

    with OutputFormat(output):
        print_table(['key', 'value'], rows)
Example #5
0
File: cli.py Project: jmcs/kio-cli
def show_app(config, application_id, output):
    '''Show application'''
    url = get_url(config)
    token = get_token()

    r = request(url, '/apps/{}'.format(application_id), token)
    r.raise_for_status()

    rows = [{'key': k, 'value': v} for k, v in sorted(r.json().items())]

    with OutputFormat(output):
        print_table(['key', 'value'], rows)