Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5-internal/move-internal-endpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove servant-generic from internal endpoints and remove them from Swagger
24 changes: 24 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Internal/Cargohold.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.API.Routes.Internal.Cargohold where

import Servant
import Wire.API.Routes.MultiVerb

type InternalAPI =
"i" :> "status" :> MultiVerb 'GET '() '[RespondEmpty 200 "OK"] ()
29 changes: 29 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Internal/LegalHold.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify it under
-- the terms of the GNU Affero General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option) any
-- later version.
--
-- This program is distributed in the hope that it will be useful, but WITHOUT
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
-- details.
--
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Wire.API.Routes.Internal.LegalHold where

import Data.Id
import Servant.API hiding (Header)
import Wire.API.Team.Feature

type InternalLegalHoldAPI =
"i" :> "teams" :> Capture "tid" TeamId :> "legalhold"
:> Get '[JSON] (TeamFeatureStatus 'WithLockStatus 'TeamFeatureLegalHold)
:<|> "i" :> "teams" :> Capture "tid" TeamId :> "legalhold"
:> ReqBody '[JSON] (TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureLegalHold)
:> Put '[] NoContent
4 changes: 0 additions & 4 deletions libs/wire-api/src/Wire/API/Routes/Public/Cargohold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ type ServantAPI =
:<|> BaseAPIv3 'ProviderPrincipalTag
:<|> QualifiedAPI
:<|> LegacyAPI
:<|> InternalAPI

type BaseAPIv3 (tag :: PrincipalTag) =
( Summary "Upload an asset"
Expand Down Expand Up @@ -208,8 +207,5 @@ type LegacyAPI =
:> GetAsset
)

type InternalAPI =
"i" :> "status" :> MultiVerb 'GET '() '[RespondEmpty 200 "OK"] ()

swaggerDoc :: Swagger.Swagger
swaggerDoc = toSwagger (Proxy @ServantAPI)
99 changes: 51 additions & 48 deletions libs/wire-api/src/Wire/API/Routes/Public/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import Wire.API.Team.Conversation
import Wire.API.Team.Feature
import Wire.API.Team.Permission (Perm (..))

-- import Wire.API.Team.Permission (Perm (..))

instance AsHeaders '[ConvId] Conversation Conversation where
toHeaders c = (I (qUnqualified (cnvQualifiedId c)) :* Nil, c)
fromHeaders = snd
Expand Down Expand Up @@ -731,59 +729,64 @@ type FeatureAPI =
:<|> FeatureConfigGet 'WithLockStatus 'TeamFeatureSelfDeletingMessages
:<|> FeatureConfigGet 'WithLockStatus 'TeamFeatureGuestLinks

