示例#1
0
        /// <summary>
        /// Lambda to insert character to character table
        /// </summary>
        /// <param name="pRequest">Incoming API Gateway request object, should be a PUT or POST with a BODY</param>
        /// <param name="pContext">Incoming Lambda Context object, not used currently</param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest pRequest, ILambdaContext pContext)
        {
            if (pRequest.Headers.Keys.Contains("warmup"))
            {
                return(HttpHelper.WarmupResponse());
            }
            if (pRequest == null)
            {
                return(HttpHelper.HandleError("Request appears to be null", 500));
            }

            using (opendkpContext vDatabase = new opendkpContext())
            {
                if (!CognitoHelper.IsDkpAdmin(pRequest) ||
                    !CognitoHelper.IsAuthorizedAdmin(vDatabase, pRequest))
                {
                    return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                }
                var vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);

                //We need to retrieve the ClientId for multitenancy purposes
                var vClientId = pRequest.Headers["clientid"];

                if (pRequest.HttpMethod.Equals("PUT", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(HandleInsert(pRequest, pContext, vCognitoUser, vDatabase, vClientId));
                }
                else if (pRequest.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(HandleUpdate(pRequest, pContext, vCognitoUser, vDatabase, vClientId));
                }
            }
            return(HttpHelper.HandleError("Only Methods PUT,POST are supported by this lamdba", 500));
        }
示例#2
0
        /// <summary>
        /// Lambda to insert character to character table
        /// </summary>
        /// <param name="pRequest">Incoming API Gateway request object, should be a PUT or POST with a BODY</param>
        /// <param name="pContext">Incoming Lambda Context object, not used currently</param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest pRequest, ILambdaContext pContext)
        {
            if (pRequest.Headers != null && pRequest.Headers.Count > 0 && pRequest.Headers.Keys.Contains("warmup"))
            {
                return(HttpHelper.WarmupResponse());
            }
            if (pRequest == null)
            {
                return(HttpHelper.HandleError("Request appears to be null", 500));
            }
            //For these operations, we should have the CognitoInfo user available to us
            //Authorized Users only for Deleting Raids
            using (opendkpContext vDatabase = new opendkpContext())
            {
                if (!CognitoHelper.IsDkpAdmin(pRequest) ||
                    !CognitoHelper.IsAuthorizedAdmin(vDatabase, pRequest))
                {
                    return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                }
                var vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);

                if (pRequest.HttpMethod.Equals("PUT", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(HandleInsert(pRequest, pContext, vCognitoUser, vDatabase));
                }
                else if (pRequest.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(HandleUpdateAsync(pRequest, pContext, vCognitoUser, vDatabase));
                }
            }

            return(HttpHelper.HandleError("Only Methods PUT,POST are supported by this lamdba", 500));
        }
示例#3
0
        /// <summary>
        /// Lambda to insert character to character table
        /// </summary>
        /// <param name="pRequest">Incoming API Gateway request object, should be a PUT or POST with a BODY</param>
        /// <param name="pContext">Incoming Lambda Context object, not used currently</param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest pRequest, ILambdaContext pContext)
        {
            if (pRequest.Headers.Keys.Contains("warmup"))
            {
                return(HttpHelper.WarmupResponse());
            }
            var vResponse = HttpHelper.HandleError("[DeleteAdjustment] Unknown Backend error", 500);

            try
            {
                if (pRequest != null && pRequest.PathParameters != null && pRequest.PathParameters.Count > 0)
                {
                    int vId = int.Parse(pRequest.PathParameters["id"]);
                    using (opendkpContext vDatabase = new opendkpContext())
                    {
                        //Authorized Users only for Deleting Adjustments
                        if (!CognitoHelper.IsDkpAdmin(pRequest) ||
                            !CognitoHelper.IsAuthorizedAdmin(vDatabase, pRequest))
                        {
                            return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                        }
                        var vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);

                        //We need to retrieve the ClientId for multitenancy purposes
                        var vClientId = pRequest.Headers["clientid"];

                        var vResult = vDatabase.Adjustments
                                      .FirstOrDefault(x => x.ClientId.Equals(vClientId) && x.IdAdjustment == vId);
                        if (vResult != null)
                        {
                            vDatabase.Adjustments.Remove(vResult);
                            vDatabase.SaveChanges();

                            //Audit
                            AuditHelper.InsertAudit(vDatabase, vClientId, vResult, string.Empty, vCognitoUser.Username, Audit.ACTION_ADJUST_DELETE);

                            //Update Caches
                            int vStatus = CacheManager.UpdateSummaryCacheAsync(vClientId).GetAwaiter().GetResult();
                            Console.WriteLine("StatusCode for CacheUpdate=" + vStatus);

                            vResponse = HttpHelper.HandleResponse(vResult, 200, true);
                        }
                        else
                        {
                            vResponse = HttpHelper.HandleError("[DeleteAdjustment] Adjustment doesnt exist in DB", 500);
                        }
                    }
                }
            }
            catch
            {
                vResponse = HttpHelper.HandleError("[DeleteAdjustment] Issue with DB or Query", 500);
            }

            return(vResponse);
        }
