Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Move Brig.User.Event* to brig-types #1523

Merged
merged 5 commits into from
May 23, 2021
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
5 changes: 4 additions & 1 deletion libs/brig-types/brig-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 34235c4ff601a26386a48b310d251ed69bd5ef7e6fa59da512fe9acca083ef96
-- hash: b653eba4d855ab6675efd3519d4259c9bb49379e92b15fb7f4f9080eac634bb1

name: brig-types
version: 1.35.0
Expand Down Expand Up @@ -41,6 +41,7 @@ library
Brig.Types.User
Brig.Types.User.Auth
Brig.Types.User.EJPD
Brig.Types.User.Event
other-modules:
Paths_brig_types
hs-source-dirs:
Expand All @@ -63,6 +64,7 @@ library
, swagger2 >=2.5
, text >=0.11
, time >=1.1
, tinylog
, types-common >=0.16
, unordered-containers >=0.2
, wire-api
Expand Down Expand Up @@ -94,6 +96,7 @@ test-suite brig-types-tests
, tasty-quickcheck
, text >=0.11
, time >=1.1
, tinylog
, types-common >=0.16
, unordered-containers >=0.2
, wire-api
Expand Down
1 change: 1 addition & 0 deletions libs/brig-types/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
- swagger2 >=2.5
- text >=0.11
- time >=1.1
- tinylog
- types-common >=0.16
- unordered-containers >=0.2
- wire-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
-- 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 Brig.User.Event where
module Brig.Types.User.Event where

import Brig.Types
import Data.ByteString.Conversion
import Data.Handle (Handle)
import Data.Id
import Imports
import System.Logger.Class

data Event
= UserEvent !UserEvent
Expand Down Expand Up @@ -176,3 +178,39 @@ propEventUserId :: PropertyEvent -> UserId
propEventUserId (PropertySet u _ _) = u
propEventUserId (PropertyDeleted u _) = u
propEventUserId (PropertiesCleared u) = u

logConnection :: UserId -> UserId -> Msg -> Msg
logConnection from to =
"connection.from" .= toByteString from
~~ "connection.to" .= toByteString to

instance ToBytes Event where
bytes (UserEvent e) = bytes e
bytes (ConnectionEvent e) = bytes e
bytes (PropertyEvent e) = bytes e
bytes (ClientEvent e) = bytes e

instance ToBytes UserEvent where
bytes e@UserCreated {} = val "user.new: " +++ toByteString (userEventUserId e)
bytes e@UserActivated {} = val "user.activate: " +++ toByteString (userEventUserId e)
bytes e@UserUpdated {} = val "user.update: " +++ toByteString (userEventUserId e)
bytes e@UserIdentityUpdated {} = val "user.update: " +++ toByteString (userEventUserId e)
bytes e@UserIdentityRemoved {} = val "user.identity-remove: " +++ toByteString (userEventUserId e)
bytes e@UserSuspended {} = val "user.suspend: " +++ toByteString (userEventUserId e)
bytes e@UserResumed {} = val "user.resume: " +++ toByteString (userEventUserId e)
bytes e@UserDeleted {} = val "user.delete: " +++ toByteString (userEventUserId e)
bytes e@UserLegalHoldDisabled {} = val "user.legalhold-disable: " +++ toByteString (userEventUserId e)
bytes e@UserLegalHoldEnabled {} = val "user.legalhold-enable: " +++ toByteString (userEventUserId e)
bytes (LegalHoldClientRequested payload) = val "user.legalhold-request: " +++ show payload

instance ToBytes ConnectionEvent where
bytes e@ConnectionUpdated {} = val "user.connection: " +++ toByteString (connEventUserId e)

instance ToBytes PropertyEvent where
bytes e@PropertySet {} = val "user.properties-set: " +++ toByteString (propEventUserId e)
bytes e@PropertyDeleted {} = val "user.properties-delete: " +++ toByteString (propEventUserId e)
bytes e@PropertiesCleared {} = val "user.properties-clear: " +++ toByteString (propEventUserId e)

