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/WPB-7222
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop cs in all production code and from Imports
2 changes: 1 addition & 1 deletion libs/bilge/src/Bilge/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import Data.ByteString.Lazy qualified as Lazy
import Data.ByteString.Lazy.Char8 qualified as LC
import Data.CaseInsensitive (original)
import Data.Id (RequestId (..))
import Imports hiding (cs, intercalate)
import Imports hiding (intercalate)
import Network.HTTP.Client (Cookie, GivesPopper, Request, RequestBody (..))
import Network.HTTP.Client qualified as Rq
import Network.HTTP.Client.Internal (CookieJar (..), brReadSome, throwHttp)
Expand Down
10 changes: 9 additions & 1 deletion libs/extended/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
, servant-client-core
, servant-openapi3
, servant-server
, string-conversions
, temporary
, text
, time
Expand Down Expand Up @@ -69,7 +70,14 @@ mkDerivation {
unliftio
wai
];
testHaskellDepends = [ aeson base hspec imports temporary ];
testHaskellDepends = [
aeson
base
hspec
imports
string-conversions
temporary
];
testToolDepends = [ hspec-discover ];
description = "Extended versions of common modules";
license = lib.licenses.agpl3Only;
Expand Down
1 change: 1 addition & 0 deletions libs/extended/extended.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ test-suite extended-tests
, extended
, hspec
, imports
, string-conversions
, temporary

default-language: GHC2021
3 changes: 2 additions & 1 deletion libs/extended/src/Servant/API/Extended.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-- errors instead of plaintext.
module Servant.API.Extended where

