Permalink
Browse files

security api

Signed-off-by: Alexander Dorofeev <aka.spin@gmail.com>
  • Loading branch information...
1 parent 54939c3 commit 91ec0f540b2a0dff4f4a4b93f4f99d13f2aa2818 @akaspin committed Jan 24, 2012
Showing with 23 additions and 22 deletions.
  1. +1 −1 ChangeLog
  2. +22 −21 src/Database/CouchDB/Conduit/DB.hs
View
@@ -1,4 +1,4 @@
- 24.01.2011, Version 0.4.0 * Detailed error type. * Throw exception on `304`. * Database API lost db argument. * `couchViewPut*` -> `couchPutView` 22.01.2011, Version 0.3.0.1 * Constraints in cabal 19.01.2011, Version 0.3.0.0 * Fix for new http-conduit types 16.01.2011, Version 0.2.1.1 * Fixes for couchViewPut and couchSecureDB. 16.01.2011, Version 0.2.1 * Secure DB. 16.01.2011, Version 0.2.0.1 * Avoid escaping path in couch' 16.01.2011, Version 0.2.0 * Low-lewel API * "Don't care" versions of couchPut. * Brain-free couchRev'. * All database methods ignores DB in connection. * couchPutDB' renamed to couchPutDB_. * Database replication. 14.01.2011, Version 0.1.3.0 * Safe version of couchViewPut 14.01.2011, Version 0.1.2.0 * Authentification 11.01.2011, Version 0.1.1.0
+ 24.01.2011, Version 0.4.1 * `couchSecureDB` lost db argument. 24.01.2011, Version 0.4.0 * Detailed error type. * Throw exception on `304`. * Database API lost db argument. * `couchViewPut*` -> `couchPutView` 22.01.2011, Version 0.3.0.1 * Constraints in cabal 19.01.2011, Version 0.3.0.0 * Fix for new http-conduit types 16.01.2011, Version 0.2.1.1 * Fixes for couchViewPut and couchSecureDB. 16.01.2011, Version 0.2.1 * Secure DB. 16.01.2011, Version 0.2.0.1 * Avoid escaping path in couch' 16.01.2011, Version 0.2.0 * Low-lewel API * "Don't care" versions of couchPut. * Brain-free couchRev'. * All database methods ignores DB in connection. * couchPutDB' renamed to couchPutDB_. * Database replication. 14.01.2011, Version 0.1.3.0 * Safe version of couchViewPut 14.01.2011, Version 0.1.2.0 * Authentification 11.01.2011, Version 0.1.1.0
* API Changes. `couchViewPut` moved to Database.CouchDB.Design and lost
language argument.
* Tests. 10.01.2011, Version 0.1.0.1
@@ -12,10 +12,10 @@ module Database.CouchDB.Conduit.DB (
couchPutDB,
couchPutDB_,
couchDeleteDB,
- -- * Replication
- couchReplicateDB,
-- * Security
- couchSecureDB
+ couchSecureDB,
+ -- * Replication
+ couchReplicateDB
) where
import qualified Data.ByteString as B
@@ -26,7 +26,7 @@ import Data.Conduit (ResourceT)
import qualified Network.HTTP.Conduit as H
import qualified Network.HTTP.Types as HT
-import Database.CouchDB.Conduit (MonadCouch(..), Path)
+import Database.CouchDB.Conduit (MonadCouch(..))
import Database.CouchDB.Conduit.LowLevel (couch, protect, protect')
@@ -50,6 +50,24 @@ couchDeleteDB = couch HT.methodDelete id [] []
(H.RequestBodyBS B.empty) protect'
>> return ()
+-- | Maintain DB security.
+couchSecureDB :: MonadCouch m =>
+ [B.ByteString] -- ^ Admin roles
+ -> [B.ByteString] -- ^ Admin names
+ -> [B.ByteString] -- ^ Readers roles
+ -> [B.ByteString] -- ^ Readers names
+ -> ResourceT m ()
+couchSecureDB adminRoles adminNames readersRoles readersNames =
+ couch HT.methodPut (`B.append` "/_security") [] []
+ reqBody protect'
+ >> return ()
+ where
+ reqBody = H.RequestBodyLBS $ A.encode $ A.object [
+ "admins" A..= A.object [ "roles" A..= adminRoles,
+ "names" A..= adminNames ],
+ "readers" A..= A.object [ "roles" A..= readersRoles,
+ "names" A..= readersNames ] ]
+
-- | Database replication.
--
-- See <http://guide.couchdb.org/editions/1/en/api.html#replication> for
@@ -73,23 +91,6 @@ couchReplicateDB source target createTarget continuous cancel =
"continuous" A..= continuous,
"cancel" A..= cancel ]
-couchSecureDB :: MonadCouch m =>
- Path -- ^ Database
- -> [B.ByteString] -- ^ Admin roles
- -> [B.ByteString] -- ^ Admin names
- -> [B.ByteString] -- ^ Readers roles
- -> [B.ByteString] -- ^ Readers names
- -> ResourceT m ()
-couchSecureDB p adminRoles adminNames readersRoles readersNames =
- couch HT.methodPut (const $ p `B.append` "/_security") [] []
- reqBody protect'
- >> return ()
- where
- reqBody = H.RequestBodyLBS $ A.encode $ A.object [
- "admins" A..= A.object [ "roles" A..= adminRoles,
- "names" A..= adminNames ],
- "readers" A..= A.object [ "roles" A..= readersRoles,
- "names" A..= readersNames ] ]

0 comments on commit 91ec0f5

Please sign in to comment.