forked from morganzero/cloudflare-companion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
978 additions
and
951 deletions.
There are no files selected for viewing
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
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 +1 @@ | ||
__version__ = "0.1.0" | ||
__version__ = '0.1.0' |
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,38 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
import asyncio | ||
import sys | ||
|
||
from pydantic import ValidationError | ||
|
||
import dns_synchub.cli as cli | ||
import dns_synchub.logger as logger | ||
import dns_synchub.settings as settings | ||
|
||
|
||
def main(): | ||
try: | ||
# Load environment variables from the specified env file | ||
cli.parse_args() | ||
|
||
# Load settings | ||
options = settings.Settings() | ||
|
||
# Check for uppercase docker secrets or env variables | ||
assert options.cf_token | ||
assert options.target_domain | ||
assert len(options.domains) > 0 | ||
|
||
except ValidationError as e: | ||
print(f"Unable to load settings: {e}", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
# Set up logging and dump runtime settings | ||
log = logger.report_current_status_and_settings(logger.get_logger(options), options) | ||
try: | ||
asyncio.run(cli.main(log, settings=options)) | ||
except KeyboardInterrupt: | ||
# asyncio.run will cancel any task pending when the main function exits | ||
log.info("Cancel by user.") | ||
log.info("Exiting...") | ||
sys.exit(1) | ||
# src/dns_synchub/__init__.py | ||
|
||
from .__about__ import __version__ as VERSION | ||
from .logger import get_logger, initialize_logger | ||
from .mappers import CloudFlareMapper | ||
from .pollers import DockerPoller, TraefikPoller | ||
from .settings import Settings | ||
|
||
__version__ = VERSION | ||
|
||
__all__ = [ | ||
# logger subpackage | ||
'get_logger', | ||
'initialize_logger', | ||
# settings subpackage | ||
'Settings', | ||
# pollers subpackage | ||
'DockerPoller', | ||
'TraefikPoller', | ||
# mappers subpackage | ||
'CloudFlareMapper', | ||
] | ||
|
||
|
||
def __dir__() -> 'list[str]': | ||
return list(__all__) |
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,16 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import asyncio | ||
from logging import Logger | ||
import pathlib | ||
import re | ||
import sys | ||
|
||
import dns_synchub | ||
from pydantic import ValidationError | ||
|
||
if __name__ == "__main__": | ||
import dns_synchub.cli as cli | ||
import dns_synchub.logger as logger | ||
import dns_synchub.settings as settings | ||
|
||
|
||
def report_state(settings: settings.Settings) -> Logger: | ||
log = logger.initialize_logger(settings=settings) | ||
|
||
settings.dry_run and log.info(f'Dry Run: {settings.dry_run}') # type: ignore | ||
log.debug(f'Default TTL: {settings.default_ttl}') | ||
log.debug(f'Refresh Entries: {settings.refresh_entries}') | ||
|
||
log.debug(f"Traefik Polling Mode: {'On' if settings.enable_traefik_poll else 'Off'}") | ||
if settings.enable_traefik_poll: | ||
if settings.traefik_poll_url and re.match(r'^\w+://[^/?#]+', settings.traefik_poll_url): | ||
log.debug(f'Traefik Poll Url: {settings.traefik_poll_url}') | ||
log.debug(f'Traefik Poll Seconds: {settings.traefik_poll_seconds}') | ||
else: | ||
settings.enable_traefik_poll = False | ||
log.error(f'Traefik polling disabled: Bad url: {settings.traefik_poll_url}') | ||
|
||
log.debug(f"Docker Polling Mode: {'On' if settings.enable_docker_poll else 'Off'}") | ||
log.debug(f'Docker Poll Seconds: {settings.docker_timeout_seconds}') | ||
|
||
for dom in settings.domains: | ||
log.debug(f'Domain Configuration: {dom.name}') | ||
log.debug(f' Target Domain: {dom.target_domain}') | ||
log.debug(f' TTL: {dom.ttl}') | ||
log.debug(f' Record Type: {dom.rc_type}') | ||
log.debug(f' Proxied: {dom.proxied}') | ||
log.debug(f' Excluded Subdomains: {dom.excluded_sub_domains}') | ||
|
||
return log | ||
|
||
|
||
def main() -> int: | ||
try: | ||
# Load environment variables from the specified env file | ||
cli.parse_args() | ||
# Load settings | ||
options = settings.Settings() | ||
# Check for uppercase docker secrets or env variables | ||
assert options.cf_token | ||
assert options.target_domain | ||
assert len(options.domains) > 0 | ||
except ValidationError as e: | ||
print(f'Unable to load settings: {e}', file=sys.stderr) | ||
return 1 | ||
|
||
# Set up logging and dump runtime settings | ||
log = report_state(options) | ||
try: | ||
asyncio.run(cli.main(log, settings=options)) | ||
except KeyboardInterrupt: | ||
# asyncio.run will cancel any task pending when the main function exits | ||
log.info('Cancel by user.') | ||
log.info('Exiting...') | ||
|
||
# Exit grqacefully | ||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
# If the script is run as a module, use the directory name as the script name | ||
script_name = pathlib.Path(sys.argv[0]).stem | ||
if sys.argv[0] == __file__: | ||
script_path = pathlib.Path(sys.argv[0]) | ||
script_name = script_path.parent.name.replace("_", "-") | ||
script_name = script_path.parent.name.replace('_', '-') | ||
# Set the script name to the first argument and invoke the main function | ||
sys.argv[0] = script_name | ||
sys.exit(dns_synchub.main()) | ||
sys.exit(main()) |
Oops, something went wrong.