diff --git a/libs/wire-api/src/Wire/API/Routes/Public/Brig.hs b/libs/wire-api/src/Wire/API/Routes/Public/Brig.hs index d377fc79835..53e0622c32e 100644 --- a/libs/wire-api/src/Wire/API/Routes/Public/Brig.hs +++ b/libs/wire-api/src/Wire/API/Routes/Public/Brig.hs @@ -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 @@ -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) @@ -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 diff --git a/libs/wire-api/src/Wire/API/Routes/Public/Cannon.hs b/libs/wire-api/src/Wire/API/Routes/Public/Cannon.hs index d688916836a..eda1f01a8e3 100644 --- a/libs/wire-api/src/Wire/API/Routes/Public/Cannon.hs +++ b/libs/wire-api/src/Wire/API/Routes/Public/Cannon.hs @@ -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) @@ -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 diff --git a/libs/wire-subsystems/src/Wire/ServerOptions/Cannon.hs b/libs/wire-subsystems/src/Wire/ServerOptions/Cannon.hs index e45f598503d..d25fb678b76 100644 --- a/libs/wire-subsystems/src/Wire/ServerOptions/Cannon.hs +++ b/libs/wire-subsystems/src/Wire/ServerOptions/Cannon.hs @@ -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 @@ -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 diff --git a/services/brig/src/Brig/API/Public.hs b/services/brig/src/Brig/API/Public.hs index 6580a413959..8e7ed332577 100644 --- a/services/brig/src/Brig/API/Public.hs +++ b/services/brig/src/Brig/API/Public.hs @@ -20,8 +20,8 @@ module Brig.API.Public ( servantSitemap, - docsAPI, - DocsAPI, + docsAndOptionsAPI, + DocsAndOptionsAPI, ) where @@ -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 @@ -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 () @@ -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 @@ -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 diff --git a/services/brig/src/Brig/Run.hs b/services/brig/src/Brig/Run.hs index 2bd43d585e1..cc911ec5aeb 100644 --- a/services/brig/src/Brig/Run.hs +++ b/services/brig/src/Brig/Run.hs @@ -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 @@ -159,7 +159,7 @@ internalHandleCompatibilityMiddleware app req k = k type ServantCombinedAPI = - ( DocsAPI + ( DocsAndOptionsAPI :<|> BrigAPI :<|> IAPI.API :<|> FederationAPI diff --git a/services/cannon/cannon.cabal b/services/cannon/cannon.cabal index bcf04e1deb8..425862a0161 100644 --- a/services/cannon/cannon.cabal +++ b/services/cannon/cannon.cabal @@ -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 @@ -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 diff --git a/services/cannon/default.nix b/services/cannon/default.nix index 5d4750f10d4..3cfa4b0816c 100644 --- a/services/cannon/default.nix +++ b/services/cannon/default.nix @@ -10,7 +10,6 @@ , bytestring , bytestring-conversion , conduit -, containers , criterion , data-timeout , exceptions @@ -27,13 +26,11 @@ , lib , metrics-wai , mwc-random -, openapi3 , prometheus-client , QuickCheck , random , retry , safe-exceptions -, schema-profunctor , servant-conduit , servant-server , strict @@ -70,7 +67,6 @@ mkDerivation { bytestring bytestring-conversion conduit - containers data-timeout exceptions extended @@ -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 diff --git a/services/cannon/src/Cannon/API/Public.hs b/services/cannon/src/Cannon/API/Public.hs index 7490c58acd5..4a559f9f17c 100644 --- a/services/cannon/src/Cannon/API/Public.hs +++ b/services/cannon/src/Cannon/API/Public.hs @@ -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