Example #1
0
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())
Example #2
0
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())
Example #3
0
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())
Example #4
0
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())
Example #5
0
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())