Пример #1
0
def auth_check():
    """Checks if user/pass exist."""
    username = cfg.get_conf(cfg.USERNAME_KEY)
    password = cfg.get_password()

    if not username or not password:
        click.echo('Credentials not found. Run `vcl config`.')
        sys.exit(1)
Пример #2
0
def auth_check():
    """Checks if user/pass exist."""
    username = cfg.get_conf(cfg.USERNAME_KEY)
    password = cfg.get_password()

    if not username or not password:
        click.echo('Credentials not found. Run `vcl config`.')
        sys.exit(1)
Пример #3
0
def call_api(endpoint, params):
    """Calls the API."""
    auth_check()

    base_url = cfg.get_conf(cfg.ENDPOINT_KEY)
    username = cfg.get_conf(cfg.USERNAME_KEY)
    data = xmlrpclib.dumps(params, endpoint)
    headers = {
        'Content-Type': 'text/xml',
        'X-User': username,
        'X-Pass': cfg.get_password(),
        'X-APIVERSION': '2'
    }

    req = urllib2.Request(base_url, data, headers)
    response = urllib2.urlopen(req)

    raw_xml = response.read()
    return xmlrpclib.loads(raw_xml)[0][0]
Пример #4
0
def call_api(endpoint, params):
    """Calls the API."""
    auth_check()

    base_url = cfg.get_conf(cfg.ENDPOINT_KEY)
    username = cfg.get_conf(cfg.USERNAME_KEY)
    data = xmlrpclib.dumps(params, endpoint)
    headers = {
        'Content-Type': 'text/xml',
        'X-User': username,
        'X-Pass': cfg.get_password(),
        'X-APIVERSION': '2'
    }

    req = urllib2.Request(base_url, data, headers)
    response = urllib2.urlopen(req)

    raw_xml = response.read()
    return xmlrpclib.loads(raw_xml)[0][0]