Package to interact with the V6 API of Transip
Project description
Transip-API-v6
This repo contains a package for Python3 to connect to the API of transip.
For more information about the Transip API go to https://api.transip.nl/rest/docs.html
Currently this is package mainly supports all actions on DNS. It can be easily extended.
Example python code:
#!/usr/bin/env python3
import requests
import json
import transip_api_v6
login = 'username' # Username from Transip
keyfile = 'test copy.pem' # Key generated @ Transip API page
domain = 'gemert.net' # Domain it concers
find_dns_entry = 'home-server' # Domain entry on which you want to access
# Get public IP
res = requests.get('https://ipinfo.io')
if res.status_code != 200:
print('Failed to get public ip.')
exit(1)
pub_ip=json.loads(res.text)['ip']
# Get Header for authentication against transip api V6
key_file = open(keyfile, "r")
key = key_file.read()
key_file.close()
# ph = transip_api_v6.Generic(login, key)
headers = transip_api_v6.Generic(login, key).get_headers()
# Request DNS entries for this domain
dns_entries = domains.list_dns_entries(domain)
# Find entry
found_dns_entries = []
for dns_entry in dns_entries['dnsEntries']:
if dns_entry['name'] == find_dns_entry and dns_entry['type'] == 'A':
found_dns_entries.append(dns_entry)
# Change entry for this domain with current public IP
if len(found_dns_entries) == 0:
data = '''{
"dnsEntry": {
"name": "''' + find_dns_entry + '''",
"expire": 300,
"type": "A",
"content": "''' + pub_ip + '''"
}
}
'''
domains.add_dns_entry(domain, data)
elif len(found_dns_entries) == 1:
if found_dns_entries[0]['content'] == pub_ip:
print('No change needed')
else:
print('Change dns entry')
print('From: ' + json.dumps(found_dns_entries[0]))
found_dns_entries[0]['content'] = pub_ip
print('To : ' + json.dumps(found_dns_entries[0]))
domains.update_dns_entry(domain, '{"dnsEntry": ' + json.dumps(found_dns_entries[0]) +'}')
else:
print('Multiple entries found, can\'t determine which to change (if any).')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
transipApiV6-0.0.1.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for transipApiV6-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4aaa130f7d8576a180f511dc3d76372063d47ab5f25bc7908795fa2cb16f1e1e |
|
MD5 | 6a8af6321e1a8989a9d4a3e54db7e69a |
|
BLAKE2b-256 | 7df003c8e8ecb729458dd04ce69b150deb9de4ac67cfb94780bde1fece4eaf49 |