1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00

revamed authentication

This commit is contained in:
Basir Jamil
2019-06-06 14:31:26 -04:00
parent 34b618fbee
commit e1a139d187

View File

@@ -9,6 +9,8 @@ from __future__ import absolute_import, division, print_function, \
from os.path import expanduser from os.path import expanduser
import ConfigParser import ConfigParser
# import os ## command line workaround
import logging import logging
from functools import reduce from functools import reduce
@@ -42,65 +44,57 @@ class AkamaiProvider(BaseProvider):
def _authenticate(self, client_secret, host, access_token, client_token) def _authenticate(self, client_secret, host, access_token, client_token)
## generate edgegrid # ## generate edgegrid
section_name = "dns" # section_name = "dns"
home = expanduser("~") # home = expanduser("~")
index = 0 # index = 0
fields = {} # fields = {}
## process original .edgerc file # ## process original .edgerc file
origConfig = ConfigParser.ConfigParser() # origConfig = ConfigParser.ConfigParser()
filename = "%s/.edgerc" % home # filename = "%s/.edgerc" % home
# If this is a new file, create it # # If this is a new file, create it
if not os.path.isfile(filename): # if not os.path.isfile(filename):
open(filename, 'a+').close() # open(filename, 'a+').close()
origConfig.read(filename) # origConfig.read(filename)
# ## credential type already exists, prompt to overwrite
# if section_name in origConfig.sections():
# print (">>> Replacing section: %s" % section_name)
# sys.stdout.write ("*** OK TO REPLACE section %s? *** [Y|n]:" % section_name)
# real_raw_input = vars(__builtins__).get('raw_input',input)
# choice = real_raw_input().lower()
# if choice == "n":
# print ("Not replacing section.")
# return
# replace_section = True
# else:
# print ("+++ Creating section: %s" % section_name)
# replace_section = False
# ## open the ~/.edgerc file for writing
# Config = ConfigParser.ConfigParser()
# Config.read(filename)
# confile = open(filename, 'w')
if section_name in origConfig.sections(): # ## add the new section
print (">>> Replacing section: %s" % section_name)
sys.stdout.write ("*** OK TO REPLACE section %s? *** [Y|n]:" % section_name)
real_raw_input = vars(__builtins__).get('raw_input',input)
choice = real_raw_input().lower()
if choice == "n":
print ("Not replacing section.")
exit(0)
replace_section = True
else:
print ("+++ Creating section: %s" % section_name)
replace_section = False
#### create credential file, and write credentials to it #### create credential file, and write credentials to it
with open('~/.edgerc', 'a') as credFile:
credFile = open('tempCred.txt', 'w') credFile.write('[dns]\n')
credFile.write('client_secret = ') credFile.write('client_secret = ' + str(client_secret) + '\n')
credFile.write(str(client_secret)) credFile.write('host = ' + str(host) + '\n')
credFile.write('\n\n') credFile.write('access_token = ' + str(access_token) + '\n')
credFile.write('client_token = ' + str(client_token) + '\n')
credFile.write('host = ' + str(host)) credFile.close()
credFile.write('\n\n')
credFile.write('access_token = ' + str(access_token))
credFile.write('\n\n')
credFile.write('client_token = ' + str(client_token))
credFile.write('\n')
credFile.close()
#### generate edgegrid using tool
#### delete temp txt file
def populate(self, zone, target=False, lenient=False): def populate(self, zone, target=False, lenient=False):
pass pass