-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support for IONOS (WIP) * Added link to IONOS API documentation to README * Updated provider doc * IONOS: implemented create, update, delete * IONOS: made integration tests pass * IONOS: added integration tests * IONOS: added cassette * IONOS: added to CODEOWNERS * Default an environment variable --------- Co-authored-by: Adrien Ferrand <ferrand.ad@gmail.com>
- Loading branch information
1 parent
f49f85d
commit bd436d9
Showing
33 changed files
with
5,930 additions
and
18 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
arvancloud | ||
* ``auth_token`` Specify api key for authentication | ||
* ``auth_token`` Specify key for authentication (api key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ionos | ||
* ``api_key`` Ionos api key: public prefix + period + key proper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import requests | ||
|
||
from lexicon.interfaces import Provider as BaseProvider | ||
|
||
|
||
_ZONES_API = 'https://api.hosting.ionos.com/dns/v1/zones' | ||
|
||
|
||
class Provider(BaseProvider): | ||
|
||
@staticmethod | ||
def get_nameservers(): | ||
return ['ui-dns.com', 'ui-dns.org', 'ui-dns.de', 'ui-dns.biz'] | ||
|
||
@staticmethod | ||
def configure_parser(parser): | ||
parser.add_argument( | ||
'--api-key', | ||
required=True, | ||
help='IONOS api key: public prefix + period + key proper', | ||
) | ||
|
||
def authenticate(self): | ||
zones = self._get(_ZONES_API) | ||
for zone in zones: | ||
if zone['name'] == self.domain: | ||
self.domain_id = zone['id'] | ||
return | ||
raise Exception('domain not found: ' + self.domain) | ||
|
||
def create_record(self, rtype, name, content): | ||
self._post( | ||
_ZONES_API + '/' + self.domain_id + '/records', | ||
data=[{ | ||
'name': self._full_name(name), | ||
'type': rtype, | ||
'content': content, | ||
'ttl': self._get_lexicon_option('ttl'), | ||
'prio': 0, | ||
'disabled': False, | ||
}], | ||
) | ||
return True | ||
|
||
def list_records(self, rtype=None, name=None, content=None): | ||
query_params = {} | ||
if rtype: | ||
query_params['recordType'] = rtype | ||
if name: | ||
query_params['recordName'] = self._full_name(name) | ||
data = self._get(_ZONES_API + '/' + self.domain_id, query_params) | ||
records = data['records'] | ||
records = [{ | ||
'type': r['type'], | ||
'name': r['name'], | ||
'ttl': r['ttl'], | ||
'content': r['content'], | ||
'id': r['id'], | ||
} for r in records] | ||
for record in records: | ||
self._clean_TXT_record(record) | ||
if content: | ||
records = [r for r in records if r['content'] == content] | ||
return records | ||
|
||
def update_record(self, identifier, rtype, name, content): | ||
self.delete_record(identifier, rtype, name, None) | ||
return self.create_record(rtype, name, content) | ||
|
||
def delete_record(self, identifier=None, rtype=None, name=None, content=None): | ||
if identifier: | ||
identifiers = [identifier] | ||
else: | ||
identifiers = [ | ||
r['id'] | ||
for r in self.list_records(rtype, name, content) | ||
] | ||
for identifier in identifiers: | ||
self._delete( | ||
_ZONES_API + '/' + self.domain_id + '/records/' + identifier | ||
) | ||
return True | ||
|
||
def _request(self, action='GET', url='/', data=None, query_params=None): | ||
response = requests.request( | ||
action, | ||
url, | ||
params=query_params, | ||
json=data, | ||
headers={ | ||
'accept': 'application/json', | ||
'x-api-key': self._get_provider_option('api_key'), | ||
}, | ||
) | ||
response.raise_for_status() | ||
try: | ||
return response.json() | ||
except requests.exceptions.JSONDecodeError: | ||
return True |
60 changes: 60 additions & 0 deletions
60
tests/fixtures/cassettes/ionos/IntegrationTests/test_provider_authenticate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.32.3 | ||
accept: | ||
- application/json | ||
method: GET | ||
uri: https://api.hosting.ionos.com/dns/v1/zones | ||
response: | ||
body: | ||
string: '[{"name": "example.com", "id": "4c9feb47-2a4d-11ec-bda4-0a5864441f49", | ||
"type": "NATIVE"}]' | ||
headers: | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '582' | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Thu, 28 Nov 2024 13:45:42 GMT | ||
Keep-Alive: | ||
- timeout=15 | ||
cache-control: | ||
- no-cache, no-store, max-age=0, must-revalidate | ||
expires: | ||
- '0' | ||
pragma: | ||
- no-cache | ||
referrer-policy: | ||
- no-referrer | ||
vary: | ||
- Origin | ||
- Access-Control-Request-Method | ||
- Access-Control-Request-Headers | ||
- Origin | ||
via: | ||
- kong/3.0.0 | ||
x-content-type-options: | ||
- nosniff | ||
x-frame-options: | ||
- DENY | ||
x-kong-proxy-latency: | ||
- '1' | ||
x-kong-upstream-latency: | ||
- '5' | ||
x-xss-protection: | ||
- '0' | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
60 changes: 60 additions & 0 deletions
60
.../ionos/IntegrationTests/test_provider_authenticate_with_unmanaged_domain_should_fail.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
interactions: | ||
- request: | ||
body: null | ||
headers: | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
User-Agent: | ||
- python-requests/2.32.3 | ||
accept: | ||
- application/json | ||
method: GET | ||
uri: https://api.hosting.ionos.com/dns/v1/zones | ||
response: | ||
body: | ||
string: '[{"name": "example.com", "id": "4c9feb47-2a4d-11ec-bda4-0a5864441f49", | ||
"type": "NATIVE"}]' | ||
headers: | ||
Access-Control-Allow-Origin: | ||
- '*' | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '582' | ||
Content-Type: | ||
- application/json | ||
Date: | ||
- Thu, 28 Nov 2024 13:45:42 GMT | ||
Keep-Alive: | ||
- timeout=15 | ||
cache-control: | ||
- no-cache, no-store, max-age=0, must-revalidate | ||
expires: | ||
- '0' | ||
pragma: | ||
- no-cache | ||
referrer-policy: | ||
- no-referrer | ||
vary: | ||
- Origin | ||
- Access-Control-Request-Method | ||
- Access-Control-Request-Headers | ||
- Origin | ||
via: | ||
- kong/3.0.0 | ||
x-content-type-options: | ||
- nosniff | ||
x-frame-options: | ||
- DENY | ||
x-kong-proxy-latency: | ||
- '0' | ||
x-kong-upstream-latency: | ||
- '5' | ||
x-xss-protection: | ||
- '0' | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
Oops, something went wrong.