packages feed

haskell-admin-managed-functions (empty) → 1.0.0.0

raw patch · 8 files changed

+173/−0 lines, 8 filesdep +basedep +haskell-admin-coredep +haskell-admin-managed-functionssetup-changed

Dependencies added: base, haskell-admin-core, haskell-admin-managed-functions, hspec, hspec-wai, managed-functions, managed-functions-http-connector, servant-server

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for haskell-admin-managed-functions++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright Martin Bednar (c) 2022++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,9 @@+# haskell-admin-managed-functions++A server component integrating [Managed Functions](https://github.com/martin-bednar/managed-functions) into [Haskell Admin](https://github.com/martin-bednar/haskell-admin).++This component can be used to define custom management tasks and easily run selected functions on the server side.++## Usage ++TBD
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ haskell-admin-managed-functions.cabal view
@@ -0,0 +1,62 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.4.+--+-- see: https://github.com/sol/hpack++name:           haskell-admin-managed-functions+version:        1.0.0.0+synopsis:       Managed Functions integration for Haskell Admin+description:    Please see the README on GitHub at <https://github.com/martin-bednar/haskell-admin#readme>+category:       Haskell Admin, Managed Functions, Remote Management+homepage:       https://github.com/martin-bednar/haskell-admin#readme+bug-reports:    https://github.com/martin-bednar/haskell-admin/issues+author:         Martin Bednar+maintainer:     bednam17@fit.cvut.cz+copyright:      2022 Martin Bednar+license:        MIT+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/martin-bednar/haskell-admin++library+  exposed-modules:+      Admin.Component.Managed+  other-modules:+      Paths_haskell_admin_managed_functions+  hs-source-dirs:+      src+  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints+  build-depends:+      base >=4.7 && <5+    , haskell-admin-core+    , managed-functions+    , managed-functions-http-connector+    , servant-server+  default-language: Haskell2010++test-suite haskell-admin-managed-functions-test+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Spec.Admin.Component.Managed+      Paths_haskell_admin_managed_functions+  hs-source-dirs:+      test+  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.7 && <5+    , haskell-admin-core+    , haskell-admin-managed-functions+    , hspec+    , hspec-wai+    , managed-functions+    , managed-functions-http-connector+    , servant-server+  default-language: Haskell2010
+ src/Admin/Component/Managed.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE DataKinds #-}++module Admin.Component.Managed+  ( ManagedAPI+  , ManagedComponent+  , managed+  , serveManaged+  , module Managed+  ) where++import Admin.Components+import Data.Version (makeVersion)+import Managed+import Managed.Connectors.HTTPConnector+import Servant++type ManagedAPI = HTTPConnectorAPI++type ManagedComponent = Component "managed" ManagedAPI++managed :: Agent SR -> ManagedComponent+managed agent =+  Component {server = serveManaged agent, version = makeVersion [1]}++serveManaged :: Agent SR -> Server ManagedAPI+serveManaged = httpConnectorServer
+ test/Spec.hs view
@@ -0,0 +1,11 @@+module Main where++import Test.Hspec++import qualified Spec.Admin.Component.Managed++main :: IO ()+main = hspec spec++spec :: Spec+spec = describe "Spec.Admin.Component.Managed" Spec.Admin.Component.Managed.spec
+ test/Spec/Admin/Component/Managed.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeApplications #-}++module Spec.Admin.Component.Managed+  ( spec+  ) where++import Admin.Component.Managed hiding (describe)+import Servant+import Test.Hspec+import Test.Hspec.Wai++app :: IO Application+app = do+  let ag = fromList [("plusOne", toProbe ((+ 1) :: Int -> Int))]+  return $ serve (Proxy @ManagedAPI) $ serveManaged ag++spec :: Spec+spec =+  with app $ do+    describe "GET /probes" $ do+      it "lists probes" $ do+        get "/probes" `shouldRespondWith` 200 {matchBody = "[\"plusOne\"]"}+    describe "GET /probes/plusOne" $ do+      it "describes a probe" $ do+        get "/probes/plusOne" `shouldRespondWith`+          200+            { matchBody =+                "{\"probeID\":\"plusOne\",\"probeParams\":[\"Int\"],\"probeReturns\":\"Int\",\"probeType\":\"Int -> Int\"}"+            }+    describe "POST /probes/plusOne/invoke" $ do+      it "invokes a probe" $+        do request+             "POST"+             "/probes/plusOne/invoke"+             [("content-type", "application/json")]+             "[\"3\"]"+           `shouldRespondWith` 200 {matchBody = "\"4\""}