Created
December 9, 2019 21:58
-
-
Save fernando-mc/91c2ad4b033b7a8906a4f5962aede2c7 to your computer and use it in GitHub Desktop.
AWS Route 53 Contact Info Updater
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
import boto3 | |
from pprint import pprint | |
from bullet import Bullet, Input, styles, VerticalPrompt, Check, YesNo | |
# List Route 53 domains | |
r53domains = boto3.client('route53domains') | |
response = r53domains.list_domains() | |
domain_list = [] | |
for domain in response["Domains"]: | |
domain_list.append(domain["DomainName"]) | |
# Prompt user to pick which domains they want | |
domains = Check( | |
"Which domains would you like to update? (Press space to (de)select a domain)", | |
choices=domain_list, | |
).launch() | |
contact_info = VerticalPrompt( | |
[ | |
Input("First Name: "), | |
Input("Last name: "), | |
Bullet( | |
prompt = "Choose a contact type from the items below: ", | |
choices = ['PERSON', 'COMPANY', 'ASSOCIATION', 'PUBLIC_BODY', 'RESELLER'], | |
**styles.Ocean | |
), | |
Input( | |
"Organization name (Used when contact type is not a person): ", | |
pattern=".*" | |
), | |
Input("Address Line 1: "), | |
Input("Address Line 2: "), | |
Input("City: "), | |
Input("State: "), | |
Input( | |
"Two Digit Country Code (e.g. US, GB, JP): ", | |
pattern="^[A-Z]{2}$"), | |
Input("Zip Code: "), | |
Input( | |
"Phone Number with period after country code (e.g. for United States: +1.5556667788): ", | |
pattern="^\+[0-9]{1,2}\.[0-9]{10}$" | |
), | |
Input("Email: ") | |
], | |
spacing = 1 | |
).launch() | |
details = { | |
'FirstName': contact_info[0][1], | |
'LastName': contact_info[1][1], | |
'ContactType': contact_info[2][1], | |
'AddressLine1': contact_info[4][1], | |
'AddressLine2': contact_info[5][1], | |
'City': contact_info[6][1], | |
'State': contact_info[7][1], | |
'CountryCode': contact_info[8][1], | |
'ZipCode': contact_info[9][1], | |
'PhoneNumber': contact_info[10][1], | |
'Email': contact_info[11][1], | |
} | |
if details['ContactType'] != "PERSON": | |
details["OrganizationName"] = contact_info[3][1] | |
# Show the domains and details and have the user confirm | |
print("Your contact information will be updated to the following: ") | |
pprint(details) | |
print("The domains to be updated are: ") | |
for domain in domains: | |
print(domain) | |
final_confirm = YesNo("Does this look correct? (y/n) ").launch() | |
# If confirmation is yes, then replace the contact info | |
if final_confirm: | |
for domain in domains: | |
result = r53domains.update_domain_contact( | |
DomainName=domain, | |
AdminContact=details, | |
RegistrantContact=details, | |
TechContact=details | |
) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment