Commit 3f4ce3f2 authored by Andreas Boysen's avatar Andreas Boysen Committed by Benny Baumann
Browse files

addet get by id for CryptoKeyMeta and CrytoKoyAttributes WARNING: This commit is untestet

parent 6b42f9e8
Branches newDB
No related merge requests found
Showing with 110 additions and 31 deletions
......@@ -18,7 +18,23 @@ cabal-version: >=1.10
executable KeyInfoService
main-is: kishttp.hs
-- other-modules:
other-modules: Control.Monad.ERIO,
Control.Monad.ERIO.IO,
CryptoKey,
DB.Hasql.Connection.ERIO,
DB.Hasql.Decoders.ERIO,
DB.Hasql.Encoders.ERIO,
DB.Hasql.Query.ERIO,
DB.Hasql.Session.ERIO,
DBConfig,
DBConstructor,
DBTypes,
DBapi,
KeyDB,
ParseWeb,
Parser.ASN1,
Parser.KeyData,
Parser.Parser
-- other-extensions:
build-depends:
base >=4.8,
......@@ -50,7 +66,8 @@ executable KeyInfoService
postgresql-libpq,
contravariant,
profunctors,
vector
vector,
convertible
hs-source-dirs: src
default-language: Haskell2010
......
......@@ -54,15 +54,29 @@ withTestConn = HC.acquire credentials
-- GetBy functionen
class GetByID a where
getByID :: Query (ID a) (Maybe a)
class GetById a where
getById :: Query (Id a) (Maybe a)
instance GetByID CryptoKey where
getByID = HQ.statement q1s q1p qr_CryptoKey True
instance GetById CryptoKey where
getById = HQ.statement q1s q1p qr_CryptoKey True
where
q1s = "SELECT * FROM crypto_key WHERE id = $1"
q1p = contramap getID (HE.value HE.int8)
instance GetById CryptoKeyAttributes where
getById = HQ.statement q1s q1p qr_CryptoKeyAttribute True
where
q1s = "SELECT * FROM crypto_key_attributes WHERE id = $1"
q1p = contramap getID (HE.value HE.int8)
instance GetById CryptoKeyMeta where
getById = HQ.statement q1s q1p qr_CryptoKeyMeta True
where
q1s = "SELECT * FROM crypto_key_Meta WHERE id = $1"
q1p = contramap getID (HE.value HE.int8)
-- Result Parser
-- crypto_key
qr_CryptoKey =
HD.maybeRow $ CryptoKey <$>
HD.value HD.int8 <*>
......@@ -95,6 +109,34 @@ qr_CryptoKeys =
HD.value HD.bytea <*>
HD.nullableValue HD.bytea
-- CryptoKeyAttributes
qr_CryptoKeyAttribute_h =CryptoKeyAttributes <$>
HD.value HD.int8 <*>
HD.value (fmap (Left . Id) HD.int8) <*>
HD.value HD.text <*>
HD.value HD.int8 <*>
HD.value HD.bytea
qr_CryptoKeyAttribute =
HD.maybeRow qr_CryptoKeyAttribute_h
qr_CryptoKeyAttributes =
HD.rowsVector qr_CryptoKeyAttribute_h
-- CryptoKeyMeta
qr_CryptoKeyMeta_h =CryptoKeyMeta <$>
HD.value HD.int8 <*>
HD.value (fmap (Left . Id) HD.int8) <*>
HD.value HD.text <*>
HD.value HD.int8 <*>
HD.value HD.bytea
qr_CryptoKeyMeta =
HD.maybeRow qr_CryptoKeyMeta_h
qr_CryptoKeyMetas =
HD.rowsVector qr_CryptoKeyMeta_h
-- Request
getBySearch :: (SearchRequest, Int, Int) -> Query (SearchRequest, Int, Int) (Vector CryptoKey)
......
{-# LANGUAGE FlexibleContexts#-}
module DBTypes where
import Data.ByteString
import Data.Int
import Data.Text
import Data.Convertible.Instances.Num
import Data.Convertible
-- State of the row ::
data ID a = ID { getID :: Int64 }
data Id a = Id { getID :: Int64 }
deriving (Show, Read)
newId :: Convertible n Int64 =>
n -> Id a
newId n = Id { getID = convert n }
-- example usage : ((newId 42):: Id CryptoKey )
-- class FromRaw a b where
-- genFromRaw :: a -> [b]
......@@ -41,36 +49,42 @@ data NewCryptoKey = NewCryptoKey {
deriving Show
data CryptoKeyAttributes =
CryptoKeyAttributesByID Int64 |
CryptoKeyAttributesRaw {
CryptoKeyAttributes {
cka_id :: Int64,
cka_key :: CryptoKey,
cka_name :: ByteString,
cka_key :: Either (Id CryptoKey) CryptoKey,
cka_name :: Text,
cka_order :: Int64,
cka_value :: ByteString
} |
CryptoKeyAttributesNew {
new_cka_key :: CryptoKey,
new_cka_name :: ByteString,
}
deriving Show
data NewCryptoKeyAttributes =
NewCryptoKeyAttributes {
new_cka_key :: Either (Id CryptoKey) CryptoKey,
new_cka_name :: Text,
new_cka_order :: Int32,
new_cka_value :: ByteString
}
deriving Show
data CryptoKeyMeta =
CryptoKeyMetaByID Int64 |
CryptoKeyMetasRaw {
CryptoKeyMeta {
ckm_id :: Int64,
ckm_key :: CryptoKey,
ckm_name :: ByteString,
ckm_key :: Either (Id CryptoKey) CryptoKey,
ckm_name :: Text,
ckm_order :: Int64,
ckm_value :: ByteString
} |
CryptoKeyMetaNew {
new_ckm_key :: CryptoKey,
new_ckm_name :: ByteString,
}
deriving Show
data NewCryptoKeyMeta =
NewCryptoKeyMeta {
new_ckm_key :: Either (Id CryptoKey) CryptoKey,
new_ckm_name :: Text,
new_ckm_order :: Int32,
new_ckm_value :: ByteString
}
deriving Show
-- Fingerprint types and Smart Constructors
......
......@@ -36,14 +36,20 @@ search r sn nn = do
(Left e) -> error $ "Something went wrong (2)" ++ show e
(Right erg) -> return erg
-- tests
testSearch :: IO ()
testSearch = do
e <- search (Not (FV_id 7)) 0 100
print e
byHash :: ByteString -> IO [CryptoKey]
byHash s = do
res <- liftIO $ search (Is $ FV_sha3_512 s) 0 1024
return $ toList res
-- count variante aller anfragen.
byId :: GetById a => Id a -> IO (Maybe a)
byId ident = do
-- ERIO stack iniizialisiren
(_, e) <- evalERIO' Nil $ do
withTestConn $ do
HS.run $ HS.query ident (getById)
case e of
(Left e) -> error "Something went wrong (1)"
(Right er) -> case er of
(Left e) -> error $ "Something went wrong (2)" ++ show e
(Right erg) -> return erg
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment