add_azure_account_and_set_role_assignment_6.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. def main():
  2. try:
  3. CloudCheckrApiKey = str(sys.argv[1])
  4. except IndexError:
  5. print("Must include an admin api key in the command line")
  6. return
  7. try:
  8. NameOfCloudCheckrAccount = str(sys.argv[2])
  9. except IndexError:
  10. print("Must include a cloudcheckr account name")
  11. return
  12. try:
  13. AzureDirectoryId = str(sys.argv[3])
  14. except IndexError:
  15. print("Must include an Azure Directory Id")
  16. return
  17. try:
  18. AzureSubscriptionId = str(sys.argv[4])
  19. except IndexError:
  20. print("Must include an Azure Subscription Id")
  21. return
  22. try:
  23. AzureAdminApplicationId = str(sys.argv[5])
  24. except IndexError:
  25. print("Must include an Azure Admin ApplictApi Id")
  26. return
  27. try:
  28. AzureAdminApplicationSecret = str(sys.argv[6])
  29. except IndexError:
  30. print("Must include an Azure Admin Application Secret")
  31. return
  32. try:
  33. AzureCloudCheckrApplicationName = str(sys.argv[7])
  34. except IndexError:
  35. print("Must include an Azure CloudCheckr Application Name")
  36. return
  37. try:
  38. AzureCloudCheckrApplicationSecret = str(sys.argv[8])
  39. except IndexError:
  40. print("Must include an Azure CloudCheckr Application Secret")
  41. return
  42. env = "https://glacier.cloudcheckr.com"
  43. AzureApiBearerToken = get_azure_bearer_token("https://management.azure.com/", AzureDirectoryId,
  44. AzureAdminApplicationId, AzureAdminApplicationSecret)
  45. AzureGraphApiBearerToken = get_azure_bearer_token("https://graph.microsoft.com/", AzureDirectoryId,
  46. AzureAdminApplicationId, AzureAdminApplicationSecret)
  47. AzureReaderRoleId = get_azure_reader_role_id(AzureApiBearerToken, AzureSubscriptionId)
  48. AzureCloudCheckrApplicationServicePrincipalId, AzureCloudCheckrApplicationId = get_azure_cloudcheckr_service_principal_id(
  49. AzureGraphApiBearerToken, AzureCloudCheckrApplicationName)
  50. set_azure_cloudcheckr_application_service_assignment(AzureApiBearerToken, AzureReaderRoleId,
  51. AzureCloudCheckrApplicationServicePrincipalId,
  52. AzureSubscriptionId)
  53. create_azure_account(env, CloudCheckrApiKey, NameOfCloudCheckrAccount, AzureDirectoryId,
  54. AzureCloudCheckrApplicationId, AzureCloudCheckrApplicationSecret, AzureSubscriptionId)