instance ToBytes ClientEvent where
bytes (ClientAdded u _) = val "user.client-add: " +++ toByteString u
bytes (ClientRemoved u _) = val "user.client-remove: " +++ toByteString u
4 changes: 1 addition & 3 deletions services/brig/brig.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 2a9b5beec9b3ca122e8c67aa63e8852c74632a3e9d3dea5b1ad9ea7c7a05ed45
-- hash: 47605047ee190f11d8d83abeb76dbdeae1a701f79348e470c419598cd05da0d8

name: brig
version: 1.35.0
Expand Down Expand Up @@ -95,8 +95,6 @@ library
Brig.User.Auth.DB.Instances
Brig.User.EJPD
Brig.User.Email
Brig.User.Event
Brig.User.Event.Log
Brig.User.Handle
Brig.User.Handle.Blacklist
Brig.User.Phone
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ import qualified Brig.Options as Opt
import Brig.Types
import Brig.Types.Intra
import Brig.Types.Team.LegalHold (LegalHoldClientRequest (..))
import Brig.Types.User.Event
import qualified Brig.User.Auth.Cookie as Auth
import Brig.User.Email
import Brig.User.Event
import Control.Error
import Control.Lens (view)
import Data.ByteString.Conversion
Expand Down
17 changes: 8 additions & 9 deletions services/brig/src/Brig/API/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ import qualified Brig.IO.Intra as Intra
import Brig.Options (setUserMaxConnections)
import Brig.Types
import Brig.Types.Intra
import Brig.User.Event
import qualified Brig.User.Event.Log as Log
import Brig.Types.User.Event
import Control.Error
import Control.Lens (view)
import Data.Id as Id
Expand Down Expand Up @@ -95,7 +94,7 @@ createConnectionToLocalUser self crUser ConnectionRequest {crName, crMessage} co
where
insert s2o o2s = lift $ do
Log.info $
Log.connection self crUser
logConnection self crUser
. msg (val "Creating connection")
cnv <- Intra.createConnectConv self crUser (Just crName) (Just crMessage) (Just conn)
s2o' <- Data.insertConnection self crUser Sent (Just crMessage) cnv
Expand All @@ -119,7 +118,7 @@ createConnectionToLocalUser self crUser ConnectionRequest {crName, crMessage} co
when (ucStatus s2o `notElem` [Sent, Accepted]) $
checkLimit self
Log.info $
Log.connection self (ucTo s2o)
logConnection self (ucTo s2o)
. msg (val "Accepting connection")
cnv <- lift $ for (ucConvId s2o) $ Intra.acceptConnectConv self (Just conn)
s2o' <- lift $ Data.updateConnection s2o Accepted
Expand All @@ -136,7 +135,7 @@ createConnectionToLocalUser self crUser ConnectionRequest {crName, crMessage} co
when (ucStatus s2o `notElem` [Sent, Accepted]) $
checkLimit self
Log.info $
Log.connection self (ucTo s2o)
logConnection self (ucTo s2o)
. msg (val "Resending connection request")
s2o' <- insert (Just s2o) (Just o2s)
return $ ConnectionExists s2o'
Expand Down Expand Up @@ -210,7 +209,7 @@ updateConnection self other newStatus conn = do
accept s2o o2s = do
checkLimit self
Log.info $
Log.connection self (ucTo s2o)
logConnection self (ucTo s2o)
. msg (val "Accepting connection")
cnv <- lift . for (ucConvId s2o) $ Intra.acceptConnectConv self conn
-- Note: The check for @Pending@ accounts for situations in which both
Expand All @@ -227,15 +226,15 @@ updateConnection self other newStatus conn = do
lift $ Just <$> Data.updateConnection s2o Accepted
block s2o = lift $ do
Log.info $
Log.connection self (ucTo s2o)
logConnection self (ucTo s2o)
. msg (val "Blocking connection")
for_ (ucConvId s2o) $ Intra.blockConv (ucFrom s2o) conn
Just <$> Data.updateConnection s2o Blocked
unblock s2o o2s new = do
when (new `elem` [Sent, Accepted]) $
checkLimit self
Log.info $
Log.connection self (ucTo s2o)
logConnection self (ucTo s2o)
. msg (val "Unblocking connection")
cnv <- lift . for (ucConvId s2o) $ Intra.unblockConv (ucFrom s2o) conn
when (ucStatus o2s == Sent && new == Accepted) . lift $ do
Expand All @@ -248,7 +247,7 @@ updateConnection self other newStatus conn = do
lift $ Just <$> Data.updateConnection s2o new
cancel s2o o2s = do
Log.info $
Log.connection self (ucTo s2o)
logConnection self (ucTo s2o)
. msg (val "Cancelling connection")
lift . for_ (ucConvId s2o) $ Intra.blockConv (ucFrom s2o) conn
o2s' <- lift $ Data.updateConnection o2s Cancelled
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ import Brig.Types
import Brig.Types.Intra
import Brig.Types.Team.LegalHold (LegalHoldClientRequest (..))
import qualified Brig.Types.User.EJPD as EJPD
import Brig.Types.User.Event (UserEvent (UserUpdated), UserUpdatedData (eupSSOId, eupSSOIdRemoved), emptyUserUpdatedData)
import qualified Brig.User.API.Auth as Auth
import qualified Brig.User.API.Search as Search
import qualified Brig.User.EJPD
import Brig.User.Event (UserEvent (UserUpdated), UserUpdatedData (eupSSOId, eupSSOIdRemoved), emptyUserUpdatedData)
import Control.Error hiding (bool)
import Control.Lens (view, (.~))
import Data.Aeson hiding (json)
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Brig.Data.Properties (PropertiesDataError)
import qualified Brig.Data.Properties as Data
import qualified Brig.IO.Intra as Intra
import Brig.Types
import Brig.User.Event
import Brig.Types.User.Event
import Control.Error
import Data.Id
import Imports
Expand Down
2 changes: 1 addition & 1 deletion services/brig/src/Brig/API/User.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ import Brig.Types.Code (Timeout (..))
import Brig.Types.Intra
import Brig.Types.Team.Invitation (inCreatedAt, inCreatedBy)
import qualified Brig.Types.Team.Invitation as Team
import Brig.Types.User.Event
import Brig.User.Auth.Cookie (revokeAllCookies)
import Brig.User.Email
import Brig.User.Event
import Brig.User.Handle
import Brig.User.Handle.Blacklist
import Brig.User.Phone
Expand Down
5 changes: 2 additions & 3 deletions services/brig/src/Brig/IO/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ import Brig.Data.Connection (lookupContactList)
import qualified Brig.IO.Journal as Journal
import Brig.RPC
import Brig.Types
import Brig.User.Event
import qualified Brig.User.Event.Log as Log
import Brig.Types.User.Event
import qualified Brig.User.Search.Index as Search
import Control.Lens (view, (.~), (?~), (^.))
import Control.Retry
Expand Down Expand Up @@ -522,7 +521,7 @@ createSelfConv u = do
createConnectConv :: UserId -> UserId -> Maybe Text -> Maybe Message -> Maybe ConnId -> AppIO ConvId
createConnectConv from to cname mess conn = do
debug $
Log.connection from to
logConnection from to
. remote "galley"
. msg (val "Creating connect conversation")
r <- galleyRequest POST req
Expand Down
62 changes: 0 additions & 62 deletions services/brig/src/Brig/User/Event/Log.hs

This file was deleted.

12 changes: 7 additions & 5 deletions services/galley/src/Galley/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import qualified Wire.API.Routes.Public.Galley as GalleyAPI

run :: Opts -> IO ()
run o = do
(app, e) <- mkApp o
(app, e, appFinalizer) <- mkApp o
let l = e ^. App.applog
s <-
newSettings $
Expand All @@ -70,18 +70,20 @@ run o = do
Async.cancel deleteQueueThread
Async.cancel refreshMetricsThread
shutdown (e ^. cstate)
Log.flush l
Log.close l
appFinalizer

mkApp :: Opts -> IO (Application, Env)
mkApp :: Opts -> IO (Application, Env, IO ())
mkApp o = do
m <- M.metrics
e <- App.createEnv m o
let l = e ^. App.applog
validateOpts l o
runClient (e ^. cstate) $
versionCheck Data.schemaVersion
return (middlewares l m $ servantApp e, e)
let finalizer = do
Log.flush l
Log.close l
return (middlewares l m $ servantApp e, e, finalizer)
where
rtree = compile API.sitemap
app e r k = runGalley e r (route rtree r k)
Expand Down
Loading