public ActionResult Index() { HomeIndexViewModel model = null; if (ClaimsPrincipal.Current.Identity.IsAuthenticated) { model = new HomeIndexViewModel(); model.UserOrganizations = new Dictionary <string, Organization>(); model.UserSubscriptions = new Dictionary <string, Subscription>(); model.UserCanManageAccessForSubscriptions = new List <string>(); model.DisconnectedUserOrganizations = new List <string>(); var orgnaizations = AzureResourceManagerUtil.GetUserOrganizations(); foreach (Organization org in orgnaizations) { model.UserOrganizations.Add(org.Id, org); var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(org.Id); if (subscriptions != null) { foreach (var subscription in subscriptions) { Subscription s = db.Subscriptions.Find(subscription.Id); if (s != null) { subscription.IsConnected = true; subscription.ConnectedOn = s.ConnectedOn; subscription.ConnectedBy = s.ConnectedBy; subscription.AzureAccessNeedsToBeRepaired = AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, org.Id); subscription.UsageString = AzureResourceManagerUtil.GetUsage(s.Id, org.Id); //Deserialize the usage response into the usagePayload object subscription.usagePayload = JsonConvert.DeserializeObject <UsagePayload>(subscription.UsageString); List <UsageAggregate> UsageAggregateList = subscription.usagePayload.value; } else { subscription.IsConnected = false; } model.UserSubscriptions.Add(subscription.Id, subscription); if (AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id, org.Id)) { model.UserCanManageAccessForSubscriptions.Add(subscription.Id); } } } else { model.DisconnectedUserOrganizations.Add(org.Id); } } } return(View(model)); }
public ActionResult Index() { HomeIndexViewModel model = null; if (ClaimsPrincipal.Current.Identity.IsAuthenticated) { model = new HomeIndexViewModel(); model.UserOrganizations = new Dictionary <Guid, Organization>(); model.UserSubscriptions = new Dictionary <Guid, Subscription>(); model.UserCanManageAccessForSubscriptions = new List <Guid>(); model.DisconnectedUserOrganizations = new List <Guid>(); var organizations = AzureResourceManagerUtil.GetUserOrganizations(); foreach (Organization org in organizations) { model.UserOrganizations.Add(org.Id, org); var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(org.Id); if (subscriptions != null) { foreach (var subscription in subscriptions) { Subscription s = db.Subscriptions.Find(subscription.Id); if (s != null) { subscription.IsConnected = true; subscription.ConnectedOn = s.ConnectedOn; subscription.ConnectedBy = s.ConnectedBy; subscription.DisplayTag = s.DisplayTag; subscription.AzureAccessNeedsToBeRepaired = !AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(subscription.Id, org.Id); } else { subscription.IsConnected = false; } model.UserSubscriptions.Add(subscription.Id, subscription); if (AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id, org.Id)) { model.UserCanManageAccessForSubscriptions.Add(subscription.Id); } } } else { model.DisconnectedUserOrganizations.Add(org.Id); } } } return(View(model)); }
public ActionResult Index() { HomeIndexViewModel model = null; if (ClaimsPrincipal.Current.Identity.IsAuthenticated) { model = new HomeIndexViewModel(); model.UserSubscriptions = new Dictionary <string, Subscription>(); model.UserCanManageAccessForSubscriptions = new List <string>(); var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(ConfigurationManager.AppSettings["AADId"]); if (subscriptions != null) { foreach (var subscription in subscriptions) { Subscription s = db.Subscriptions.Find(subscription.Id); if (s != null) { subscription.IsConnected = true; subscription.ConnectedOn = s.ConnectedOn; subscription.ConnectedBy = s.ConnectedBy; subscription.AzureAccessNeedsToBeRepaired = !AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription (subscription.Id, ConfigurationManager.AppSettings["AADId"]); } else { subscription.IsConnected = false; } model.UserSubscriptions.Add(subscription.Id, subscription); if (AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id, ConfigurationManager.AppSettings["AADId"])) { model.UserCanManageAccessForSubscriptions.Add(subscription.Id); } } } } return(View(model)); }
public async Task <UserSubscriptionInfo> GetUserDetailsFull() { var subscriptionInfo = new UserSubscriptionInfo(); subscriptionInfo.UserName = ClaimsPrincipal.Current.Identity.Name; subscriptionInfo.FirstName = ClaimsPrincipal.Current.FirstName(); subscriptionInfo.LastName = ClaimsPrincipal.Current.LastName(); subscriptionInfo.DefaultAdGroup = Config.DefaultAdGroup; subscriptionInfo.DefaultResourceGroup = Config.DefaultResourceGroup; string tenantId = ClaimsPrincipal.Current.TenantId(); string signedInUserUniqueId = ClaimsPrincipal.Current.SignedInUserName(); var userGroupsRoles = AzureADGraphApiUtil.GetUserGroups(signedInUserUniqueId, tenantId); subscriptionInfo.IsGlobalAdministrator = AzureADGraphApiUtil.IsGlobalAdministrator(userGroupsRoles); var org = GetOrganization(tenantId); var dbOrg = await this.coreRepository.GetOrganization(tenantId); List <Subscription> dbSubscriptions = null; if (dbOrg != null) { org.DeployGroup = dbOrg.DeployGroup; org.CreateProductGroup = dbOrg.CreateProductGroup; org.AdminGroup = dbOrg.AdminGroup; //var userGroups = AzureADGraphApiUtil.GetUserGroups(signedInUserUniqueId, org.Id); subscriptionInfo.CanCreate = userGroupsRoles.Any(x => x.Id == dbOrg.CreateProductGroup); subscriptionInfo.CanDeploy = userGroupsRoles.Any(x => x.Id == dbOrg.DeployGroup); subscriptionInfo.CanAdmin = userGroupsRoles.Any(x => x.Id == dbOrg.AdminGroup); dbSubscriptions = this.coreRepository.GetSubscriptionListByOrgId(tenantId); if (dbSubscriptions != null && dbSubscriptions.Count > 0) { subscriptionInfo.IsActivatedByAdmin = (dbSubscriptions.Any(x => x.IsConnected)); } } subscriptionInfo.Organization = org; var orgGroups = AzureADGraphApiUtil.GetAllGroupsForOrganization(org.Id); subscriptionInfo.OrganizationADGroups = orgGroups; var subscriptions = AzureResourceManagerUtil.GetUserSubscriptions(org.Id); if (subscriptions != null) { foreach (var subscription in subscriptions) { var userDetailVM = new UserDetailsViewModel(); userDetailVM.CanCreate = subscriptionInfo.CanCreate; userDetailVM.CanDeploy = subscriptionInfo.CanDeploy; userDetailVM.CanAdmin = subscriptionInfo.CanAdmin; userDetailVM.Name = subscriptionInfo.UserName; userDetailVM.IsAdminOfSubscription = AzureResourceManagerUtil.UserCanManageAccessForSubscription(subscription.Id); userDetailVM.SubscriptionName = subscription.DisplayName; userDetailVM.SubscriptionId = subscription.Id; userDetailVM.OrganizationId = org.Id; userDetailVM.ServicePrincipalId = org.ObjectIdOfCloudSenseServicePrincipal; userDetailVM.OrganizationName = org.DisplayName; Subscription dbSubscription = null; if (dbSubscriptions != null && dbSubscriptions.Count > 0) { dbSubscription = dbSubscriptions.FirstOrDefault(x => x.Id == subscription.Id) ?? null; } if (dbSubscription != null) { userDetailVM.SubscriptionIsConnected = dbSubscription.IsConnected;// true; userDetailVM.IsEnrolled = dbSubscription.IsEnrolled; userDetailVM.SubscriptionNeedsRepair = !AzureResourceManagerUtil.ServicePrincipalHasReadAccessToSubscription(dbSubscription.Id); if (userDetailVM.SubscriptionIsConnected) { string organizationId = dbSubscription.OrganizationId; string storageName = dbSubscription.StorageName; try { string storageKey = await AzureResourceManagerUtil.GetStorageAccountKeysArm(dbSubscription.Id, dbSubscription.StorageName); CacheDetails(userDetailVM, storageKey, storageName, organizationId, signedInUserUniqueId); } catch (Exception ex) { Trace.TraceError(ex.Message); Trace.TraceError($"Storage account: {storageName} was not found!"); userDetailVM.SubscriptionIsConnected = false; userDetailVM.IsEnrolled = false; } } } subscriptionInfo.Subscriptions.Add(userDetailVM); } } return(subscriptionInfo); }