create_challenge.py 1.17 KiB
#!/usr/bin/env python3
""" Add Acme challenges to Infoblox """
import os
import time
import configparser
import requests
def create_acme(iblox_domain, acme_token, iblox_user, iblox_pw):
""" upload txt record """
post_req = requests.post(
'https://infoblox.geant.org/wapi/v2.6.1/record:txt',
auth=(iblox_user, iblox_pw),
data={
'name': '_acme-challenge.{}'.format(iblox_domain),
'text': acme_token,
'ttl': '60',
"view": "External"
}
)
return post_req.status_code
# Here we Go.
if __name__ == "__main__":
CONFIG = configparser.RawConfigParser()
CONFIG.read_file(open('/root/.geant_acme.ini'))
IBLOX_PASS = CONFIG.get('geant_acme', 'iblox_pass')
IBLOX_USER = CONFIG.get('geant_acme', 'iblox_user')
ARGS = os.sys.argv
_ = ARGS.pop(0)
for host in ARGS:
if ARGS.index(host) % 2 == 0:
token = ARGS.index(host)+1
http_code = create_acme(host, ARGS[token], IBLOX_USER, IBLOX_PASS)
if http_code != 201:
print('could not create {} for {}'.format(ARGS[token], host))
os.sys.exit(1)
time.sleep(10)