Skip to content

Commit

Permalink
feat: add package configuration (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegofd authored Dec 24, 2023
1 parent 930b00e commit 3e6e713
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
.venv
__pycache__
__pycache__
dist
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Diego Fernandez Duran

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Full documentation [here](https://github.com/cloudflare/python-cloudflare?tab=re

### How to run

#### From git

```
$ pwd
/home/user
Expand All @@ -24,19 +26,36 @@ $ cd dnsupdater
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
$ cd src
# For AWS
$ python3 -m dnsupdater.dnsupdater --name RECORD_NAME route53 --hosted-zone-id HOSTED_ZONE_ID
# For Cloudflare
$ python3 -m dnsupdater.dnsupdater --name RECORD_NAME cloudflare --domain DOMAIN
```

#### From package

Using virtualenv is recommended to not polute your system.

```
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install dnsupdater
# For AWS
$ ./dnsupdater.py --name RECORD_NAME route53 --hosted-zone-id HOSTED_ZONE_ID
$ dnsupdater --name RECORD_NAME route53 --hosted-zone-id HOSTED_ZONE_ID
# For Cloudflare
$ ./dnsupdater.py --name RECORD_NAME cloudflare --domain DOMAIN
$ dnsupdater --name RECORD_NAME cloudflare --domain DOMAIN
```

### How to schedule it with cron

Follow the steps above to install and configure a cron job to run every hour:
```
0 * * * * user cd /home/user/dnsupdater && .venv/bin/python3 dnsupdater.py --name sub.example.com route53 --hosted-zone-id ZXXXXXXXXXXX
0 * * * * user cd /home/user/dnsupdater && .venv/bin/python3 -m dnsupdater.dnsupdater --name sub.example.com route53 --hosted-zone-id ZXXXXXXXXXXX
```

### Cost
Expand All @@ -48,3 +67,7 @@ Estimated cost is $0.5 per hosted zone per month plus additional cost per DNS re
#### Cloudflare

Free.

### Development

* Packaging documentation: https://packaging.python.org/en/latest/tutorials/packaging-projects/
31 changes: 31 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[build-system]
# https://github.com/pypa/pip/issues/12100#issuecomment-1606060725
requires = [
"hatchling",
"boto3",
"requests",
"cloudflare"
]
build-backend = "hatchling.build"

[project]
name = "dnsupdater"
version = "0.0.1"
authors = [
{ name="Diego Fernandez Duran", email="diego@goedi.net" },
]
description = "Update an Amazon Route53 or Cloudflare record with your current public IP address."
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
Homepage = "https://github.com/diegofd/dnsupdater"
Issues = "https://github.com/diegofd/dnsupdater/issues"

[project.scripts]
dnsupdater = "dnsupdater.dnsupdater:main"
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Needed until https://github.com/pypa/pip/issues/11440 is done
# and deps can be extracted from project.toml
#
# Until then, keep it sync.
boto3
requests
cloudflare
Empty file added src/dnsupdater/__init__.py
Empty file.
File renamed without changes.
6 changes: 3 additions & 3 deletions dnsupdater.py → src/dnsupdater/dnsupdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import argparse
import logging

import ip
import route53 as r53
import cloudflare as cf
from . import ip
from . import route53 as r53
from . import cloudflare as cf


def route53_command(args):
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 3e6e713

Please sign in to comment.