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/3-bug-fixes/stern-api-check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove overly restricte api check
Copy link
Contributor

Choose a reason for hiding this comment

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

arguably it's overly restrictive to make sure we're running into this early, and not when we have to make the version bump. but that's clearly arguable, yes. :)

3 changes: 3 additions & 0 deletions tools/stern/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
, split
, string-conversions
, swagger2
, tasty
, tasty-hunit
, text
, tinylog
, transformers
Expand Down Expand Up @@ -107,6 +109,7 @@ mkDerivation {
types-common
unliftio
];
testHaskellDepends = [ base tasty tasty-hunit wire-api ];
license = lib.licenses.agpl3Only;
mainProgram = "stern";
}
1 change: 0 additions & 1 deletion tools/stern/src/Stern/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ default (ByteString)
start :: Opts -> IO ()
start o = do
e <- newEnv o
runAppT e $ Intra.assertBackendApiVersion
s <- Server.newSettings (server e)
Server.runSettingsWithShutdown s (servantApp e) Nothing
where
Expand Down
15 changes: 1 addition & 14 deletions tools/stern/src/Stern/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-- with this program. If not, see <https://www.gnu.org/licenses/>.

module Stern.Intra
( assertBackendApiVersion,
( backendApiVersion,
putUser,
putUserStatus,
getContacts,
Expand Down Expand Up @@ -67,7 +67,6 @@ import qualified Bilge
import Bilge.RPC
import Brig.Types.Intra
import Control.Error
import Control.Exception (ErrorCall (ErrorCall))
import Control.Lens (view, (^.))
import Control.Monad.Reader
import Data.Aeson hiding (Error)
Expand Down Expand Up @@ -95,7 +94,6 @@ import Stern.Types
import System.Logger.Class hiding (Error, name, (.=))
import qualified System.Logger.Class as Log
import UnliftIO.Exception hiding (Handler)
import UnliftIO.Retry (constantDelay, limitRetries, recoverAll)
import Wire.API.Connection
import Wire.API.Conversation
import Wire.API.Internal.Notification
Expand All @@ -121,17 +119,6 @@ import Wire.API.User.Search
backendApiVersion :: Version
backendApiVersion = V2

-- | Make sure the backend supports `backendApiVersion`. Crash if it doesn't. (This is called
-- in `Stern.API` so problems make `./services/run-service` crash.)
assertBackendApiVersion :: App ()
assertBackendApiVersion = recoverAll (constantDelay 1000000 <> limitRetries 5) $ \_retryStatus -> do
b <- view brig
vinfo :: VersionInfo <-
responseJsonError
=<< rpc' "brig" b (method GET . Bilge.path "/api-version" . contentJson . expect2xx)
unless (maximum (vinfoSupported vinfo) == backendApiVersion) $ do
throwIO . ErrorCall $ "newest supported backend api version must be " <> show backendApiVersion

path :: ByteString -> Request -> Request
path = Bilge.path . ((toPathComponent backendApiVersion <> "/") <>)

Expand Down
14 changes: 14 additions & 0 deletions tools/stern/stern.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,17 @@ executable stern
ld-options: -static

default-language: Haskell2010

test-suite stern-tests
type: exitcode-stdio-1.0
main-is: Main.hs

-- cabal-fmt: expand test/unit
other-modules: Main
hs-source-dirs: test/unit
build-depends:
base
, stern
, tasty
, tasty-hunit
, wire-api
37 changes: 37 additions & 0 deletions tools/stern/test/unit/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- This file is part of the Wire Server implementation.
--
-- Copyright (C) 2022 Wire Swiss GmbH <opensource@wire.com>
--
-- 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 Main where

import qualified Stern.Intra as Intra
import Test.Tasty
import Test.Tasty.HUnit
import Wire.API.Routes.Version (supportedVersions)

main :: IO ()
main =
defaultMain $
testGroup
"Tests"
[ testCase "testSupportedAPIVersion" testSupportedAPIVersion
]

testSupportedAPIVersion :: IO ()
testSupportedAPIVersion =
assertBool
"Stern requires an API version that is unsupported"
(Intra.backendApiVersion `elem` supportedVersions)