Compare commits

...

9 Commits

Author SHA1 Message Date
Pierre-Olivier Mercier
63fe8c9b80 Prepare 0.3.0
All checks were successful
continuous-integration/drone/tag Build is passing
2023-12-10 12:42:09 +01:00
Pierre-Olivier Mercier
d14552dd78 apply_changes handles commit message 2023-12-10 12:41:45 +01:00
Pierre-Olivier Mercier
c32633ba09 Handle domains with no history on domain_list 2023-12-10 11:58:07 +01:00
Pierre-Olivier Mercier
af58391164 Prepare 0.2.0
All checks were successful
continuous-integration/drone/tag Build is passing
2023-12-10 11:41:34 +01:00
Pierre-Olivier Mercier
3110840017 Fix use of API token, without login 2023-12-10 11:40:44 +01:00
Pierre-Olivier Mercier
a586960ae6 Prepare 0.1.1
Some checks failed
continuous-integration/drone/tag Build is failing
2023-12-10 11:21:51 +01:00
Pierre-Olivier Mercier
5050c3fed0 Comply with setuptools 69 2023-12-10 11:21:51 +01:00
Pierre-Olivier Mercier
3fb64bb6ee Prepare 0.1.0
Some checks failed
continuous-integration/drone/tag Build is failing
2023-05-02 20:38:47 +02:00
Pierre-Olivier Mercier
a62e5f1a59 Introducing UncompleteZoneMeta to solve inconsistent API on zone_history
Closes: https://github.com/happyDomain/python-sdk/issues/1
2023-05-02 20:36:53 +02:00
5 changed files with 68 additions and 8 deletions

View File

@ -20,6 +20,9 @@ class HappyDomain:
self.baseurl = scheme + "://" + host + ":" + str(port) + baseurl
self.token = token
if self.token is not None:
self.session.headers.update({'Authorization': 'Bearer ' + self.token})
def login(self, username, password):
r = self.session.post(
self.baseurl + "/api/auth",
@ -51,7 +54,7 @@ class HappyDomain:
if val is not None:
for au in val:
ret.append(Domain(self, **au))
ret.append(Domain(self, zone_history_are_ids=True, **au))
return ret

View File

@ -2,11 +2,11 @@ import json
from urllib.parse import quote
from .error import HappyError
from .zone import ZoneMeta, Zone
from .zone import UncompleteZoneMeta, ZoneMeta, Zone
class Domain:
def __init__(self, _session, id, id_owner, id_provider, domain, zone_history, group=""):
def __init__(self, _session, id, id_owner, id_provider, domain, zone_history, zone_history_are_ids=False, group=""):
self._session = _session
self.id = id
@ -14,7 +14,10 @@ class Domain:
self.id_provider = id_provider
self.domain = domain
self.group = group
self.zone_history = zone_history if zone_history is not None else []
if zone_history_are_ids:
self.zone_history = [UncompleteZoneMeta(self, zid) for zid in zone_history] if zone_history is not None else []
else:
self.zone_history = zone_history if zone_history is not None else []
def _dumps(self):
return json.dumps({

View File

@ -31,6 +31,54 @@ class ZoneMeta:
})
class UncompleteZoneMeta(ZoneMeta):
def __init__(self, _domain, id):
self._complete = None
self._domain = _domain
self.id = id
def resolve(self):
if self._complete is None:
self._complete = self._domain.get_zone(self.id)
@property
def id_author(self):
self.resolve()
return self._complete.id_author
@property
def default_ttl(self):
self.resolve()
return self._complete.default_ttl
@property
def last_modified(self):
self.resolve()
return self._complete.last_modified
@property
def last_modified(self):
self.resolve()
return self._complete.last_modified
@property
def commit_message(self):
self.resolve()
return self._complete.commit_message
@property
def commit_date(self):
self.resolve()
return self._complete.commit_date
@property
def published(self):
self.resolve()
return self._complete.published
class Zone(ZoneMeta):
def __init__(self, _session, _domainid, **kwargs):
@ -96,7 +144,7 @@ class Zone(ZoneMeta):
return r.json()
def apply_changes(self):
def apply_changes(self, message=""):
rdiff = self._session.session.post(
self._session.baseurl + "/api/domains/" + quote(self._domainid) + "/diff_zones/%40/" + quote(self.id),
)
@ -106,7 +154,10 @@ class Zone(ZoneMeta):
r = self._session.session.post(
self._session.baseurl + "/api/domains/" + quote(self._domainid) + "/zone/" + quote(self.id) + "/apply_changes",
data=rdiff.text
data=json.dumps({
"wantedCorrections": json.loads(rdiff.text),
"commitMessage": message,
})
)
if r.status_code > 300:

View File

@ -1,12 +1,14 @@
[project]
name = "happydomain"
version = "0.0.7"
version = "0.3.0"
authors = [
{ name="happyDomain's team", email="contact+pypi@happydomain.org" },
]
description = "Finally a simple interface for domain names."
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.9"
keywords = ['dns ns happydomain domain domainname']
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: CEA CNRS Inria Logiciel Libre License, version 2.1 (CeCILL-2.1)",
@ -18,6 +20,7 @@ classifiers = [
"Intended Audience :: Information Technology",
"Operating System :: POSIX",
]
dependencies = ['requests']
[project.urls]
"Homepage" = "https://git.happydomain.org/python-sdk"

View File

@ -8,7 +8,7 @@ try:
except ImportError:
from distutils.core import setup
version = "0.0.7"
version = "0.3.0"
setup(
name = "happydomain",