From 84f2affd66a0ff3947b91a30308cb8e6a8ff7594 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 19 May 2022 22:05:02 +0200 Subject: surtr: ... --- .../spm/lib/Data/CaseInsensitive/Instances.hs | 19 ++++++++++ hosts/surtr/email/spm/lib/Data/UUID/Instances.hs | 18 ++++++++++ hosts/surtr/email/spm/lib/Spm.hs | 5 +++ hosts/surtr/email/spm/lib/Spm/Api.hs | 40 ++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 hosts/surtr/email/spm/lib/Data/CaseInsensitive/Instances.hs create mode 100644 hosts/surtr/email/spm/lib/Data/UUID/Instances.hs create mode 100644 hosts/surtr/email/spm/lib/Spm.hs create mode 100644 hosts/surtr/email/spm/lib/Spm/Api.hs (limited to 'hosts/surtr/email/spm/lib') diff --git a/hosts/surtr/email/spm/lib/Data/CaseInsensitive/Instances.hs b/hosts/surtr/email/spm/lib/Data/CaseInsensitive/Instances.hs new file mode 100644 index 00000000..56cba98a --- /dev/null +++ b/hosts/surtr/email/spm/lib/Data/CaseInsensitive/Instances.hs @@ -0,0 +1,19 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Data.CaseInsensitive.Instances () where + +import Prelude + +import Data.CaseInsensitive (CI) +import qualified Data.CaseInsensitive as CI + +import Servant.API.ContentTypes + +import Data.Aeson + + +instance MimeRender PlainText a => MimeRender PlainText (CI a) where + mimeRender p = mimeRender p . CI.original + +instance ToJSON a => ToJSON (CI a) where + toJSON = toJSON . CI.original diff --git a/hosts/surtr/email/spm/lib/Data/UUID/Instances.hs b/hosts/surtr/email/spm/lib/Data/UUID/Instances.hs new file mode 100644 index 00000000..335937d8 --- /dev/null +++ b/hosts/surtr/email/spm/lib/Data/UUID/Instances.hs @@ -0,0 +1,18 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Data.UUID.Instances () where + +import Prelude +import Data.UUID (UUID) +import qualified Data.UUID as UUID +import Servant.API.ContentTypes + + +instance MimeRender PlainText UUID where + mimeRender p = mimeRender p . UUID.toText + +instance MimeRender JSON UUID where + mimeRender p = mimeRender p . UUID.toText + +instance MimeRender OctetStream UUID where + mimeRender p = mimeRender p . UUID.toByteString diff --git a/hosts/surtr/email/spm/lib/Spm.hs b/hosts/surtr/email/spm/lib/Spm.hs new file mode 100644 index 00000000..c7f7dfe5 --- /dev/null +++ b/hosts/surtr/email/spm/lib/Spm.hs @@ -0,0 +1,5 @@ +module Spm + ( module Spm.Api + ) where + +import Spm.Api diff --git a/hosts/surtr/email/spm/lib/Spm/Api.hs b/hosts/surtr/email/spm/lib/Spm/Api.hs new file mode 100644 index 00000000..d9644222 --- /dev/null +++ b/hosts/surtr/email/spm/lib/Spm/Api.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE TemplateHaskell #-} + +module Spm.Api + ( SpmMailbox + , SpmApi, spmApi + ) where + +import Prelude + +import Servant.API + +import Data.Proxy (Proxy(..)) + +import Data.Text (Text) + +import GHC.Generics (Generic) +import Type.Reflection (Typeable) + +import Control.Lens.TH + +import Data.CaseInsensitive (CI) +import Data.CaseInsensitive.Instances () + +import Crypto.JOSE.JWK (JWKSet) + +import Data.UUID (UUID) +import Data.UUID.Instances () + + +newtype SpmMailbox = SpmMailbox { unSpmMailbox :: CI Text } + deriving stock (Eq, Ord, Read, Show, Generic, Typeable) + deriving newtype (MimeRender JSON, MimeRender PlainText) +makeWrapped ''SpmMailbox + +type SpmApi = "whoami" :> Get '[PlainText, JSON] SpmMailbox + :<|> ".well-known" :> "jwks.json" :> Get '[JSON] JWKSet + :<|> "instance-id" :> Get '[PlainText, JSON, OctetStream] UUID + +spmApi :: Proxy SpmApi +spmApi = Proxy -- cgit v1.2.3