type FeatureStatusGet featureName =
type FeatureStatusGet f =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, no one-letter names :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you picking on this particular one? The codebase is full of one-letter names. Even for this very purpose (see e.g. Galley.API.Teams.Features). I'm actually not sure what the problem is with one-letter names when they stand for very abstract things in a very limited scope (e.g. a single expression, like in this example). Also, the name that was there before isn't even correctly describing what the variable stands for (it's not a "feature name").

Named
'("get", featureName)
( Summary (AppendSymbol "Get config for " (KnownTeamFeatureNameSymbol featureName))
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> KnownTeamFeatureNameSymbol featureName
:> Get '[Servant.JSON] (TeamFeatureStatus 'WithLockStatus featureName)
)
'("get", f)
(ZUser :> FeatureStatusBaseGet 'WithLockStatus f)

type FeatureStatusPut featureName =
type FeatureStatusPut f =
Named
'("put", featureName)
( Summary (AppendSymbol "Put config for " (KnownTeamFeatureNameSymbol featureName))
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> KnownTeamFeatureNameSymbol featureName
:> ReqBody '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)
:> Put '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)
)
'("put", f)
(ZUser :> FeatureStatusBasePut f)

-- | A type for a GET endpoint for a feature with a deprecated path
type FeatureStatusDeprecatedGet ps featureName =
type FeatureStatusDeprecatedGet l f =
Named
'("get-deprecated", featureName)
( Summary
(AppendSymbol "[deprecated] Get config for " (KnownTeamFeatureNameSymbol featureName))
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> DeprecatedFeatureName featureName
:> Get '[Servant.JSON] (TeamFeatureStatus ps featureName)
)
'("get-deprecated", f)
(ZUser :> FeatureStatusBaseDeprecatedGet l f)

-- | A type for a PUT endpoint for a feature with a deprecated path
type FeatureStatusDeprecatedPut featureName =
type FeatureStatusDeprecatedPut f =
Named
'("put-deprecated", featureName)
( Summary
(AppendSymbol "[deprecated] Get config for " (KnownTeamFeatureNameSymbol featureName))
:> ZUser
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> DeprecatedFeatureName featureName
:> ReqBody '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)
:> Put '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)
)
'("put-deprecated", f)
(ZUser :> FeatureStatusBaseDeprecatedPut f)

type FeatureStatusBaseGet lockStatus featureName =
Summary (AppendSymbol "Get config for " (KnownTeamFeatureNameSymbol featureName))
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> KnownTeamFeatureNameSymbol featureName
:> Get '[Servant.JSON] (TeamFeatureStatus lockStatus featureName)

type FeatureStatusBasePut featureName =
Summary (AppendSymbol "Put config for " (KnownTeamFeatureNameSymbol featureName))
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> KnownTeamFeatureNameSymbol featureName
:> ReqBody '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)
:> Put '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)

-- | A type for a GET endpoint for a feature with a deprecated path
type FeatureStatusBaseDeprecatedGet lockStatus featureName =
( Summary
(AppendSymbol "[deprecated] Get config for " (KnownTeamFeatureNameSymbol featureName))
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> DeprecatedFeatureName featureName
:> Get '[Servant.JSON] (TeamFeatureStatus lockStatus featureName)
)

-- | A type for a PUT endpoint for a feature with a deprecated path
type FeatureStatusBaseDeprecatedPut featureName =
Summary
(AppendSymbol "[deprecated] Get config for " (KnownTeamFeatureNameSymbol featureName))
:> "teams"
:> Capture "tid" TeamId
:> "features"
:> DeprecatedFeatureName featureName
:> ReqBody '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)
:> Put '[Servant.JSON] (TeamFeatureStatus 'WithoutLockStatus featureName)

type FeatureConfigGet ps featureName =
Named
Expand Down
12 changes: 1 addition & 11 deletions libs/wire-api/src/Wire/API/Routes/Public/LegalHold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ import Data.Proxy
import Data.Swagger hiding (Header (..))
import Servant.API hiding (Header)
import Servant.Swagger
import Wire.API.Team.Feature
import Wire.API.Team.LegalHold

type ServantAPI = PublicAPI :<|> InternalAPI

-- FUTUREWORK: restructure this for readability and add missing bodies
type PublicAPI =
type ServantAPI =
"teams" :> Capture "tid" TeamId :> "legalhold" :> "settings"
:> ReqBody '[JSON] NewLegalHoldService
:> Post '[JSON] ViewLegalHoldService
Expand All @@ -50,12 +47,5 @@ type PublicAPI =
-- :> ReqBody '[JSON] DisableLegalHoldForUserRequest
:> Verb 'DELETE 204 '[] NoContent

type InternalAPI =
"i" :> "teams" :> Capture "tid" TeamId :> "legalhold"
:> Get '[JSON] (TeamFeatureStatus 'WithLockStatus 'TeamFeatureLegalHold)
:<|> "i" :> "teams" :> Capture "tid" TeamId :> "legalhold"
:> ReqBody '[JSON] (TeamFeatureStatus 'WithoutLockStatus 'TeamFeatureLegalHold)
:> Put '[] NoContent

