in radlab-launcher/radlab.py [0:0]
def getbillingacc():
x = input("\nSet Billing Account ?\n[1] Enter Manually\n[2] Select from the List\n" + Fore.YELLOW + Style.BRIGHT + "Choose a number for your choice" + Style.RESET_ALL + ': ').strip()
if (x == '1'):
billing_acc = input(Fore.YELLOW + Style.BRIGHT + "Enter the Billing Account ( Example format - ABCDEF-GHIJKL-MNOPQR )" + Style.RESET_ALL + ': ').strip()
return billing_acc
elif (x == '2'):
credentials = GoogleCredentials.get_application_default()
service = discovery.build('cloudbilling', 'v1', credentials=credentials)
request = service.billingAccounts().list()
response = request.execute()
# print(response['billingAccounts'])
print("\nList of Billing account you have access to: \n")
billing_accounts = []
# Print out Billing accounts
for x in range(len(response['billingAccounts'])):
print("[" + str(x + 1) + "] " + response['billingAccounts'][x]['name'] + " " + response['billingAccounts'][x]['displayName'])
billing_accounts.append(response['billingAccounts'][x]['name'])
# Take user input and get the corresponding item from the list
inp = int(input(Fore.YELLOW + Style.BRIGHT + "Choose a number for Billing Account" + Style.RESET_ALL + ': '))
if inp in range(1, len(billing_accounts) + 1):
inp = billing_accounts[inp - 1]
billing_acc = inp.split('/')
# print(billing_acc[1])
return billing_acc[1]
else:
sys.exit(Fore.RED + "\nError Occured - INVALID BILLING ACCOUNT\n")
else:
sys.exit(Fore.RED + "\nError Occured - INVALID CHOICE\n" + Style.RESET_ALL)