This repository has been archived on 2021-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
certbot_dns_corenetworks/authenticator.py

44 lines
901 B
Python
Raw Normal View History

2018-06-05 00:32:16 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2018-06-06 21:38:20 +02:00
"""API client to core-networks"""
import requests
import os
import json
import urlparse
import configparser
2018-06-06 21:38:20 +02:00
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"""
2018-06-09 22:46:31 +02:00
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)
2018-06-06 21:38:20 +02:00
print auth_token
if __name__ == "__main__":
main()