-
-
Save reubeningber/0373ba72b73839577698692786137c45 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #! /usr/bin/env python3 | |
| from ns1 import NS1 | |
| from pprint import pprint | |
| import yaml | |
| import os | |
| def validate_record(api, zone, records): | |
| print("records") | |
| # pprint(records) | |
| print(records['short_answers']) | |
| zone_api = api.loadZone(zone) | |
| # print("zone API data") | |
| # pprint(zone_api.data) | |
| def main(): | |
| path = 'ns1configs/' | |
| for config_file in os.listdir(path): | |
| with open(path + config_file, 'r') as yaml_file: | |
| try: | |
| # pprint(yaml.safe_load(yaml_file)) | |
| yaml_data = yaml.safe_load(yaml_file) | |
| except yaml.YAMLError: | |
| print(yaml.YAMLError) | |
| # pprint(yaml_data) | |
| api = NS1(apiKey=os.getenv('NS1_TOKEN')) | |
| zone_records = yaml_data['records'] | |
| for record in zone_records: | |
| validate_record(api, yaml_data['zone'], record) | |
| zone = api.loadZone('testbizone.com') | |
| record = zone.loadRecord('apple.testbizone.com', 'A') | |
| pprint(record.data) | |
| record.update(answers=['3.3.3.3']) # Update answers in NS1 | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment