packages feed

cruncher-types (empty) → 1.0.0

raw patch · 7 files changed

+228/−0 lines, 7 filesdep +aesondep +basedep +bytestringsetup-changed

Dependencies added: aeson, base, bytestring, containers, hlint, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Ricky Elrod++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Ricky Elrod nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ cruncher-types.cabal view
@@ -0,0 +1,45 @@+name:                cruncher-types+version:             1.0.0+synopsis:            Request and Response types for Eval.so's API+description:+  You are not likely to find this useful unless you are building a library for+  accessing Eval.so's new API, or working on the "Cruncher" backend.+homepage:            http://github.com/eval-so/cruncher-types+license:             BSD3+license-file:        LICENSE+author:              Ricky Elrod+maintainer:          ricky@elrod.me+copyright:           2013 - Ricky Elrod+category:            Eval.so+build-type:          Simple+cabal-version:       >=1.18++library+  exposed-modules:+    Evalso.Cruncher.FinalResult+    Evalso.Cruncher.SandboxResult+    Evalso.Cruncher.Request++  ghc-options: -Wall -O2+  hs-source-dirs: src+  default-language:    Haskell2010++  build-depends:+      base ==4.6.*+    , bytestring ==0.10.*+    , containers ==0.5.*+    , text ==0.11.*+    , aeson ==0.6.*++test-suite hlint+  hs-source-dirs: tests+  main-is: hlint.hs+  type: exitcode-stdio-1.0+  ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base+    , hlint >= 1.7++source-repository head+  type:     git+  location: git://github.com/eval-so/cruncher-types.git
+ src/Evalso/Cruncher/FinalResult.hs view
@@ -0,0 +1,63 @@+{-# LANGUAGE OverloadedStrings, Trustworthy #-}+-- |+-- Maintainer  : Ricky Elrod <ricky@elrod.me>+-- Stability   : stable+--+-- The highest level of a response that Cruncher deals with. Contains only the+-- final result of a sandbox run, including compilation, execution, and output+-- files (which are base64-encoded).++module Evalso.Cruncher.FinalResult (FinalResult (..)) where++import Evalso.Cruncher.SandboxResult++import Control.Applicative+import Control.Monad (mzero)+import Data.Aeson+import Data.ByteString (ByteString)+import Data.Map (Map)++-- | The final result for a given request.+--+--   This contains the 'Result' obtained from both evaluation and compilation+--   as well as any files which resulted from performing the above steps.+--   Such files should placed in @~/output/@ of the evaluation.+--+--   This data type also handles error handling, in the form of types.+data FinalResult+  = FinalResult+    {+      compile     :: Maybe SandboxResult -- ^ The compilation result, if any+    , run         :: Maybe SandboxResult -- ^ The execution result, if any+    , outputFiles :: Map String ByteString -- ^ Base64-encoded output files+    }+  | NoSuchLanguage+  | SELinuxNotEnforcing+  deriving (Eq, Show)++instance ToJSON FinalResult where+  toJSON (FinalResult compile' run' outputFiles') = object+    [+      "compile"     .= compile'+    , "run"         .= run'+    , "outputFiles" .= outputFiles'+    ]++  -- | TODO: i18n+  toJSON (NoSuchLanguage) = object ["error" .= noSuchLanguageError]+    where+      noSuchLanguageError :: String+      noSuchLanguageError = "We do not currently support that language"++  -- | TODO: i18n+  toJSON (SELinuxNotEnforcing) = object ["error" .= selinuxError]+    where+      selinuxError :: String+      selinuxError = "Internal security error - halting request"++instance FromJSON FinalResult where+  parseJSON (Object v) = FinalResult <$>+                             v .: "compile"+                         <*> v .: "run"+                         <*> v .: "outputFiles"+  parseJSON _          = mzero
+ src/Evalso/Cruncher/Request.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE OverloadedStrings, Trustworthy #-}+-- |+-- Maintainer  : Ricky Elrod <ricky@elrod.me>+-- Stability   : stable+--+-- Handles incoming requests (usually from our Yesod frontend, but could be+-- from anywhere).++module Evalso.Cruncher.Request (Request (..)) where++import Control.Applicative+import Control.Monad (mzero)+import Data.Aeson hiding (Result)+import qualified Data.ByteString.Char8 as C8+import qualified Data.Text as T++-- | Describes an incoming request to the system. Proper use of this will+--   normally lead to some kind of a 'IO' 'Result'.+data Request = Request {+    language    :: String+  , code        :: T.Text+  , files       :: Maybe [(String, C8.ByteString)]+  , compileOnly :: Bool+  , stdin       :: Maybe T.Text+} deriving (Eq, Show)++instance FromJSON Request where+  parseJSON (Object v) = Request <$>+                             v .:  "language"+                         <*> v .:  "code"+                         <*> v .:? "inputFiles"+                         <*> v .:? "compilationOnly" .!= False+                         <*> v .:? "stdin"+  parseJSON _          = mzero
+ src/Evalso/Cruncher/SandboxResult.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE OverloadedStrings, Trustworthy #-}+-- |+-- Maintainer  : Ricky Elrod <ricky@elrod.me>+-- Stability   : stable+--+-- Contains data types/constructors for individual sandbox runs.+-- For example, the compile step will produce a 'SandboxResult', which is+-- defined in this module. The execution/evaluation step will also produce a+-- 'SandboxResult'.++module Evalso.Cruncher.SandboxResult (SandboxResult (..)) where++import Control.Applicative+import Control.Monad (mzero)+import Data.Aeson hiding (Result)+import Data.Text (Text)++-- | Describes the result we get back after performing an evaluation (or+--   compilation). This is almost always wrapped in 'IO'.+data SandboxResult = SandboxResult {+    stdout   :: Text+  , stderr   :: Text+  , wallTime :: Int+  , exitCode :: Int+} deriving (Eq, Show)++instance ToJSON SandboxResult where+  toJSON (SandboxResult stdout' stderr' wallTime' exitCode') = object+    [+      "stdout"   .= stdout'+    , "stderr"   .= stderr'+    , "wallTime" .= wallTime'+    , "exitCode" .= exitCode'+    ]++instance FromJSON SandboxResult where+  parseJSON (Object v) = SandboxResult <$>+                             v .: "stdout"+                         <*> v .: "stderr"+                         <*> v .: "wallTime"+                         <*> v .: "exitCode"+  parseJSON _          = mzero
+ tests/hlint.hs view
@@ -0,0 +1,12 @@+module Main where++import Control.Monad+import Language.Haskell.HLint+import System.Environment+import System.Exit++main :: IO ()+main = do+  args <- getArgs+  hints <- hlint $ ["src", "--cpp-define=HLINT", "--cpp-ansi"] ++ args+  unless (null hints) exitFailure