Esempio n. 1
0
        public async Task <IActionResult> Post(string groupId, string resourceId, string actionname, uint?duration = null)
        {
            ScampResource res = await _resourceRepository.GetResource(resourceId);

            if (res == null)
            {
                return(new HttpStatusCodeResult(404)); // not found
            }
            ResourceAction action   = WebJobController.GetAction(actionname);
            ResourceState  newState = ResourceState.Unknown;

            switch (action)
            {
            case ResourceAction.Start:
                newState = ResourceState.Starting;
                break;

            case ResourceAction.Stop:
                newState = ResourceState.Stopping;
                break;
            }

            if (await CanManageResource(res, action))
            {
                await _volatileStorageController.UpdateResourceState(resourceId, newState);

                _webJobController.SubmitActionInQueue(resourceId, action, duration);
            }

            return(new HttpStatusCodeResult(204));
        }
Esempio n. 2
0
        public async Task <IActionResult> RemoveUserFromGroup(string groupId, string userId)
        {
            if (!await _securityHelper.CurrentUserCanManageGroup(groupId))
            {
                return(new HttpStatusCodeResult(403)); // Forbidden
            }

            var requestingUser = await _securityHelper.GetOrCreateCurrentUser();

            // don't allow user to remove themselves
            if (requestingUser.Id == userId)
            {
                return new ObjectResult("User cannot remove themselves")
                       {
                           StatusCode = 403
                       }
            }
            ;

            // remove the user from the group
            await _groupRepository.RemoveUserFromGroup(groupId, userId);

            // get list of user resources in this group
            IEnumerable <ScampUserGroupResources> resources = await _groupRepository.GetGroupMemberResources(groupId, userId);

            foreach (ScampUserGroupResources resource in resources)
            {
                // request deprovisioning of user resources
                // this will delete the resource entries and update the group usage
                _webJobController.SubmitActionInQueue(resource.Id, ResourceAction.Delete);
            }

            // remove the user's budget entry for the group from the volatile store
            await _volatileStorageController.DeleteUserBudgetState(userId, groupId);

            return(new ObjectResult(null)
            {
                StatusCode = 200
            });
        }
    }