aboutsummaryrefslogtreecommitdiff
path: root/src/Sproxy/Server/DB/DataFile.hs
blob: efac923a8efc52a61eaef60b95df6ea2933c2f42 (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
58
59
60
61
62
63
64
65
66
67
68
69
{-# LANGUAGE OverloadedStrings #-}
module Sproxy.Server.DB.DataFile (
  DataFile(..)
, GroupMember(..)
, GroupPrivilege(..)
, PrivilegeRule(..)
) where

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


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