#!/usr/bin/env python3
import argparse

from gcloud_dynamic_dns.dns import update_dns
import json
import logging

parser = argparse.ArgumentParser()
parser.add_argument("zone_name", help="the name of the GCP zone to manage")
parser.add_argument("dns_name", help="the DNS name to update")
parser.add_argument("--ttl", help="TTL of the update record", default=60)
parser.add_argument("--project_id", default=None, help="name of the GCP project")
parser.add_argument("--credentials_file", default=None, help="file with credentials of service account for GCP project")
parser.add_argument("--force_update", action="store_true", default=False, help="force the DNS update even if the record hasn't changed")

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    args = parser.parse_args()

    credentials = None
    if args.credentials_file is not None:
        with open(args.credentials_file) as f:
            credentials = json.load(f)

    update_dns(logging.getLogger(), args.zone_name, args.dns_name, args.ttl, args.force_update, args.project_id, credentials)
