Compare commits
4 commits
c14decbd44
...
9363de2db1
Author | SHA1 | Date | |
---|---|---|---|
|
9363de2db1 | ||
|
4726ec0b08 | ||
|
ff1fdebefe | ||
|
a2019df56d |
3 changed files with 25 additions and 25 deletions
|
@ -15,7 +15,7 @@ steps:
|
||||||
image: python:3-alpine
|
image: python:3-alpine
|
||||||
commands:
|
commands:
|
||||||
- python3 -m pip install twine
|
- python3 -m pip install twine
|
||||||
- python3 -m twine upload --repository testpypi dist/*
|
- python3 -m twine upload --repository pypi dist/*
|
||||||
environment:
|
environment:
|
||||||
TWINE_PASSWORD:
|
TWINE_PASSWORD:
|
||||||
from_secret: pypi-token
|
from_secret: pypi-token
|
||||||
|
@ -27,7 +27,7 @@ steps:
|
||||||
image: python:3-alpine
|
image: python:3-alpine
|
||||||
commands:
|
commands:
|
||||||
- python3 -m pip install twine
|
- python3 -m pip install twine
|
||||||
- python3 -m twine upload --repository-url https://forgejo.example.com/api/packages/minecraftchest1/pypi dist/*
|
- python3 -m twine upload --repository-url https://code.minecraftchest1.us/api/packages/minecraftchest1/pypi dist/*
|
||||||
environment:
|
environment:
|
||||||
TWINE_USERNAME: minecraftchest1
|
TWINE_USERNAME: minecraftchest1
|
||||||
TWINE_PASSWORD:
|
TWINE_PASSWORD:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
from .dnscode import *
|
|
@ -79,15 +79,15 @@ class CNAME(Record):
|
||||||
|
|
||||||
#target: str
|
#target: str
|
||||||
|
|
||||||
def __init__(self, name: str = '@', ttl: int = 3600, target: str = 'example.com'):
|
def __init__(self, name: str = '@', ttl: int = 3600, host: str = 'example.com'):
|
||||||
self.rtype = 'CNAME'
|
self.rtype = 'CNAME'
|
||||||
self.name = name
|
self.name = name
|
||||||
self.ttl = ttl
|
self.ttl = ttl
|
||||||
|
|
||||||
if fqdn.FQDN(target).is_valid:
|
if fqdn.FQDN(host).is_valid:
|
||||||
self.data = target
|
self.data = host
|
||||||
else:
|
else:
|
||||||
raise InvalidDataException(message=f'{target} is not a valid FQDN')
|
raise InvalidDataException(message=f'{host} is not a valid FQDN')
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MX(Record):
|
class MX(Record):
|
||||||
|
@ -114,16 +114,16 @@ class NS(Record):
|
||||||
|
|
||||||
#target: str
|
#target: str
|
||||||
|
|
||||||
def __init__(self, name: str = '@', ttl: int = 3600, target: str = 'example.com'):
|
def __init__(self, name: str = '@', ttl: int = 3600, host: str = 'example.com'):
|
||||||
self.rtype = 'NS'
|
self.rtype = 'NS'
|
||||||
self.name = name
|
self.name = name
|
||||||
self.ttl = ttl
|
self.ttl = ttl
|
||||||
self.target = target
|
self.host = target
|
||||||
|
|
||||||
if fqdn.FQDN(target).is_valid:
|
if fqdn.FQDN(host).is_valid:
|
||||||
self.data = target
|
self.data = host
|
||||||
else:
|
else:
|
||||||
raise InvalidDataException(message=f'{target} is not a valid FQDN')
|
raise InvalidDataException(message=f'{host} is not a valid FQDN')
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PTR(Record):
|
class PTR(Record):
|
||||||
|
@ -178,7 +178,7 @@ class SRV(Record):
|
||||||
#target: str
|
#target: str
|
||||||
|
|
||||||
def __init__(self, name: str = '@', ttl: int = 3600, service: str = "service", protocol: str = 'proto',
|
def __init__(self, name: str = '@', ttl: int = 3600, service: str = "service", protocol: str = 'proto',
|
||||||
priority: int = 10, weight: int = 10, port: int = 0, target: str = 'example.com'):
|
priority: int = 10, weight: int = 10, port: int = 0, host: str = 'example.com'):
|
||||||
self.rtype = 'SRV'
|
self.rtype = 'SRV'
|
||||||
self.name = f"_{service}._{protocol}.{name}"
|
self.name = f"_{service}._{protocol}.{name}"
|
||||||
self.ttl = ttl
|
self.ttl = ttl
|
||||||
|
@ -195,12 +195,11 @@ class SRV(Record):
|
||||||
|
|
||||||
self.data = f"{self.priority} {self.weight} {self.port} {self.target}"
|
self.data = f"{self.priority} {self.weight} {self.port} {self.target}"
|
||||||
|
|
||||||
@dataclass
|
#@dataclass
|
||||||
class Zone:
|
class Zone:
|
||||||
"""Represents a DNS zone containing multiple records."""
|
"""Represents a DNS zone containing multiple records."""
|
||||||
|
|
||||||
origin: str
|
origin: str
|
||||||
records: list = field(default_factory=list)
|
records:list = []
|
||||||
|
|
||||||
def __init__(self, origin: str):
|
def __init__(self, origin: str):
|
||||||
"""Initializes a zone with the given origin and ensures it ends with a dot."""
|
"""Initializes a zone with the given origin and ensures it ends with a dot."""
|
||||||
|
@ -223,30 +222,30 @@ class Zone:
|
||||||
else:
|
else:
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def new_A(self, name: str = '@', ttl: int = 3600, data: str = '0.0.0.0'):
|
def new_A(self, name: str = '@', ttl: int = 3600, host: str = '0.0.0.0'):
|
||||||
"""Creates and adds a new A record to the zone."""
|
"""Creates and adds a new A record to the zone."""
|
||||||
name = self.__mkfqdn(name)
|
name = self.__mkfqdn(name)
|
||||||
self.add(A(name=name, ttl=ttl, data=data))
|
self.add(A(name=name, ttl=ttl, host=host))
|
||||||
|
|
||||||
def new_AAAA(self, name: str = '@', ttl: int = 3600, data: str = '0.0.0.0'):
|
def new_AAAA(self, name: str = '@', ttl: int = 3600, host: str = '0.0.0.0'):
|
||||||
"""Creates and adds a new AAAA record to the zone."""
|
"""Creates and adds a new AAAA record to the zone."""
|
||||||
name = self.__mkfqdn(name)
|
name = self.__mkfqdn(name)
|
||||||
self.add(AAAA(name=name, ttl=ttl, data=data))
|
self.add(AAAA(name=name, ttl=ttl, host=host))
|
||||||
|
|
||||||
def new_CNAME(self, name: str = '@', ttl: int = 3600, data: str = 'example.com'):
|
def new_CNAME(self, name: str = '@', ttl: int = 3600, host: str = 'example.com'):
|
||||||
"""Creates and adds a new CNAME record to the zone."""
|
"""Creates and adds a new CNAME record to the zone."""
|
||||||
name = self.__mkfqdn(name)
|
name = self.__mkfqdn(name)
|
||||||
self.add(CNAME(name=name, ttl=ttl, target=data))
|
self.add(CNAME(name=name, ttl=ttl, host=host))
|
||||||
|
|
||||||
def new_MX(self, name: str = '@', ttl: int = 3600, priority: int = 10, host: str = 'example.com'):
|
def new_MX(self, name: str = '@', ttl: int = 3600, priority: int = 10, host: str = 'example.com'):
|
||||||
"""Creates and adds a new MX record to the zone."""
|
"""Creates and adds a new MX record to the zone."""
|
||||||
name = self.__mkfqdn(name)
|
name = self.__mkfqdn(name)
|
||||||
self.add(MX(name=name, ttl=ttl, priority=priority, host=host))
|
self.add(MX(name=name, ttl=ttl, priority=priority, host=host))
|
||||||
|
|
||||||
def new_NS(self, name: str = '@', ttl: int = 3600, target: str = 'example.com'):
|
def new_NS(self, name: str = '@', ttl: int = 3600, host: str = 'example.com'):
|
||||||
"""Creates and adds a new NS record to the zone."""
|
"""Creates and adds a new NS record to the zone."""
|
||||||
name = self.__mkfqdn(name)
|
name = self.__mkfqdn(name)
|
||||||
self.add(NS(name=name, ttl=ttl, target=target))
|
self.add(NS(name=name, ttl=ttl, host=host))
|
||||||
|
|
||||||
def new_PTR(self, name: str = '@', ttl: int = 3600, host: str = 'example.com'):
|
def new_PTR(self, name: str = '@', ttl: int = 3600, host: str = 'example.com'):
|
||||||
"""Creates and adds a new PTR record to the zone."""
|
"""Creates and adds a new PTR record to the zone."""
|
||||||
|
@ -261,11 +260,11 @@ class Zone:
|
||||||
self.add(SOA(mname=mname, rname=rname, serial=serial, refresh=refresh, retry=retry, expire=expire, ttl=ttl))
|
self.add(SOA(mname=mname, rname=rname, serial=serial, refresh=refresh, retry=retry, expire=expire, ttl=ttl))
|
||||||
|
|
||||||
def new_SRV(self, name: str = '@', ttl: int = 3600, service: str = 'service', protocol: str = 'proto',
|
def new_SRV(self, name: str = '@', ttl: int = 3600, service: str = 'service', protocol: str = 'proto',
|
||||||
priority: int = 10, weight: int = 10, target: str = 'example.com'):
|
priority: int = 10, weight: int = 10, host: str = 'example.com'):
|
||||||
"""Creates and adds a new SRV record to the zone."""
|
"""Creates and adds a new SRV record to the zone."""
|
||||||
name = self.__mkfqdn(name)
|
name = self.__mkfqdn(name)
|
||||||
self.add(SRV(name=name, ttl=ttl, service=service, protocol=protocol,
|
self.add(SRV(name=name, ttl=ttl, service=service, protocol=protocol,
|
||||||
priority=priority, weight=weight, target=target))
|
priority=priority, weight=weight, host=host))
|
||||||
|
|
||||||
def new_record(self, name: str = '@', ttl: int = 3600, rtype: str = 'A', data: str = '0.0.0.0'):
|
def new_record(self, name: str = '@', ttl: int = 3600, rtype: str = 'A', data: str = '0.0.0.0'):
|
||||||
"""Creates and adds a generic DNS record to the zone."""
|
"""Creates and adds a generic DNS record to the zone."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue