Exemple #1
0
def delhost(subdomain):
    recid = str(listhosts(subdomain))

    headers = {"Authorization": "Bearer " + env('TOKEN')}
    values = {}
    url = url = 'https://api.digitalocean.com/v2/domains/' + (
        env('DOMAIN')) + '/records/' + recid

    data = urllib.parse.urlencode(values)
    data = data.encode('ascii')
    req = urllib.request.Request(url, data, headers, method='DELETE')
    with urllib.request.urlopen(req) as response:
        print(response.read())
Exemple #2
0
def listhosts(subdomain):
    headers = {"Authorization": "Bearer " + env('TOKEN')}
    url = 'https://api.digitalocean.com/v2/domains/' + (
        env('DOMAIN')) + '/records'

    req = urllib.request.Request(url, headers=headers)
    request = urllib.request.urlopen(req)

    data = json.loads(request.read().decode(request.info().get_param('charset')
                                            or 'utf-8'))
    for i in (data['domain_records']):
        for k, v in i.items():
            if v == subdomain:
                recid = (i['id'])
                return recid
Exemple #3
0
def addhost(subdomain, ip):
    if ip == '':
        ip = '127.0.0.1'
    headers = {"Authorization": "Bearer " + env('TOKEN')}
    values = {
        'name': subdomain,
        'type': 'A',
        'ttl': '1800',
        'data': ip,
        'priority': 'null',
        'port': 'null',
        'weight': 'null',
        'flags': 'null',
        'tag': 'null'
    }
    url = 'https://api.digitalocean.com/v2/domains/' + (
        env('DOMAIN')) + '/records'

    data = urllib.parse.urlencode(values)
    data = data.encode('ascii')
    req = urllib.request.Request(url, data, headers)
    with urllib.request.urlopen(req) as response:
        print(response.read())
Exemple #4
0
from pathlib import Path

import yaml
from defaultenv import env

from ._config import Config

__all__ = ["config"]

config_dict = dict(
    API_TOKEN=env("API_TOKEN"),
    sse=dict(host=env("SSE_HOST"), port=env("SSE_PORT")),
    rabbit=dict(
        host=env("RABBIT_HOST"),
        port=env("RABBIT_PORT"),
        login=env("RABBIT_LOGIN"),
        pwd=env("RABBIT_PWD"),
        rabbit_queue=env("RABBIT_QUEUE"),
    ),
)

config = Config(dict_config=config_dict)

with open(Path(__file__).parent.absolute() / "logging.yml") as f:
    logging_config = yaml.load(f, Loader=yaml.SafeLoader)

path_to_configs = Path("logs") / logging_config["handlers"]["file"]["filename"]
logging_config["handlers"]["file"]["filename"] = path_to_configs

config["logging"] = logging_config
Exemple #5
0
def puship():
    subdomain = (env('SUBDOMAIN'))
    ip = get('https://api.ipify.org').text

    updatehost(subdomain, ip)