示例#4
0
        /// <summary>
        /// Lambda to insert character to character table
        /// </summary>
        /// <param name="pRequest">Incoming API Gateway request object, should be a PUT or POST with a BODY</param>
        /// <param name="pContext">Incoming Lambda Context object, not used currently</param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest pRequest, ILambdaContext pContext)
        {
            if (pRequest.Headers.Keys.Contains("warmup"))
            {
                return(HttpHelper.WarmupResponse());
            }
            var vResponse = HttpHelper.HandleError("[DeleteCharacter] Unknown Backend error", 500);

            try
            {
                if (pRequest != null && pRequest.PathParameters != null && pRequest.PathParameters.Count > 0)
                {
                    //We need to retrieve the ClientId for multitenancy purposes
                    var vClientId = pRequest.Headers["clientid"];

                    string vCharacterName = pRequest.PathParameters["character"];
                    using (opendkpContext vDatabase = new opendkpContext())
                    {
                        //Authorized Users only for Deleting Characters
                        if (!CognitoHelper.IsDkpAdmin(pRequest) ||
                            !CognitoHelper.IsAuthorizedAdmin(vDatabase, pRequest))
                        {
                            return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                        }
                        var vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);

                        var vResult = vDatabase.
                                      Characters.
                                      FirstOrDefault(x => x.ClientId.Equals(vClientId) &&
                                                     x.Name.Equals(vCharacterName, StringComparison.InvariantCultureIgnoreCase));

                        if (vResult != null)
                        {
                            vDatabase.Characters.Remove(vResult);
                            vDatabase.SaveChanges();
                            AuditHelper.InsertAudit(vDatabase, vClientId, vResult, string.Empty, vCognitoUser.Username, Audit.ACTION_CHAR_DELETE);
                            vResponse = HttpHelper.HandleResponse(vResult, 200);
                        }
                        else
                        {
                            vResponse = HttpHelper.HandleError("[DeleteCharacter] Character doesn't exist in the DB", 500);
                        }
                    }
                }
            }
            catch
            {
                vResponse = HttpHelper.HandleError("[DeleteCharacter] Issue with DB or Query", 500);
            }

            return(vResponse);
        }
示例#5
0
        /// <summary>
        /// Lambda to insert character to character table
        /// </summary>
        /// <param name="pRequest">Incoming API Gateway request object, should be a PUT or POST with a BODY</param>
        /// <param name="pContext">Incoming Lambda Context object, not used currently</param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest pRequest, ILambdaContext pContext)
        {
            if (pRequest.Headers.Keys.Contains("warmup"))
            {
                return(HttpHelper.WarmupResponse());
            }
            var vResponse = HttpHelper.HandleError("[DeleteRaid] Unknown Backend error", 500);

            try
            {
                if (pRequest != null && pRequest.PathParameters != null && pRequest.PathParameters.Count > 0)
                {
                    int vId = int.Parse(pRequest.PathParameters["id"]);
                    using (opendkpContext vDatabase = new opendkpContext())
                    {
                        //Authorized Users only for Deleting Raids
                        if (!CognitoHelper.IsDkpAdmin(pRequest) ||
                            !CognitoHelper.IsAuthorizedAdmin(vDatabase, pRequest))
                        {
                            return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                        }
                        var vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);

                        //We need to retrieve the ClientId for multitenancy purposes
                        var vClientId = pRequest.Headers["clientid"];

                        Raids vResult = RaidHelper.DeleteRaid(vDatabase, vId, vClientId);
                        vDatabase.SaveChanges();
                        vResponse = HttpHelper.HandleResponse(vResult, 200);

                        //Audit
                        AuditHelper.InsertAudit(vDatabase, vClientId, vResult, string.Empty, vCognitoUser.Username, Audit.ACTION_RAID_DELETE);

                        //Update Caches
                        int vStatus = CacheManager.UpdateSummaryCacheAsync(vClientId).GetAwaiter().GetResult();
                        Console.WriteLine("SummaryCacheResponse=" + vStatus);
                        vStatus = CacheManager.UpdateItemCacheAsync(vClientId).GetAwaiter().GetResult();
                        Console.WriteLine("ItemCacheResponse=" + vStatus);
                    }
                }
            }
            catch
            {
                vResponse = HttpHelper.HandleError("[DeleteRaid] Issue with DB or Query", 500);
            }

            return(vResponse);
        }