swaggerDoc :: Swagger
swaggerDoc = toSwagger (Proxy @ServantAPI)
2 changes: 2 additions & 0 deletions libs/wire-api/wire-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ library
Wire.API.Routes.Internal.Brig
Wire.API.Routes.Internal.Brig.Connection
Wire.API.Routes.Internal.Brig.EJPD
Wire.API.Routes.Internal.Cargohold
Wire.API.Routes.Internal.LegalHold
Wire.API.Routes.MultiTablePaging
Wire.API.Routes.MultiTablePaging.State
Wire.API.Routes.MultiVerb
Expand Down
11 changes: 7 additions & 4 deletions services/cargohold/src/CargoHold/API/Public.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-- You should have received a copy of the GNU Affero General Public License along
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module CargoHold.API.Public (servantSitemap) where
module CargoHold.API.Public (servantSitemap, internalSitemap) where

import qualified CargoHold.API.Legacy as LegacyAPI
import CargoHold.API.Util
Expand All @@ -36,17 +36,18 @@ import Servant.Server hiding (Handler)
import URI.ByteString
import Wire.API.Asset
import Wire.API.Routes.AssetBody
import Wire.API.Routes.Internal.Cargohold
import Wire.API.Routes.Public.Cargohold

servantSitemap :: ServerT ServantAPI Handler
servantSitemap =
renewTokenV3 :<|> deleteTokenV3
renewTokenV3
:<|> deleteTokenV3
:<|> userAPI
:<|> botAPI
:<|> providerAPI
:<|> qualifiedAPI
:<|> legacyAPI
:<|> internalAPI
where
userAPI :: forall tag. tag ~ 'UserPrincipalTag => ServerT (BaseAPIv3 tag) Handler
userAPI = uploadAssetV3 @tag :<|> downloadAssetV3 @tag :<|> deleteAssetV3 @tag
Expand All @@ -56,7 +57,9 @@ servantSitemap =
providerAPI = uploadAssetV3 @tag :<|> downloadAssetV3 @tag :<|> deleteAssetV3 @tag
legacyAPI = legacyDownloadPlain :<|> legacyDownloadPlain :<|> legacyDownloadOtr
qualifiedAPI = downloadAssetV4 :<|> deleteAssetV4
internalAPI = pure ()

internalSitemap :: ServerT InternalAPI Handler
internalSitemap = pure ()

class HasLocation (tag :: PrincipalTag) where
assetLocation :: Local AssetKey -> [Text]
Expand Down
8 changes: 5 additions & 3 deletions services/cargohold/src/CargoHold/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ import qualified Servant
import Servant.API
import Servant.Server hiding (Handler, runHandler)
import Util.Options
import qualified Wire.API.Routes.Public.Cargohold as Public
import Wire.API.Routes.Internal.Cargohold
import Wire.API.Routes.Public.Cargohold

type CombinedAPI = FederationAPI :<|> Public.ServantAPI
type CombinedAPI = FederationAPI :<|> ServantAPI :<|> InternalAPI

run :: Opts -> IO ()
run o = lowerCodensity $ do
Expand Down Expand Up @@ -77,7 +78,8 @@ mkApp o = Codensity $ \k ->
(Proxy @CombinedAPI)
((o ^. optSettings . setFederationDomain) :. Servant.EmptyContext)
( hoistServer' @FederationAPI (toServantHandler e) federationSitemap
:<|> hoistServer' @Public.ServantAPI (toServantHandler e) servantSitemap
:<|> hoistServer' @ServantAPI (toServantHandler e) servantSitemap
:<|> hoistServer' @InternalAPI (toServantHandler e) internalSitemap
)
r

Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Galley.API
where

import qualified Data.Swagger.Build.Api as Doc
import qualified Galley.API.Internal as Internal
import Galley.API.Internal
import qualified Galley.API.Public as Public
import Galley.API.Public.Servant
import Galley.App (GalleyEffects)
Expand All @@ -33,4 +33,4 @@ sitemap :: Routes Doc.ApiBuilder (Sem GalleyEffects) ()
sitemap = do
Public.sitemap
Public.apiDocs
Internal.sitemap
internalSitemap
Loading