Skip to main content

Python wrapper for the Websupport.sk REST API

Project description

python-websupportsk

Python wrapper for the Websupport.sk REST API.
The Websupportsk REST API can be found here.

Current API support

✅ DNS management (v0.1.0+)
❌ Hosting management
❌ VPS management

Python 2.x vs 3.x support

Code is Python3 clean, developed under version 3.9. Python2 is not supported.

Installation

Two methods are provided to install this software. Use PyPi (see package details) or GitHub (see package details).

Via PyPI

    $ sudo pip install websupportsk
    $

Via GitHub

    $ git clone https://github.com/JozefGalbicka/python-websupportsk
    $ cd python-websupportsk
    $ ./setup.py build
    $ sudo ./setup.py install
    $

Example code

All example code is available on GitHub (see package in the examples folder).

Getting Started

Direct authentication in code itself.

import websupportsk

identifier = "your-identifier"
secret_key = "your-secret-key"
domain = "example.com"

client = websupportsk.Client(identifier, secret_key, domain)

print(client.test_connection())


File based authentication. This or similar solution is more secure and recommended, as you can limit file privileges to root only.

import websupportsk
import json

with open("/path/to/config.json", "r") as config_file:
    config = json.load(config_file)

client = websupportsk.Client(config['authentication']['identifier'],
                             config['authentication']['secret_key'],
                             config['registered_domain'])

print(client.test_connection())


DNS record creation with error example.

import websupportsk
import json
client = websupportsk.Client("your-identifier", "your-secret_key", "example.com")

ip_addresses = ["56.67.78.89", "45.56.67.78"]

for ip in ip_addresses:
    response = client.create_record(type_="A", name="www", content=ip)
    if response['errors']:  # if error key in response is not empty(contains some errors)
        print("Request failed, response:")
        print(json.dumps(response, indent=4))  # pretty-printed JSON

# Request failed, response:
# {
#     "status": "error",
#     "item": {
#         "type": "A",
#         "id": null,
#         "name": "www",
#         "content": "45.56.67.78",
#         "ttl": 600,
#         "note": null,
#         "zone": {
#             "name": "example.com",
#             "service_id": 1234657,
#             "updateTime": 1234567890
#         }
#     },
#     "errors": {
#         "content": [
#             "For specified address already exists A record. It can not be overwritten. You need to edit it or delete it."
#         ]
#     }
# }

Debugging

If you feel like debugging, here is simple logger configuration to show debug messages.

import logging

logging.basicConfig()
logging.getLogger('urllib3').setLevel(logging.WARNING) # disable `requests` debug messages if you want to.
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

websupportsk-0.1.2.tar.gz (6.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page