fix auth method
This commit is contained in:
parent
ddfa0a8a5a
commit
34211dec87
|
@ -8,6 +8,8 @@ import os
|
||||||
import json
|
import json
|
||||||
import urlparse
|
import urlparse
|
||||||
import configparser
|
import configparser
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
def api_auth(user, passwd, host):
|
def api_auth(user, passwd, host):
|
||||||
|
@ -16,27 +18,51 @@ def api_auth(user, passwd, host):
|
||||||
data["password"] = passwd
|
data["password"] = passwd
|
||||||
json_data = json.dumps(data)
|
json_data = json.dumps(data)
|
||||||
|
|
||||||
url = urlparse.urljoin(host, "auth", "token")
|
url = urlparse.urljoin(host, os.path.join("auth", "token"))
|
||||||
r = requests.post(url, data=json_data)
|
r = requests.post(url, data=json_data)
|
||||||
return r
|
return r.json()
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logger():
|
||||||
|
# seup logging
|
||||||
|
logger = logging.getLogger("certbot_dns_corenetworks")
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
# create console handler
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
formatter = logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s- %(levelname)s - %(message)s')
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
# add handler to logger
|
||||||
|
logger.addHandler(ch)
|
||||||
|
logger.propagate = False
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main logic entrypoint"""
|
"""Main logic entrypoint"""
|
||||||
|
|
||||||
|
logger = setup_logger()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config_path = os.path.join(os.path.expanduser("~"), "config.ini")
|
config_path = os.path.join(
|
||||||
|
os.path.expanduser("~"),
|
||||||
|
".certbot_dns_corenetworks",
|
||||||
|
"config.ini"
|
||||||
|
)
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_path)
|
config.read(config_path)
|
||||||
|
|
||||||
API_HOST = config['API']['HOST']
|
API_HOST = config['API']['HOST']
|
||||||
API_USER = config['API']['USER']
|
API_USER = config['API']['USER']
|
||||||
PASSWORD = config['API']['PASSWORD']
|
PASSWORD = config['API']['PASSWORD']
|
||||||
except configparser.Error:
|
except KeyError, e:
|
||||||
return
|
logger.error("Key %s not found in config" % (e))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
auth_token = api_auth(API_USER, PASSWORD, API_HOST)
|
auth = api_auth(API_USER, PASSWORD, API_HOST)
|
||||||
print auth_token
|
print auth["token"]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Reference in New Issue