44 lines
901 B
Python
44 lines
901 B
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""API client to core-networks"""
|
|
|
|
import requests
|
|
import os
|
|
import json
|
|
import urlparse
|
|
import configparser
|
|
|
|
|
|
def api_auth(user, passwd, host):
|
|
data = {}
|
|
data["login"] = user
|
|
data["password"] = passwd
|
|
json_data = json.dumps(data)
|
|
|
|
url = urlparse.urljoin(host, "auth", "token")
|
|
r = requests.post(url, data=json_data)
|
|
return r
|
|
|
|
|
|
def main():
|
|
"""Main logic entrypoint"""
|
|
|
|
try:
|
|
config_path = os.path.join(os.path.expanduser("~"), "config.ini")
|
|
config = configparser.ConfigParser()
|
|
config.read(config_path)
|
|
|
|
API_HOST = config['API']['HOST']
|
|
API_USER = config['API']['USER']
|
|
PASSWORD = config['API']['PASSWORD']
|
|
except configparser.Error:
|
|
return
|
|
|
|
auth_token = api_auth(API_USER, PASSWORD, API_HOST)
|
|
print auth_token
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|