lowercased variable names, added function to get account details and write basic config ini file

This commit is contained in:
crp3844
2022-09-06 15:46:51 -04:00
parent 247615d3d1
commit f823711817

View File

@@ -7,25 +7,69 @@ import json
import configparser
import getpass
OS_DETECTED = platform.system()
SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
os_detected = platform.system()
script_directory = os.path.dirname(os.path.realpath(__file__))
secrets_ini_file = script_directory + "/secrets.ini"
if OS_DETECTED == 'Windows':
BITWARDEN_CLI_EXECUTABLE = "bw.exe"
elif OS_DETECTED == 'Linux':
BITWARDEN_CLI_EXECUTABLE = "bw"
if os_detected == "Windows":
bitwarden_cli_executable = script_directory + "lib/bw.exe"
elif os_detected == "Linux":
bitwarden_cli_executable = script_directory + "lib/bw"
else:
print("Your OS is not supported. Only Windows and Linux are currently supported.\nDetected OS: {0}".format(OS_DETECTED))
print("Your OS is not supported. Only Windows and Linux are currently supported.\nDetected OS: {0}".format(U))
sys.exit(1)
#parser = configparser.ConfigParser()
#parser.read(SCRIPT_DIRECTORY + '/secrets.ini')
#accounts = parser.sections()
#for account in accounts:
# print("User Account is {0}".format(account))
# INI format, mulitple accounts can be used.
#[Account Email Address]
#ENCRYPTED_API_CLIENT_ID =
#ENCRYPTED_API_SECRET =
#ENCRYPTED_VAULT_PASSWORD =
#encrypted_api_client_id =
#encrypted_api_secret =
#encrypted_vault_password =
def does_file_exist(filepath):
return os.path.exists(filepath)
def ask_for_account_details():
print("Requesting account details to build the ini file.")
account_email_address = input("Please enter Bitwarden account email address: ")
#encrypted_account_email_address = encrypt(client, account_email_address)
account_api_client_id = input("Please enter Bitwarden account API client ID: ")
#encrypted_account_api_client_id = encrypt(client, account_api_client_id)
while True:
account_api_secret = getpass.getpass("Please enter Bitwarden account API secret: ")
account_api_secret2 = getpass.getpass("Please confirm Bitwarden account API secret: ")
if account_api_secret == account_api_secret2:
#encrypted_account_api_secret = encrypt(client, account_api_secret)
break
else:
print("The Bitwarden account API secrets do not match, please try again.")
while True:
account_vault_password = getpass.getpass("Please enter Bitwarden account vault password: ")
account_vault_password2 = getpass.getpass("Please confirm Bitwarden account vault password: ")
if account_vault_password == account_vault_password2:
#encrypted_account_vault_password = encrypt(client, account_vault_password)
break
else:
print("The Bitwarden account vault passwords do not match, please try again.")
array = dict()
array["account_email_address"] = account_email_address
array["account_api_client_id"] = account_api_client_id
array["account_api_secret"] = account_api_secret
array["account_vault_password"] = account_vault_password
return array
if __name__ == "__main__":
# INI config does not exist
if not does_file_exist(secrets_ini_file):
account_details = ask_for_account_details()
config = configparser.ConfigParser()
config[account_details["account_email_address"]] = {}
config[account_details["account_email_address"]]["account_api_client_id"] = account_details["account_api_client_id"]
config[account_details["account_email_address"]]["account_api_secret"] = account_details["account_api_secret"]
config[account_details["account_email_address"]]["account_vault_password"] = account_details["account_vault_password"]
with open(secrets_ini_file, "w") as configfile:
config.write(configfile)
config = configparser.ConfigParser()
config.read(secrets_ini_file)
accounts = config.sections()