示例#6
0
        /// <summary>
        /// Lambda to insert character to character table
        /// </summary>
        /// <param name="pRequest">Incoming API Gateway request object, should be a PUT or POST with a BODY</param>
        /// <param name="pContext">Incoming Lambda Context object, not used currently</param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest pRequest, ILambdaContext pContext)
        {
            if (pRequest.Headers != null && pRequest.Headers.Count > 0 && pRequest.Headers.Keys.Contains("warmup"))
            {
                return(HttpHelper.WarmupResponse());
            }
            var vResponse = HttpHelper.HandleError("[UserRequestsLambda] Unknown Backend error", 500);

            //We need to retrieve the ClientId for multitenancy purposes
            var vClientId = pRequest.Headers["clientid"];

            try
            {
                using (opendkpContext vDatabase = new opendkpContext())
                {
                    //For these operations, we should have the CognitoInfo user available to us
                    if (pRequest.Headers != null && !pRequest.Headers.ContainsKey("cognitoinfo"))
                    {
                        return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                    }

                    CognitoUser vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);
                    if (pRequest.HttpMethod.Equals("GET", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //If the GET request has PathParameter of the account, fetch all requests for given account
                        //Otherwise return all requests
                        if (pRequest != null && pRequest.PathParameters != null && pRequest.PathParameters.Count > 0)
                        {
                            string vAccountName = pRequest.PathParameters["account"];
                            vResponse = GetAccountRequests(vDatabase, vAccountName, vClientId);
                        }
                        else
                        {
                            vResponse = GetAllRequests(vDatabase, vClientId);
                        }
                    }

                    //PUT can come from any user, such as a standard user who wants to assign a character to themselves
                    //or credit for a raid tick.
                    if (pRequest.HttpMethod.Equals("PUT", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (vCognitoUser == null)
                        {
                            return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                        }
                        UserRequests vUserRequest = JsonConvert.DeserializeObject <UserRequests>(pRequest.Body);
                        if (vUserRequest.RequestType == UserRequests.TYPE_CHARACTER_ASSIGN)
                        {
                            vResponse = HandleCharacterAssignRequest(vDatabase, vUserRequest, pRequest, vCognitoUser);
                        }
                        if (vUserRequest.RequestType == UserRequests.TYPE_RAIDTICK)
                        {
                            vResponse = HandleRaidTickRequest(vDatabase, vUserRequest, pRequest, vCognitoUser);
                        }
                    }

                    //POST can only come from admins, need to make sure cognito Groups contains "DKP_ADMIN" or "SITE_ADMIN"
                    //This would be for approving or denying requests
                    if (pRequest.HttpMethod.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!CognitoHelper.IsDkpAdmin(pRequest) ||
                            !CognitoHelper.IsAuthorizedAdmin(vDatabase, pRequest))
                        {
                            return(HttpHelper.HandleError("You do not have permission to perform this action", 401));
                        }
                        vCognitoUser = CognitoHelper.GetCognitoUser(pRequest.Headers["cognitoinfo"]);

                        UserRequests vUserRequest = JsonConvert.DeserializeObject <UserRequests>(pRequest.Body);
                        if (vUserRequest.RequestType == UserRequests.TYPE_CHARACTER_ASSIGN)
                        {
                            vResponse = UpdateCharacterAssignRequest(vDatabase, vClientId, vUserRequest, vCognitoUser);
                        }
                        if (vUserRequest.RequestType == UserRequests.TYPE_RAIDTICK)
                        {
                            vResponse = UpdateRaidTickRequest(vDatabase, vUserRequest, vCognitoUser, vClientId);
                        }
                    }
                }
            }
            catch (Exception vException)
            {
                vResponse = HttpHelper.HandleError("[UserRequestsLambda] Issue with DB or Query: " + vException.Message, 500);
            }

            return(vResponse);
        }