Giter Club home page Giter Club logo

sync-gandi-dns's Introduction

sync-gandi-dns

Test & QA GitHub release (latest by date)

This is a simple Python package which allows the IP address records for domains registered with Gandi to be kept up to date with the dynamic public values assigned to you by your ISP.

It can be used to update the resource record for either IPV4 (A) or IPV6 (AAAA) or both, for a single or multiple domains.

How it works

It uses the Gandi LiveDNS API to query the current settings and make changes. The API is marked as (beta), but I've not experienced any issues with it. To access the API you need to obtain a key via the Security tab under "User Settings", "Manage the user account and security settings".

It also needs to find out what the latest IP address is before deciding if an update is required. To do this it uses the ipify API which provides simple endpoints for finding your public IPV4 and IPV6 address.

Installing

Checkout the source code from here:

$ git clone https://github.com/RatJuggler/sync-gandi-dns.git
$ cd sync-gandi-dns

Then install/update as a Python package:

$ sudo pip3 install -U .

Running

$ syncgandidns --help
Usage: syncgandidns [OPTIONS]

  Sync a dynamic IP address (V4 & V6) with a Gandi DNS domain entry.

  The external IP address is determined automatically by default.

  Domains can be set using the GANDI_DOMAINS environment variable. For
  multiple domains separate with a ';'.

  The Gandi API key can be set using the GANDI_APIKEY environment variable.

Options:
  --version                       Show the version and exit.
  -d, --domain DOMAIN             A domain to update the DNS for. Repeat the
                                  option to update multiple domains.
                                  [required]
  -a, --apikey TEXT               Your Gandi API key.  [required]
  -ipv4, --ipv4-address IPV4_ADDRESS
                                  Override the IPV4 address to update the
                                  domain DNS with.
  -no-ipv4, --no-ipv4-update      Don't update the IPV4 address, will override
                                  '-ipv4'.
  -ipv6, --ipv6-address IPV6_ADDRESS
                                  Override the IPV6 address to update the
                                  domain DNS with.
  -no-ipv6, --no-ipv6-update      Don't update the IPV6 address, will override
                                  '-ipv6'.
  -l, --log-level [DEBUG|VERBOSE|INFO|WARNING]
                                  Show additional logging information.
                                  [default: INFO]
  -m, --metrics URL               Push metrics to this URL.
  -t, --test                      Test the Gandi API key and exit.  [default:
                                  False]
  --help                          Show this message and exit.

There are a number of ways of configuring the domain(s) to update, and the API key. You can set them directly with options on the command line or provide them pre-set in environment variables, but probably the easiest way to do this is to create a sync-gandi-dns.env file from the supplied template, then edit the file and set them there.

$ cp sync-gandi-dns.env.template sync-gandi-dns.env

The edited file should then look something like this (not real data):

GANDI_APIKEY="12345abcde67890fghij12kl"
GANDI_DOMAINS="mydomain.com;otherdomain.co.uk;anyothers.io"

It will always start by looking for this file in the current directory and then search upwards. Test that your configuration is working by using:

$ syncgandidns --test

Docker

Note: IPV6 connectivity is not enabled by default for docker containers, so the ipify IPV6 lookup will always fail, and the IPV6 address cannot then be kept up to date. I am currently researching how best to proceed with configuring this.

Docker build and compose files are available which create a standalone image to run the sync on an hourly schedule using the push metrics option to record its activity.

Edit the docker/crontab.txt file to set your preferred timings and change the options used.

Create the image with:

$ docker build -f docker/Dockerfile -t sync-gandi-dns:local .

Environment variables should be used to set the domains to update, and the Gandi API key. It is important that the API key is not included in the image in case it is pushed to a public repository (and it's also just best practice). There are a number of ways to do this but probably the easiest is to create a sync-gandi-dns.env file as described above and then run the image with the --env-file option.

$ docker run sync-gandi-dns:local -d --env-file sync-gandi-dns.env

Or just use the compose file to do everything:

$ docker-compose up -d

Environment variables can also be used to configure image tagging (see the file), and a simple health check, using the --test option, is available if running under orchestration.

Development

For development one of the tests requires access to a key, and an accessible domain to show a working API call. These need to be set as the environment variables GANDI_TEST_APIKEY and GANDI_TEST_DOMAINS. No tests attempt to make any changes.

sync-gandi-dns's People

Contributors

dependabot[bot] avatar ratjuggler avatar

Stargazers

 avatar

Watchers

 avatar  avatar

sync-gandi-dns's Issues

Improve request timeout handling

Catch timeouts and handle gracefully so we don't get this in the log file.

Traceback (most recent call last):
File "/usr/local/bin/syncgandidns", line 10, in
sys.exit(syncgandidns())
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/syncgandidns/main.py", line 73, in syncgandidns
do_sync(domains, apikey, no_ipv4, ipv4, no_ipv6, ipv6)
File "/usr/local/lib/python3.7/dist-packages/syncgandidns/sync_ip_address.py", line 51, in do_sync
_sync_ip(domain, 'IPV6', update_ipv6, gandi_api.get_ipv6_address, gandi_api.update_ipv6_address)
File "/usr/local/lib/python3.7/dist-packages/syncgandidns/sync_ip_address.py", line 11, in _sync_ip
current_ip = get_ip(domain)
File "/usr/local/lib/python3.7/dist-packages/syncgandidns/gandi_api.py", line 55, in get_ipv6_address
return self._get_domain_record_resource_value(domain, 'AAAA')
File "/usr/local/lib/python3.7/dist-packages/syncgandidns/gandi_api.py", line 30, in _get_domain_record_resource_value
timeout=4)
File "/usr/local/lib/python3.7/dist-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/dist-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.gandi.net', port=443): Read timed out. (read timeout=4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.