mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 10:46:06 +02:00
split things up
This commit is contained in:
parent
366ecb97d9
commit
bd64a04a91
2 changed files with 94 additions and 40 deletions
|
@ -308,7 +308,52 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
To update the expiration date, use renew_domain method."""
|
||||
raise NotImplementedError()
|
||||
|
||||
def create_dns_record(self, dns_record_dict):
|
||||
def create_prototype_account(self, base_url, headers, tenant_id):
|
||||
account_response = requests.post(
|
||||
f"{base_url}/accounts",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": f"account-{self.name}",
|
||||
"type": "enterprise",
|
||||
"unit": {"id": tenant_id}
|
||||
}
|
||||
)
|
||||
account_response.raise_for_status()
|
||||
account_response_json = account_response.json()
|
||||
account_id = account_response_json["result"]["id"]
|
||||
logger.info(f"Created account: {account_response_json}")
|
||||
return account_id
|
||||
|
||||
def create_prototype_zone(self, base_url, headers, account_id):
|
||||
zone_response = requests.post(
|
||||
f"{base_url}/zones",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": self.name,
|
||||
"account": {"id": account_id},
|
||||
"type": "full"
|
||||
}
|
||||
)
|
||||
zone_response.raise_for_status()
|
||||
zone_response_json = zone_response.json()
|
||||
zone_id = zone_response_json["result"]["id"]
|
||||
logger.info(f"Created zone: {zone_response_json}")
|
||||
return zone_id
|
||||
|
||||
def create_prototype_subscription(self, base_url, headers, zone_id):
|
||||
subscription_response = requests.post(
|
||||
f"{base_url}/zones/{zone_id}/subscription",
|
||||
headers=headers,
|
||||
json={
|
||||
"rate_plan": {"id": "PARTNERS_ENT"},
|
||||
"frequency": "annual"
|
||||
}
|
||||
)
|
||||
subscription_response.raise_for_status()
|
||||
subscription_response_json = subscription_response.json()
|
||||
logger.info(f"Created subscription: {subscription_response_json}")
|
||||
|
||||
def create_prototype_dns_record(self, dns_record_dict):
|
||||
print(f"what is the key? {settings.SECRET_REGISTRY_TENANT_KEY}")
|
||||
# Cloudflare API endpoints
|
||||
base_url = "https://api.cloudflare.com/client/v4"
|
||||
|
@ -329,50 +374,15 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
# 1. Get tenant details
|
||||
# Note: we can grab this more generally but lets be specific to keep things safe.
|
||||
tenant_id = settings.SECRET_REGISTRY_TENANT_ID
|
||||
account_name = f"account-{self.name}"
|
||||
|
||||
# 2. Create account under tenant
|
||||
account_response = requests.post(
|
||||
f"{base_url}/accounts",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": account_name,
|
||||
"type": "enterprise",
|
||||
"unit": {"id": tenant_id}
|
||||
}
|
||||
)
|
||||
account_response.raise_for_status()
|
||||
account_response_json = account_response.json()
|
||||
account_id = account_response_json["result"]["id"]
|
||||
logger.info(f"Created account: {account_response_json}")
|
||||
account_id = self.create_prototype_account(base_url, headers, tenant_id)
|
||||
|
||||
# 3. Create zone under account
|
||||
zone_response = requests.post(
|
||||
f"{base_url}/zones",
|
||||
headers=headers,
|
||||
json={
|
||||
"name": self.name,
|
||||
"account": {"id": account_id},
|
||||
"type": "full"
|
||||
}
|
||||
)
|
||||
zone_response.raise_for_status()
|
||||
zone_response_json = zone_response.json()
|
||||
zone_id = zone_response_json["result"]["id"]
|
||||
logger.info(f"Created zone: {zone_id}")
|
||||
zone_id = self.create_prototype_zone(base_url, headers, account_id)
|
||||
|
||||
# 4. Add zone subscription
|
||||
subscription_response = requests.post(
|
||||
f"{base_url}/zones/{zone_id}/subscription",
|
||||
headers=headers,
|
||||
json={
|
||||
"rate_plan": {"id": "PARTNERS_ENT"},
|
||||
"frequency": "annual"
|
||||
}
|
||||
)
|
||||
subscription_response.raise_for_status()
|
||||
subscription_response_json = subscription_response.json()
|
||||
logger.info(f"Created subscription: {subscription_response_json}")
|
||||
self.create_prototype_subscription(base_url, headers, zone_id)
|
||||
|
||||
# 5. Create DNS record
|
||||
dns_response = requests.post(
|
||||
|
@ -391,7 +401,6 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
"dns_record_id": dns_response_json["result"]["id"]
|
||||
}
|
||||
|
||||
|
||||
def renew_domain(self, length: int = 1, unit: epp.Unit = epp.Unit.YEAR):
|
||||
"""
|
||||
Renew the domain to a length and unit of time relative to the current
|
||||
|
|
|
@ -64,6 +64,7 @@ from epplibwrapper import (
|
|||
|
||||
from ..utility.email import send_templated_email, EmailSendingError
|
||||
from .utility import DomainPermissionView, DomainInvitationPermissionCancelView
|
||||
from django import forms
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -462,6 +463,50 @@ class DomainDNSView(DomainBaseView):
|
|||
return context
|
||||
|
||||
|
||||
class PrototypeDomainDNSRecordForm(forms.Form):
|
||||
"""Form for adding DNS records in prototype."""
|
||||
|
||||
record_type = forms.ChoiceField(
|
||||
label="Record Type",
|
||||
choices=[
|
||||
("A", "A"),
|
||||
("AAAA", "AAAA"),
|
||||
("CNAME", "CNAME"),
|
||||
("TXT", "TXT")
|
||||
],
|
||||
required=True
|
||||
)
|
||||
|
||||
name = forms.CharField(
|
||||
label="Name",
|
||||
required=True,
|
||||
help_text="The DNS record name (e.g., www)"
|
||||
)
|
||||
|
||||
content = forms.GenericIPAddressField(
|
||||
label="IPv4 Address",
|
||||
required=True,
|
||||
protocol="IPv4",
|
||||
help_text="The IPv4 address this record points to"
|
||||
)
|
||||
|
||||
ttl = forms.ChoiceField(
|
||||
label="TTL",
|
||||
choices=[
|
||||
(1, "Automatic"),
|
||||
(60, "1 minute"),
|
||||
(300, "5 minutes"),
|
||||
(1800, "30 minutes"),
|
||||
(3600, "1 hour"),
|
||||
(7200, "2 hours"),
|
||||
(18000, "5 hours"),
|
||||
(43200, "12 hours"),
|
||||
(86400, "1 day")
|
||||
],
|
||||
initial=1,
|
||||
help_text="Time to Live - how long DNS resolvers should cache this record"
|
||||
)
|
||||
|
||||
class DomainNameserversView(DomainFormBaseView):
|
||||
"""Domain nameserver editing view."""
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue