Revision d79a6502 src/Ganeti/Luxi.hs

b/src/Ganeti/Luxi.hs
45 45
  , queryJobsStatus
46 46
  , buildCall
47 47
  , buildResponse
48
  , validateCall
49
  , decodeCall
48
  , decodeLuxiCall
50 49
  , recvMsg
51 50
  , recvMsgExt
52 51
  , sendMsg
......
55 54

  
56 55
import Control.Monad
57 56
import qualified Data.ByteString.UTF8 as UTF8
58
import Data.Functor ((<$>))
59 57
import Text.JSON (encodeStrict, decodeStrict)
60 58
import qualified Text.JSON as J
61 59
import Text.JSON.Pretty (pp_value)
......
170 168
-- | The serialisation of LuxiOps into strings in messages.
171 169
$(genStrOfOp ''LuxiOp "strOfOp")
172 170

  
173
-- | Type holding the initial (unparsed) Luxi call.
174
data LuxiCall = LuxiCall LuxiReq JSValue
175 171

  
176 172
luxiConnectConfig :: ConnectConfig
177 173
luxiConnectConfig = ConnectConfig { connDaemon = GanetiLuxid
......
198 194
      jo = toJSObject ja
199 195
  in encodeStrict jo
200 196

  
201
-- | Check that luxi request contains the required keys and parse it.
202
validateCall :: String -> Result LuxiCall
203
validateCall s = uncurry LuxiCall <$> parseCall s
204 197

  
205 198
-- | Converts Luxi call arguments into a 'LuxiOp' data structure.
199
-- This is used for building a Luxi 'Handler'.
206 200
--
207 201
-- This is currently hand-coded until we make it more uniform so that
208 202
-- it can be generated using TH.
209
decodeCall :: LuxiCall -> Result LuxiOp
210
decodeCall (LuxiCall call args) =
203
decodeLuxiCall :: JSValue -> JSValue -> Result LuxiOp
204
decodeLuxiCall method args = do
205
  call <- fromJResult "Unable to parse LUXI request method" $ J.readJSON method
211 206
  case call of
212 207
    ReqQueryJobs -> do
213 208
              (jids, jargs) <- fromJVal args

Also available in: Unified diff