def update_credential_file(): with open('configure.json') as file: json_text = json.load(file) if json_text.get('afr_source_dir', None): afr_source_dir = os.path.expanduser(json_text['afr_source_dir']) else: afr_source_dir = None thing_name = json_text.get('thing_name', "") mac_addr = json_text.get('mac_addr', "") wifi_ssid = json_text.get('wifi_ssid', "") wifi_passwd = json_text.get('wifi_password', "") wifi_security = json_text.get('wifi_security', "") # Read cert_pem from file cert_pem_filename = thing_name + '_cert.pem' try: cert_pem_file = open(cert_pem_filename, 'r') except IOError: print("%s file not found. Run prerequisite step" % cert_pem_filename) sys.exit(1) else: cert_pem = cert_pem_file.read() # Read private_key_pem from file private_key_pem_filename = thing_name + '_private_key.pem' try: private_key_pem_file = open(private_key_pem_filename, 'r') except IOError: print("%s file not found. Run prerequisite step" % private_key_pem_filename) sys.exit(1) else: private_key_pem = private_key_pem_file.read() # Modify 'aws_clientcredential.h' file misc.update_client_credentials(afr_source_dir, thing_name, wifi_ssid, wifi_passwd, wifi_security) # Modify 'aws_clientcredential_keys.h' file misc.update_client_credential_keys(afr_source_dir, cert_pem, private_key_pem) # Modify 'thing_config.py' file misc.update_thing_config(thing_name, mac_addr)
def update_credential_file(): with open('configure.json') as file: json_text = json.load(file) afr_source_dir = os.path.expanduser(json_text['afr_source_dir']) thing_name = json_text['thing_name'] wifi_ssid = json_text['wifi_ssid'] wifi_passwd = json_text['wifi_password'] wifi_security = json_text['wifi_security'] # Read cert_pem from file cert_pem_filename = thing_name + '_cert_pem_file' try: cert_pem_file = open(cert_pem_filename, 'r') except IOError: print("%s file not found. Run prerequisite step" % cert_pem_filename) sys.exit(1) else: cert_pem = cert_pem_file.read() # Read private_key_pem from file private_key_pem_filename = thing_name + '_private_key_pem_file' try: private_key_pem_file = open(private_key_pem_filename, 'r') except IOError: print("%s file not found. Run prerequisite step" % private_key_pem_filename) sys.exit(1) else: private_key_pem = private_key_pem_file.read() # Modify 'aws_clientcredential.h' file misc.update_client_credentials(afr_source_dir, thing_name, wifi_ssid, wifi_passwd, wifi_security) # Modify 'aws_clientcredential_keys.h' file misc.update_client_credential_keys(afr_source_dir, cert_pem, private_key_pem) print("Completed update operation!")