Exemple #1
0
        public async Task <ActionResult> Step2(string repoId)
        {
            var repository = await _assetRepoCoordinator.GetRepository(repoId);

            if (repository == null)
            {
                // redirect to Step1 if no config.
                return(RedirectToAction("Index"));
            }

            if (repository.Enabled)
            {
                // not allowed to edit an existing enabled config
                return(RedirectToAction("Overview", new { repoId }));
            }

            string error        = null;
            string errorMessage = null;

            var canCreateTask = _azureResourceProvider.CanCreateResources(repository.SubscriptionId);
            var canAssignTask = _azureResourceProvider.CanCreateRoleAssignments(
                repository.SubscriptionId,
                repository.ResourceGroupName);

            var subnets = await _azureResourceProvider.GetSubnetsAsync(
                repository.SubscriptionId,
                repository.SelectedVNet.Location,
                repository.SelectedVNet.ResourceGroupName,
                repository.SelectedVNet.Name);

            var canCreate = await canCreateTask;
            var canAssign = await canAssignTask;

            if (!canCreate)
            {
                error        = "You don't have the required permissions to create resources";
                errorMessage = "In order to complete this step which involves creating resources, you must have the Owner or Contributor role for the specified Subscription. " +
                               "Either request someone with this role to complete the step, or ask your admin to make you an Owner or Contributor for the Subscription.";
            }
            else
            {
                if (!canAssign)
                {
                    error        = "You don't have the required permissions to assign roles to users";
                    errorMessage = "In order to complete this step which involves creating role assignments, you must have the Owner or User Access Administrator role for the specified Subscription. " +
                                   "Either request someone with this role to complete the step, or ask your admin to make you an Owner or User Access Administrator for the Subscription or Resource Group.";
                }
            }

            return(View("Create/Step2", new AddNetworkingModel(repository, subnets)
            {
                Error = error,
                ErrorMessage = errorMessage,
            }));
        }
        public async Task <ActionResult> Step2(string repoId)
        {
            var repository = await _assetRepoCoordinator.GetRepository(repoId);

            if (repository == null)
            {
                // redirect to Step1 if no config.
                return(RedirectToAction("Step1", new { repoId }));
            }

            if (repository.Enabled)
            {
                // not allowed to edit an existing enabled config
                return(RedirectToAction("Overview", new { repoId }));
            }

            string error        = null;
            string errorMessage = null;

            var canCreate = await _azureResourceProvider.CanCreateResources(repository.SubscriptionId);

            if (!canCreate)
            {
                error        = "You don't have the required permissions to create resources";
                errorMessage = "In order to complete this step which involves creating resources, you must have the Owner or Contributor role for the specified Subscription. " +
                               "Either request someone with this role to complete the step, or ask your admin to make you an Owner or Contributor for the Subscription.";
            }
            else
            {
                var canAssign = await _azureResourceProvider.CanCreateRoleAssignments(
                    repository.SubscriptionId,
                    repository.ResourceGroupName);

                if (!canAssign)
                {
                    error        = "You don't have the required permissions to assign roles to users";
                    errorMessage = "In order to complete this step which involves creating role assignments, you must have the Owner or User Access Administrator role for the specified Subscription. " +
                                   "Either request someone with this role to complete the step, or ask your admin to make you an Owner or User Access Administrator for the Subscription or Resource Group.";
                }
            }

            switch (repository)
            {
            case NfsFileServer nfs:
                return(View("Create/Step2Nfs", new AddNfsFileServerModel(nfs)
                {
                    VmName = "FileServer",
                    UserName = "******",
                    Password = Guid.NewGuid().ToString(),
                    FileShareName = "/exports/share",
                    Error = error,
                    ErrorMessage = errorMessage
                }));

            default:
                throw new NotSupportedException("Unknown type of repository");
            }
        }