コード例 #1
0
ファイル: entrypoint.py プロジェクト: boxnwhiskr/gbscli
def list_services(cred, url):
    """Get all service configurations"""
    try:
        headers = auth(get_cred(cred))
        req = url + '/services'
        res = requests.get(req, headers=headers)
        render_res(res)
    except CLIError as e:
        render_error(e.asdict())
コード例 #2
0
ファイル: entrypoint.py プロジェクト: boxnwhiskr/gbscli
def get_goals_stats(svc_id, exp_id, cred, url):
    try:
        req = url + '/stats/goals?svc_id=' + svc_id + '&exp_id=' + exp_id
        header = auth(get_cred(cred))
        header.update({'Accept': 'text/csv'})
        res = requests.get(req, headers=header)
        click.echo(res.text)
    except CLIError as e:
        render_error(e.asdict())
コード例 #3
0
ファイル: entrypoint.py プロジェクト: boxnwhiskr/gbscli
def delete_service(svc_id, cred, url):
    """Delete service configuration"""
    try:
        headers = auth(get_cred(cred))
        req = url + '/services/' + svc_id
        res = requests.delete(req, headers=headers)
        render_res(res)
    except CLIError as e:
        render_error(e.asdict())
コード例 #4
0
ファイル: entrypoint.py プロジェクト: boxnwhiskr/gbscli
def describe_acount(cred, url):
    """Get account information."""
    try:
        credential = get_cred(cred)
        headers = auth(credential)
        req = url + '/accounts/' + credential['account_id']
        res = requests.get(req, headers=headers)
        render_res(res)
    except CLIError as e:
        render_error(e.asdict())
コード例 #5
0
ファイル: entrypoint.py プロジェクト: boxnwhiskr/gbscli
def edit_service(svc_id, cred, url):
    """Create or update service configuration"""
    try:
        headers = auth(get_cred(cred))

        # Get current config
        req = url + '/services/' + svc_id
        res = requests.get(req, headers=headers)
        if res.status_code == 200:
            cur = res.json()
            read_only_fields = ['account_id', 'svc_id', 'update_dt']
            for f in read_only_fields:
                del cur[f]
        elif res.status_code == 404:
            cur = {
                'experiments': [],
                'goals': [],
            }
        else:
            render_res(res)
            return

        # Launch editor
        new = click.edit(json.dumps(cur, indent=4),
                         require_save=True,
                         extension='.json')

        # Do nothing if user didn't save the content on the editor
        if new is None:
            click.secho('Configuration not saved.', fg='yellow')
            return

        try:
            parsed = json.loads(new)
        except ValueError as e:
            # Catch ValueError since python 3.4 doesn't have JSONDecodeError
            raise CLIError(str(e))
        else:
            res = requests.put(req, headers=headers, json=parsed)
            render_res(res)
    except CLIError as e:
        render_error(e.asdict())
コード例 #6
0
def header():
    return auth(CRED)