Commits

Stefan Saasen committed d2baf13

Fix parsing of actions

The actions recorded for ssh access have a different format than the ones that
are recorded for http.

Comments (0)

Files changed (2)

src/Stash/Log/Parser.hs

 data Action = Action {
      getMethod       :: S.ByteString
     ,getPath         :: S.ByteString
-    ,getVersion      :: S.ByteString
 } deriving (Show, Eq)
 
 data InOurOut = In | Out deriving (Show, Eq)
 
 -- =================================================================================
 
-pipe, space, dash, colon, comma, quote, x :: Parser Char
+pipe, space, dash, colon, comma, quote, single, x :: Parser Char
 pipe        = satisfy (== '|')
 space       = satisfy (== ' ')
 dash        = satisfy (== '-')
 colon       = satisfy (== ':')
 comma       = satisfy (== ',')
 quote       = satisfy (== '"')
+single      = satisfy (== '\'')
 x           = satisfy (== 'x')
 
 -- 2012-08-22 18:32:08,505
     pipe
     space
 
+
+-- http: "GET /scm/CONF/confluence.git/info/refs HTTP/1.1"
+-- ssh: git-upload-pack '/CONF/teamcal.git'
 parseAction :: Parser Action
-parseAction = do
+parseAction = do choice [parseSshAction, parseHttpAction]
+
+parseSshAction :: Parser Action
+parseSshAction = do
+    method <- takeTill (== ' ')
+    space
+    single
+    path <- takeTill (== '\'')
+    single
+    separator
+    return $ Action method path
+
+
+
+parseHttpAction :: Parser Action
+parseHttpAction = do
     quote
     method <- takeTill (== ' ')
     space
     path <- takeTill (== ' ')
     space
-    version <- takeTill (== '"')
+    _ <- takeTill (== '"')
     quote
     separator
-    return $ Action method path version
+    return $ Action method path
 
 
 -- | Parse an access log line

tests/Properties.hs

 parsedLogLine2 = parseLogLine inputLine
     where inputLine = "63.246.22.196,172.16.3.45 | https | i1112x6x32 | - | 2012-08-22 18:32:08,505 | \"GET /git/ATLASSIAN/jira.git/info/refs HTTP/1.1\" | \"\" \"git/1.7.4.1\" | fetch | - | - | "
 
+parsedLogLine3 = parseLogLine inputLine
+    where inputLine = "172.16.3.7 | ssh | o949x7523178x1 | atlaseye_user | 2012-10-23 15:49:46,461 | git-upload-pack '/CONF/teamcal.git' | - | fetch | 117 | de84i5 | "
+
 test_parseLogEntryDate = H.assertEqual
     "Should parse the date correctly"
     (LogDate 2012 8 22 18 32 08 505)
     "https"
     (getProtocol $ fromJust parsedLogLine)
 
+test_logLineParseProtocolSsh = H.assertEqual
+    "Should parse the protocol correctly"
+    "ssh"
+    (getProtocol $ fromJust parsedLogLine3)
+
 test_logLineParseAction = H.assertEqual
-    "Should parse the labels correctly"
+    "Should parse the action correctly for http"
     "/git/ATLASSIAN/jira.git/info/refs"
     (getPath $ getAction $ fromJust parsedLogLine)
 
+test_logLineParseActionSsh = H.assertEqual
+    "Should parse the action correctly for ssh"
+    "/CONF/teamcal.git"
+    (getPath $ getAction $ fromJust parsedLogLine3)
+
 test_logLineParseDetails = H.assertEqual
     "Should parse the labels correctly"
     "\"\" \"git/1.7.4.1\""
 dataLogLines = [
     "63.246.22.196,172.16.3.45 | https | i1112x6x6 | - | 2012-08-22 18:32:08,505 | \"GET /git/ATLASSIAN/jira.git/info/refs HTTP/1.1\" | \"\" \"git/1.7.4.1\" | - | - | - | "
     ,"63.246.22.196,172.16.3.45 | https | i1112x10x10 | - | 2012-08-22 18:32:55,300 | \"GET /git/ATLASSIAN/jira.git/info/refs HTTP/1.1\" | \"\" \"git/1.7.4.1\" | - | - | - | "
-    ,"63.246.22.222,172.16.3.45 | https | o1227x7026x1 | bamboo_user | 2012-08-22 20:28:04,864 | \"POST /git/STASH/stash.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.11.1\" | clone | 15109 | - | "
+    ,"172.16.3.7 | ssh | o949x7523178x1 | atlaseye_user | 2012-08-22 20:28:04,864 | git-upload-pack '/CONF/teamcal.git' | - | fetch | 117 | de84i5 | "
     ,"63.246.22.222,172.16.3.45 | https | o1266x9120x4 | bamboo_user | 2012-08-22 21:07:11,798 | \"POST /git/STASH/stash.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.11.1\" | clone | 12426 | - | "
     ,"63.246.22.222,172.16.3.45 | https | o1439x17982x5 | bamboo_user | 2012-08-22 23:59:59,296 | \"POST /git/ATLASSIAN/jira.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.11.1\" | shallow clone | 289 | 1h32yz6 | "
     ,"63.246.22.222,172.16.3.45 | https | o1439x17983x4 | bamboo_user | 2012-08-22 23:59:59,460 | \"POST /git/ATLASSIAN/jira.git/git-upload-pack HTTP/1.1\" | \"\" \"git/1.7.11.1\" | shallow clone | 368 | 1p7ya9s | "
     ,"63.246.22.222,172.16.3.45 | https | i2112x2x4 | - | 2012-08-23 17:44:20,123 | \"GET /git/ATLASSIAN/jira.git/info/refs HTTP/1.1\" | \"\" \"JGit/unknown\" | - | - | - | "
-    ,"63.246.22.196,172.16.3.45 | ssh | i2112x4x2 | - | 2012-08-23 17:48:20,505 | \"GET /git/ATLASSIAN/jira.git/info/refs HTTP/1.1\" | \"\" \"git/1.7.4.1\" | - | - | - | "]
+    ,"63.246.22.196,172.16.3.45 | ssh | i2112x4x2 | - | 2012-08-23 17:48:20,505 | git-upload-pack '/CONF/teamcal.git' | \"\" \"git/1.7.4.1\" | - | - | - | "]
 
 
 test_plotDataConcurrentConn = H.assertEqual
 
 test_protocolCount = H.assertEqual
     "Should count the protocol correctly"
-    [("https", 7), ("ssh", 1)]
+    [("https", 6), ("ssh", 2)]
     (protocolCount dataLogLines)
 
 ------------------------------------------------------------------------
       testGroup "parser"
       [ testCase "parser/parse empty String" test_logLineParserEmpty
         ,testCase "parser/parse single line" test_logLineParseSingleLine
-        ,testCase "parser/parse protocol" test_logLineParseProtocol
+        ,testCase "parser/parse protocol (https)" test_logLineParseProtocol
+        ,testCase "parser/parse protocol (ssh)" test_logLineParseProtocolSsh
         ,testCase "parser/parse request id" test_logLineParseRequestId
         ,testCase "parser/parse action" test_logLineParseAction
         ,testCase "parser/parse details" test_logLineParseDetails