public async Task FunctionHandler(S3NotificationEvent input, ILambdaContext context)
        {
            var data      = input?.GetFileData();
            var retriever = new S3ObjectRetriever(data.Value.objectsKey,
                                                  RegionEndpoint.GetBySystemName(data.Value.region));

            using var connection = new DbConnection();
            await connection.GetConnection().OpenAsync().ConfigureAwait(false);

            var    logSaver = new LogSaver(connection.GetConnection());
            string logId    = await logSaver.GetAssociatedLogIdAsync(data.Value.objectsKey).ConfigureAwait(false);

            if (!String.IsNullOrEmpty(logId))
            {
                var entries = retriever.GetObjectDataAsync().Select(
                    logLine => EntryParser.ProcessLogLine(logLine));
                await logSaver.SaveLogsAsync(logId, entries).ConfigureAwait(false);

                if (NotificationSender.IsNotificationNecessary(data.Value.objectsKey))
                {
                    await NotificationSender.TryPublishNotification(data.Value.objectsKey).ConfigureAwait(false);
                }
            }
            else
            {
                throw new Exception($"Log with given object name " +
                                    $"({data.Value.objectsKey}) has no associated record in database");
            }
        }
Ejemplo n.º 2
0
        public void TestProcessLogLineMatchUserAgent(string logLine, string expectedUserAgent)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(expectedUserAgent, logEntry.UserAgent);
        }
Ejemplo n.º 3
0
        public void TestProcessLogLineMatchRawEntry(string logLine)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(logLine, logEntry.RawEntry);
        }
Ejemplo n.º 4
0
        public void TestProcessLogLineMatchResponseCode(string logLine, int expectedResponseCode)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(expectedResponseCode, logEntry.ResponseCode);
        }
Ejemplo n.º 5
0
        public void TestProcessLogLineMatchIP(string logLine, string expectedIP)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(expectedIP, logEntry.ClientIp);
        }
Ejemplo n.º 6
0
        public void TestProcessLogLineMatchRequestTime(string logLine, DateTime expectedRequestTime)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(expectedRequestTime, logEntry.RequestTime);
        }
Ejemplo n.º 7
0
        public void TestProcessLogLineMatchResource(string logLine, string expectedResource)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(expectedResource, logEntry.Resource);
        }
Ejemplo n.º 8
0
        public void TestProcessLogLineMatchMethod(string logLine, LogEntry.RequestType expectedMethod)
        {
            var logEntry = EntryParser.ProcessLogLine(logLine);

            Assert.Equal(expectedMethod, logEntry.Method);
        }