haskell-neo4j-client 0.3.2.1 → 0.3.2.2
raw patch · 4 files changed
+47/−12 lines, 4 filesdep +http-client-tls
Dependencies added: http-client-tls
Files
- haskell-neo4j-client.cabal +5/−1
- src/Database/Neo4j.hs +1/−0
- src/Database/Neo4j/Http.hs +40/−11
- src/Database/Neo4j/Types.hs +1/−0
haskell-neo4j-client.cabal view
@@ -1,5 +1,5 @@ name: haskell-neo4j-client-version: 0.3.2.1+version: 0.3.2.2 synopsis: A Haskell neo4j client description: Library to interact with Neo4j databases. @@ -16,6 +16,8 @@ . -Authentication .+ -SSL+ . All code has been tested with Neo4j versions 2.0.3, 2.1.5, 2.1.7, 2.2.0 and 2.2.1 homepage: https://github.com/asilvestre/haskell-neo4j-rest-client license: MIT@@ -47,6 +49,7 @@ , Cabal , text >= 1.1 , http-client >= 0.4+ , http-client-tls >= 0.2 , http-conduit >= 2.1 , http-types >= 0.8 , resourcet >= 1.1@@ -78,6 +81,7 @@ , containers >= 0.5 , text >= 1.1 , http-client >= 0.4+ , http-client-tls >= 0.2 , http-conduit >= 2.1 , http-types >= 0.8 , bytestring >= 0.10
src/Database/Neo4j.hs view
@@ -17,6 +17,7 @@ -- * Connection handling objects Connection, Hostname, Port, Credentials, newConnection, withConnection, newAuthConnection, withAuthConnection,+ newSecureConnection, withSecureConnection, newSecureAuthConnection, withSecureAuthConnection, -- * Main monadic type to handle sequences of commands to Neo4j Neo4j(..), -- * Constructing and managing node/relationship properties
src/Database/Neo4j/Http.hs view
@@ -11,7 +11,7 @@ import Data.Aeson ((.:)) import Data.Aeson.Types (parseMaybe) -import Network.HTTP.Client (defaultManagerSettings)+import Network.HTTP.Client.TLS (tlsManagerSettings) import Text.ParserCombinators.ReadP @@ -27,39 +27,68 @@ -- | Create a new connection that can be manually closed with runResourceT newConnection :: Hostname -> Port -> IO Connection newConnection hostname port = do- mgr <- HC.newManager defaultManagerSettings- return $ Connection hostname port mgr Nothing+ mgr <- HC.newManager tlsManagerSettings+ return $ Connection hostname port mgr Nothing False +-- | Create a new https connection that can be manually closed with runResourceT+newSecureConnection :: Hostname -> Port -> IO Connection+newSecureConnection hostname port = do+ mgr <- HC.newManager tlsManagerSettings+ return $ Connection hostname port mgr Nothing True+ -- | Create a new connection that can be manually closed with runResourceT using provided credentials for basic auth newAuthConnection :: Hostname -> Port -> Credentials -> IO Connection newAuthConnection hostname port creds = do- mgr <- HC.newManager defaultManagerSettings- return $ Connection hostname port mgr (Just creds)+ mgr <- HC.newManager tlsManagerSettings+ return $ Connection hostname port mgr (Just creds) False +-- | Create a new https connection that can be manually closed with runResourceT using provided credentials for basic auth+newSecureAuthConnection :: Hostname -> Port -> Credentials -> IO Connection+newSecureAuthConnection hostname port creds = do+ mgr <- HC.newManager tlsManagerSettings+ return $ Connection hostname port mgr (Just creds) True+ -- | Run a set of Neo4j commands in a single connection withConnection :: Hostname -> Port -> Neo4j a -> IO a withConnection hostname port cmds = runResourceT $ do- mgr <- liftIO $ HC.newManager defaultManagerSettings- let conn = Connection hostname port mgr Nothing+ mgr <- liftIO $ HC.newManager tlsManagerSettings+ let conn = Connection hostname port mgr Nothing False liftIO $ runNeo4j cmds conn +-- | Run a set of Neo4j commands in a single https connection+withSecureConnection :: Hostname -> Port -> Neo4j a -> IO a+withSecureConnection hostname port cmds = runResourceT $ do+ mgr <- liftIO $ HC.newManager tlsManagerSettings+ let conn = Connection hostname port mgr Nothing True+ liftIO $ runNeo4j cmds conn++ -- | Run a set of Neo4j commands in a single connection using provided credentials for basic auth withAuthConnection :: Hostname -> Port -> Credentials -> Neo4j a -> IO a withAuthConnection hostname port creds cmds = runResourceT $ do- mgr <- liftIO $ HC.newManager defaultManagerSettings- let conn = Connection hostname port mgr (Just creds)+ mgr <- liftIO $ HC.newManager tlsManagerSettings+ let conn = Connection hostname port mgr (Just creds) False liftIO $ runNeo4j cmds conn- ++-- | Run a set of Neo4j commands in a single https connection using provided credentials for basic auth+withSecureAuthConnection :: Hostname -> Port -> Credentials -> Neo4j a -> IO a+withSecureAuthConnection hostname port creds cmds = runResourceT $ do+ mgr <- liftIO $ HC.newManager tlsManagerSettings+ let conn = Connection hostname port mgr (Just creds) True+ liftIO $ runNeo4j cmds conn++ -- | General function for HTTP requests httpReq :: Connection -> HT.Method -> S.ByteString -> L.ByteString -> (HT.Status -> Bool) -> IO (HC.Response L.ByteString)-httpReq (Connection h p m c) method path body statusCheck = do+httpReq (Connection h p m c s) method path body statusCheck = do let request = def { HC.host = h, HC.port = p, HC.path = path, HC.method = method, HC.requestBody = HC.RequestBodyLBS body,+ HC.secure = s, HC.checkStatus = \s _ _ -> if statusCheck s then Nothing else Just (toException $ Neo4jUnexpectedResponseException s),
src/Database/Neo4j/Types.hs view
@@ -327,6 +327,7 @@ ,dbPort :: Port ,manager :: HC.Manager ,dbCredentials :: Maybe Credentials+ ,dbSecure :: Bool } type Hostname = S.ByteString