aboutsummaryrefslogtreecommitdiff
path: root/src/Sproxy/Server/DB/DataFile.hs
blob: 850e283379141b64c1a4d973a9d63ed73b38d2b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE OverloadedStrings #-}

module Sproxy.Server.DB.DataFile
  ( DataFile(..)
  , GroupMember(..)
  , GroupPrivilege(..)
  , PrivilegeRule(..)
  ) where

import Control.Applicative (empty)
import Data.Aeson (FromJSON, Value(Object), (.:), parseJSON)
import Data.Text (Text)

data DataFile = DataFile
  { groupMember :: [GroupMember]
  , groupPrivilege :: [GroupPrivilege]
  , privilegeRule :: [PrivilegeRule]
  } deriving (Show)

instance FromJSON DataFile where
  parseJSON (Object m) =
    DataFile <$> m .: "group_member" <*> m .: "group_privilege" <*>
    m .: "privilege_rule"
  parseJSON _ = empty

data GroupMember = GroupMember
  { gmGroup :: Text
  , gmEmail :: Text
  } deriving (Show)

instance FromJSON GroupMember where
  parseJSON (Object m) = GroupMember <$> m .: "group" <*> m .: "email"
  parseJSON _ = empty

data GroupPrivilege = GroupPrivilege
  { gpGroup :: Text
  , gpDomain :: Text
  , gpPrivilege :: Text
  } deriving (Show)

instance FromJSON GroupPrivilege where
  parseJSON (Object m) =
    GroupPrivilege <$> m .: "group" <*> m .: "domain" <*> m .: "privilege"
  parseJSON _ = empty

data PrivilegeRule = PrivilegeRule
  { prDomain :: Text
  , prPrivilege :: Text
  , prPath :: Text
  , prMethod :: Text
  } deriving (Show)

instance FromJSON PrivilegeRule where
  parseJSON (Object m) =
    PrivilegeRule <$> m .: "domain" <*> m .: "privilege" <*> m .: "path" <*>
    m .: "method"
  parseJSON _ = empty