Skip to content

Commit

Permalink
Mv public endpoint for config options schemas from cannon to brig.
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Nov 4, 2024
1 parent 3254618 commit 7978547
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 44 deletions.
17 changes: 17 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Public/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Data.CommaSeparatedList (CommaSeparatedList)
import Data.Domain
import Data.Handle
import Data.Id as Id
import Data.Json.Util
import Data.Nonce (Nonce)
import Data.OpenApi hiding (Contact, Header, Schema, ToSchema)
import Data.OpenApi qualified as S
Expand All @@ -39,6 +40,7 @@ import Imports hiding (head)
import Network.Wai.Utilities
import Servant (JSON)
import Servant hiding (Handler, JSON, addHeader, respond)
import Servant.API.Extended
import Servant.OpenApi.Internal.Orphans ()
import Wire.API.Call.Config (RTCConfiguration)
import Wire.API.Connection hiding (MissingLegalholdConsent)
Expand Down Expand Up @@ -80,6 +82,21 @@ import Wire.API.User.RichInfo (RichInfoAssocList)
import Wire.API.User.Search (Contact, PagingState, RoleFilter, SearchResult, TeamContact, TeamUserSearchSortBy, TeamUserSearchSortOrder)
import Wire.API.UserMap

----------------------------------------------------------------------

type ServerOptionsDocsAPI =
Named
"server-config-options"
( Summary "JSON schema of the server config yaml file(s)."
:> Description
"returns a JSON (or YAML) object with one JSON schema for each \
\backend service (brig, gundeck, ...)."
:> "server-config-options"
:> Get '[JSON, YAML] JsonObject
)

----------------------------------------------------------------------

type BrigAPI =
UserAPI
:<|> SelfAPI
Expand Down
8 changes: 0 additions & 8 deletions libs/wire-api/src/Wire/API/Routes/Public/Cannon.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
module Wire.API.Routes.Public.Cannon where

import Data.Id
import Data.Json.Util
import Servant
import Servant.API.Extended
import Wire.API.Routes.API
import Wire.API.Routes.Named
import Wire.API.Routes.Public (ZConn, ZUser)
Expand All @@ -43,12 +41,6 @@ type CannonAPI =
-- FUTUREWORK: Consider higher-level web socket combinator
:> WebSocketPending
)
:<|> Named
"config-options-cannon"
( Summary "Establish websocket connection"
:> "config-options-cannon"
:> Get '[JSON, YAML] JsonObject
)

data CannonAPITag

Expand Down
16 changes: 0 additions & 16 deletions libs/wire-subsystems/src/Wire/ServerOptions/Cannon.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@ module Wire.ServerOptions.Cannon
minBatchSize,
disabledAPIVersions,
DrainOpts,
optsSchema,
)
where

import Control.Lens (makeFields)
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as A
import Data.Json.Util
import Data.OpenApi qualified as O
import Data.OpenApi.Declare qualified as O
import Data.Proxy (Proxy (Proxy))
import Data.Schema
import Data.Set qualified as Set
import Imports
Expand Down Expand Up @@ -138,14 +133,3 @@ instance ToSchema Opts where
<*> (Set.toList . _optsDisabledAPIVersions) .= field "disabledAPIVersions" (Set.fromList <$> array schema)

makeFields ''Opts

optsSchema :: JsonObject
optsSchema = case A.toJSON r of
A.Object obj -> JsonObject obj
other -> JsonObject (A.singleton "value" other)
where
d :: O.Declare (O.Definitions O.Schema) O.Schema
d = O.declareSchema (Proxy @Opts)

r :: (O.Definitions O.Schema, O.Schema)
r = O.runDeclare d mempty
35 changes: 33 additions & 2 deletions services/brig/src/Brig/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

module Brig.API.Public
( servantSitemap,
docsAPI,
DocsAPI,
docsAndOptionsAPI,
DocsAndOptionsAPI,
)
where

Expand Down Expand Up @@ -61,6 +61,7 @@ import Control.Lens ((.~), (?~))
import Control.Monad.Catch (throwM)
import Control.Monad.Except
import Data.Aeson hiding (json)
import Data.Aeson.Types qualified as A
import Data.ByteString (fromStrict, toStrict)
import Data.ByteString.Lazy.Char8 qualified as LBS
import Data.ByteString.UTF8 qualified as UTF8
Expand All @@ -74,10 +75,12 @@ import Data.Handle qualified as Handle
import Data.HavePendingInvitations
import Data.Id
import Data.Id qualified as Id
import Data.Json.Util
import Data.List.NonEmpty (nonEmpty)
import Data.Map.Strict qualified as Map
import Data.Nonce (Nonce, randomNonce)
import Data.OpenApi qualified as S
import Data.OpenApi.Declare qualified as S
import Data.Qualified
import Data.Range
import Data.Schema ()
Expand Down Expand Up @@ -168,6 +171,7 @@ import Wire.Sem.Concurrency
import Wire.Sem.Jwk (Jwk)
import Wire.Sem.Now (Now)
import Wire.Sem.Paging.Cassandra
import Wire.ServerOptions.Cannon qualified
import Wire.TeamInvitationSubsystem
import Wire.UserKeyStore
import Wire.UserSearch.Types
Expand All @@ -182,6 +186,33 @@ import Wire.VerificationCodeSubsystem