import Data.ByteString
import Data.ByteString.Lazy qualified as BL
import Data.EitherR (fmapL)
import Data.Kind
Expand Down Expand Up @@ -92,7 +93,7 @@ instance
fromMaybe "application/octet-stream" $
lookup hContentType $
requestHeaders request
case canHandleCTypeH (Proxy :: Proxy list) (cs contentTypeH) :: Maybe (BL.ByteString -> Either String a) of
case canHandleCTypeH (Proxy :: Proxy list) (fromStrict contentTypeH) :: Maybe (BL.ByteString -> Either String a) of
Nothing -> delayedFail err415
Just f -> pure f
-- Body check, we get a body parsing functions as the first argument.
Expand Down
23 changes: 20 additions & 3 deletions libs/extended/src/System/Logger/Extended.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ import Control.Monad.Catch
import Data.Aeson as Aeson
import Data.Aeson.Encoding (list, pair, text)
import Data.Aeson.Key qualified as Key
import Data.ByteString (toStrict)
import Data.ByteString.Builder qualified as B
import Data.ByteString.Lazy.Char8 qualified as L
import Data.Map.Lazy qualified as Map
import Data.Text.Encoding
import Data.Text.Encoding.Error
import GHC.Generics
import Imports
import System.Logger as Log
Expand All @@ -65,7 +68,14 @@ elementToEncoding :: Element' -> Encoding
elementToEncoding (Element' fields msgs) = pairs $ fields <> msgsToSeries msgs
where
msgsToSeries :: [Builder] -> Series
msgsToSeries = pair "msgs" . list (text . cs . eval)
msgsToSeries =
pair "msgs"
. list
( text
. decodeUtf8With lenientDecode
. toStrict
. eval
)

collect :: [Element] -> Element'
collect = foldr go (Element' mempty [])
Expand All @@ -74,7 +84,14 @@ collect = foldr go (Element' mempty [])
go (Bytes b) (Element' f m) =
Element' f (b : m)
go (Field k v) (Element' f m) =
Element' (f <> pair (Key.fromText . cs . eval $ k) (text . cs . eval $ v)) m
Element'
( f
<> pair
(Key.fromText . dec . toStrict . eval $ k)
(text . dec . toStrict . eval $ v)
)
m
dec = decodeUtf8With lenientDecode

jsonRenderer :: Renderer
jsonRenderer _sep _dateFormat _logLevel = fromEncoding . elementToEncoding . collect
Expand Down Expand Up @@ -105,7 +122,7 @@ structuredJSONRenderer _sep _dateFmt _lvlThreshold logElems =
renderTextList xs = toJSON xs

builderToText :: Builder -> Text
builderToText = cs . eval
builderToText = decodeUtf8With lenientDecode . toStrict . eval

-- We need to do this to work around https://gitlab.com/twittner/tinylog/-/issues/5
parseLevel :: Text -> Maybe Level
Expand Down
1 change: 1 addition & 0 deletions libs/extended/test/Test/System/Logger/ExtendedSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Test.System.Logger.ExtendedSpec where

import Data.Aeson ((.=))
import Data.Aeson qualified as Aeson
import Data.String.Conversions
import Imports
import System.IO.Temp
import System.Logger.Extended hiding ((.=))
Expand Down
2 changes: 2 additions & 0 deletions libs/galley-types/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
, tasty-quickcheck
, text
, types-common
, utf8-string
, uuid
, wire-api
}:
Expand All @@ -43,6 +44,7 @@ mkDerivation {
schema-profunctor
text
types-common
utf8-string
uuid
wire-api
];
Expand Down
1 change: 1 addition & 0 deletions libs/galley-types/galley-types.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ library
, schema-profunctor
, text >=0.11
, types-common >=0.16
, utf8-string
, uuid
, wire-api

Expand Down
2 changes: 1 addition & 1 deletion libs/galley-types/src/Galley/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
import Data.Aeson
import Data.Id (ClientId, UserId)
import Data.Map.Strict qualified as Map
import Imports hiding (cs)
import Imports
import Wire.API.Message

--------------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions libs/galley-types/src/Galley/Types/Teams.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ where
import Control.Lens (makeLenses, view)
import Data.Aeson
import Data.Aeson.Types qualified as A
import Data.ByteString (toStrict)
import Data.ByteString.UTF8 qualified as UTF8
import Data.Id (UserId)
import Data.Schema qualified as Schema
import Data.Set qualified as Set
Expand Down Expand Up @@ -199,7 +201,7 @@ instance ToJSON FeatureFlags where
instance FromJSON FeatureSSO where
parseJSON (String "enabled-by-default") = pure FeatureSSOEnabledByDefault
parseJSON (String "disabled-by-default") = pure FeatureSSODisabledByDefault
parseJSON bad = fail $ "FeatureSSO: " <> cs (encode bad)
parseJSON bad = fail $ "FeatureSSO: " <> (UTF8.toString . toStrict . encode $ bad)

instance ToJSON FeatureSSO where
toJSON FeatureSSOEnabledByDefault = String "enabled-by-default"
Expand All @@ -209,7 +211,7 @@ instance FromJSON FeatureLegalHold where
parseJSON (String "disabled-permanently") = pure $ FeatureLegalHoldDisabledPermanently
parseJSON (String "disabled-by-default") = pure $ FeatureLegalHoldDisabledByDefault
parseJSON (String "whitelist-teams-and-implicit-consent") = pure FeatureLegalHoldWhitelistTeamsAndImplicitConsent
parseJSON bad = fail $ "FeatureLegalHold: " <> cs (encode bad)
parseJSON bad = fail $ "FeatureLegalHold: " <> (UTF8.toString . toStrict . encode $ bad)

instance ToJSON FeatureLegalHold where
toJSON FeatureLegalHoldDisabledPermanently = String "disabled-permanently"
Expand All @@ -219,7 +221,7 @@ instance ToJSON FeatureLegalHold where
instance FromJSON FeatureTeamSearchVisibilityAvailability where
parseJSON (String "enabled-by-default") = pure FeatureTeamSearchVisibilityAvailableByDefault
parseJSON (String "disabled-by-default") = pure FeatureTeamSearchVisibilityUnavailableByDefault
parseJSON bad = fail $ "FeatureSearchVisibility: " <> cs (encode bad)
parseJSON bad = fail $ "FeatureSearchVisibility: " <> (UTF8.toString . toStrict . encode $ bad)

instance ToJSON FeatureTeamSearchVisibilityAvailability where
toJSON FeatureTeamSearchVisibilityAvailableByDefault = String "enabled-by-default"
Expand Down
2 changes: 1 addition & 1 deletion libs/gundeck-types/src/Gundeck/Types/Push/V2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import Data.List1 qualified as List1
import Data.Range
import Data.Range qualified as Range
import Data.Set qualified as Set
import Imports hiding (cs)
import Imports
import Wire.API.Message (Priority (..))
import Wire.API.Push.V2.Token
import Wire.Arbitrary
Expand Down
2 changes: 0 additions & 2 deletions libs/imports/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
, gitignoreSource
, lib
, mtl
, string-conversions
, text
, transformers
, unliftio
Expand All @@ -29,7 +28,6 @@ mkDerivation {
deepseq
extra
mtl
string-conversions
text
transformers
unliftio
Expand Down
1 change: 0 additions & 1 deletion libs/imports/imports.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ library
, deepseq
, extra
, mtl
, string-conversions
, text
, transformers
, unliftio
Expand Down
2 changes: 0 additions & 2 deletions libs/imports/src/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ module Imports
-- * Extra Helpers
whenM,
unlessM,
cs,

-- * Functor
(<$$>),
Expand Down Expand Up @@ -165,7 +164,6 @@ import Data.Ord
import Data.Semigroup hiding (diff)
import Data.Set (Set)
import Data.String
import Data.String.Conversions (cs)
import Data.Text (Text)
import Data.Text.Lazy qualified
import Data.Traversable
Expand Down
11 changes: 10 additions & 1 deletion libs/jwt-tools/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
, imports
, lib
, rusty_jwt_tools_ffi
, string-conversions
, transformers
, utf8-string
}:
mkDerivation {
pname = "jwt-tools";
Expand All @@ -24,9 +26,16 @@ mkDerivation {
http-types
imports
transformers
utf8-string
];
librarySystemDepends = [ rusty_jwt_tools_ffi ];
testHaskellDepends = [ bytestring hspec imports transformers ];
testHaskellDepends = [
bytestring
hspec
imports
string-conversions
transformers
];
description = "FFI to rusty-jwt-tools";
license = lib.licenses.agpl3Only;
}
2 changes: 2 additions & 0 deletions libs/jwt-tools/jwt-tools.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ library
, http-types
, imports
, transformers
, utf8-string

default-language: GHC2021
other-extensions: ForeignFunctionInterface
Expand All @@ -83,6 +84,7 @@ test-suite jwt-tools-tests
, hspec
, imports
, jwt-tools
, string-conversions
, transformers

hs-source-dirs: test
Expand Down
9 changes: 5 additions & 4 deletions libs/jwt-tools/src/Data/Jwt/Tools.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ where
import Control.Exception hiding (handle)
import Control.Monad.Trans.Except
import Data.ByteString.Conversion
import Data.ByteString.UTF8 qualified as UTF8
import Foreign.C.String (CString, newCString, peekCString)
import Foreign.Ptr (Ptr, nullPtr)
import Imports
Expand Down Expand Up @@ -163,7 +164,7 @@ generateDpopToken dpopProof uid cid handle displayName tid domain nonce uri meth
domainCStr <- toCStr domain
nonceCStr <- toCStr nonce
uriCStr <- toCStr uri
methodCStr <- liftIO $ newCString $ cs $ methodToBS method
methodCStr <- liftIO $ newCString $ UTF8.toString $ methodToBS method
backendPubkeyBundleCStr <- toCStr backendPubkeyBundle

-- log all variable inputs (can comment in if need to generate new test data)
Expand Down Expand Up @@ -205,7 +206,7 @@ generateDpopToken dpopProof uid cid handle displayName tid domain nonce uri meth
toCStr = liftIO . newCString . toStr
where
toStr :: a -> String
toStr = cs . toByteString'
toStr = UTF8.toString . toByteString'

methodToBS :: StdMethod -> ByteString
methodToBS = \case
Expand All @@ -221,8 +222,8 @@ generateDpopToken dpopProof uid cid handle displayName tid domain nonce uri meth

toResult :: Maybe Word8 -> Maybe String -> Either DPoPTokenGenerationError ByteString
-- the only valid cases are when the error=0 (meaning no error) or nothing and the token is not null
toResult (Just 0) (Just token) = Right $ cs token
toResult Nothing (Just token) = Right $ cs token
toResult (Just 0) (Just token) = Right $ UTF8.fromString token
toResult Nothing (Just token) = Right $ UTF8.fromString token
-- errors
toResult (Just errNo) _ = Left $ fromInt (fromIntegral errNo)
where
Expand Down
1 change: 1 addition & 0 deletions libs/jwt-tools/test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import Control.Monad.Trans.Except
import Data.ByteString.Char8 (split)
import Data.Jwt.Tools
import Data.String.Conversions
import Imports
import Test.Hspec

Expand Down
2 changes: 2 additions & 0 deletions libs/metrics-wai/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
, servant
, servant-multipart
, text
, utf8-string
, wai
, wai-middleware-prometheus
, wai-route
Expand All @@ -35,6 +36,7 @@ mkDerivation {
servant
servant-multipart
text
utf8-string
wai
wai-middleware-prometheus
wai-route
Expand Down
1 change: 1 addition & 0 deletions libs/metrics-wai/metrics-wai.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ library
, servant
, servant-multipart
, text >=0.11
, utf8-string
, wai >=3
, wai-middleware-prometheus
, wai-route >=0.3
Expand Down
11 changes: 7 additions & 4 deletions libs/metrics-wai/src/Data/Metrics/Servant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
-- | Given a servant API type, this module gives you a 'Paths' for 'withPathTemplate'.
module Data.Metrics.Servant where

import Data.ByteString.UTF8 qualified as UTF8
import Data.Metrics.Middleware.Prometheus (normalizeWaiRequestRoute)
import Data.Metrics.Types
import Data.Metrics.Types qualified as Metrics
import Data.Metrics.WaiRoute (treeToPaths)
import Data.Proxy
import Data.Text.Encoding
import Data.Text.Encoding.Error
import Data.Tree
import GHC.TypeLits
import Imports
Expand All @@ -48,8 +51,8 @@ servantPrometheusMiddleware _ = Promth.prometheus conf . instrument promthNormal
promthNormalize :: Wai.Request -> Text
promthNormalize req = pathInfo
where
mPathInfo = Metrics.treeLookup (routesToPaths @api) $ cs <$> Wai.pathInfo req
pathInfo = cs $ fromMaybe "N/A" mPathInfo
mPathInfo = Metrics.treeLookup (routesToPaths @api) $ encodeUtf8 <$> Wai.pathInfo req
pathInfo = decodeUtf8With lenientDecode $ fromMaybe "N/A" mPathInfo

-- See Note [Raw Response]
instrument = Promth.instrumentHandlerValueWithFilter Promth.ignoreRawResponses
Expand Down Expand Up @@ -85,14 +88,14 @@ instance
(KnownSymbol seg, RoutesToPaths segs) =>
RoutesToPaths (seg :> segs)
where
getRoutes = [Node (Right . cs $ symbolVal (Proxy @seg)) (getRoutes @segs)]
getRoutes = [Node (Right . UTF8.fromString $ symbolVal (Proxy @seg)) (getRoutes @segs)]

-- <capture> :> routes
instance
(KnownSymbol capture, RoutesToPaths segs) =>
RoutesToPaths (Capture' mods capture a :> segs)
where
getRoutes = [Node (Left (cs (":" <> symbolVal (Proxy @capture)))) (getRoutes @segs)]
getRoutes = [Node (Left (UTF8.fromString (":" <> symbolVal (Proxy @capture)))) (getRoutes @segs)]

instance
(RoutesToPaths rest) =>
Expand Down
Loading