-- User API -----------------------------------------------------------

type DocsAndOptionsAPI = DocsAPI :<|> ServerOptionsDocsAPI

docsAndOptionsAPI :: Servant.Server DocsAndOptionsAPI
docsAndOptionsAPI = docsAPI :<|> serverOptionsDocsAPI

-- TODO: write a test for this end-point!
serverOptionsDocsAPI :: Servant.Server ServerOptionsDocsAPI
serverOptionsDocsAPI = Named @"server-config-options" $ pure allOptsSchema
where
allOptsSchema =
mkJsonObject
( [ "brig" .= ("comping up!" :: Text), -- TODO
"galley" .= ("comping up!" :: Text), -- TODO
"spar" .= ("comping up!" :: Text), -- TODO
"gundeck" .= ("comping up!" :: Text), -- TODO
"cannon" .= describeOpts (Proxy @Wire.ServerOptions.Cannon.Opts),
"cargohold" .= ("comping up!" :: Text), -- TODO
"federator" .= ("comping up!" :: Text), -- TODO
"proxy" .= ("comping up!" :: Text), -- TODO
"background-worker" .= ("comping up!" :: Text) -- TODO
] ::
[A.Pair]
)

describeOpts :: (S.ToSchema a) => Proxy a -> A.Value
describeOpts prx = toJSON $ S.runDeclare (S.declareSchema prx) mempty

docsAPI :: Servant.Server DocsAPI
docsAPI =
versionedSwaggerDocsAPI
Expand Down
4 changes: 2 additions & 2 deletions services/brig/src/Brig/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ mkApp opts = do
Servant.serveWithContext
(Proxy @ServantCombinedAPI)
(customFormatters :. localDomain :. Servant.EmptyContext)
( docsAPI
( docsAndOptionsAPI
:<|> hoistServerWithDomain @BrigAPI (toServantHandler env) servantSitemap
:<|> hoistServerWithDomain @IAPI.API (toServantHandler env) IAPI.servantSitemap
:<|> hoistServerWithDomain @FederationAPI (toServantHandler env) federationSitemap
Expand All @@ -159,7 +159,7 @@ internalHandleCompatibilityMiddleware app req k =
k

type ServantCombinedAPI =
( DocsAPI
( DocsAndOptionsAPI
:<|> BrigAPI
:<|> IAPI.API
:<|> FederationAPI
Expand Down
6 changes: 0 additions & 6 deletions services/cannon/cannon.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ library
aeson >=2.0.1.0
, async >=2.0
, base >=4.6 && <5
, containers
, openapi3
, schema-profunctor
, bilge >=0.12
, bytestring >=0.10
, bytestring-conversion >=0.2
, conduit >=1.3.4.2
, containers
, data-timeout >=0.3
, exceptions >=0.6
, extended
Expand All @@ -101,11 +97,9 @@ library
, lens-family-core >=1.1
, metrics-wai >=0.4
, mwc-random >=0.13
, openapi3
, prometheus-client
, retry >=0.7
, safe-exceptions
, schema-profunctor
, servant-conduit
, servant-server
, strict >=0.3.2
Expand Down
6 changes: 0 additions & 6 deletions services/cannon/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
, bytestring
, bytestring-conversion
, conduit
, containers
, criterion
, data-timeout
, exceptions
Expand All @@ -27,13 +26,11 @@
, lib
, metrics-wai
, mwc-random
, openapi3
, prometheus-client
, QuickCheck
, random
, retry
, safe-exceptions
, schema-profunctor
, servant-conduit
, servant-server
, strict
Expand Down Expand Up @@ -70,7 +67,6 @@ mkDerivation {
bytestring
bytestring-conversion
conduit
containers
data-timeout
exceptions
extended
Expand All @@ -84,11 +80,9 @@ mkDerivation {
lens-family-core
metrics-wai
mwc-random
openapi3
prometheus-client
retry
safe-exceptions
schema-profunctor
servant-conduit
servant-server
strict
Expand Down
5 changes: 1 addition & 4 deletions services/cannon/src/Cannon/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import Network.WebSockets.Connection
import Servant
import Wire.API.Routes.Named
import Wire.API.Routes.Public.Cannon
import Wire.ServerOptions.Cannon (optsSchema)

publicAPIServer :: ServerT CannonAPI Cannon
publicAPIServer =
Named @"await-notifications" streamData
:<|> Named @"config-options-cannon" (pure optsSchema)
publicAPIServer = Named @"await-notifications" streamData

streamData :: UserId -> ConnId -> Maybe ClientId -> PendingConnection -> Cannon ()
streamData userId connId clientId con = do
Expand Down

0 comments on commit 7978547

Please sign in to comment.