Skip to content

Commit

Permalink
Remove some extra dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Sideris committed Feb 21, 2021
1 parent e6e5414 commit 8c6ec5a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
32 changes: 16 additions & 16 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ mkDerivation, aeson, base, base64-bytestring, bits, blaze-builder
, bytestring, case-insensitive, containers, contravariant-extras
, cookie, cryptonite, fakedata, file-embed, hasql, hasql-pool
, hasql-queue, hasql-transaction, http-client, http-client-tls
, http-media, http-types, katip, mr-env, optparse-applicative
{ mkDerivation, aeson, base, base64-bytestring, bytestring
, case-insensitive, containers, contravariant-extras, cookie
, cryptonite, fakedata, file-embed, hasql, hasql-pool, hasql-queue
, hasql-transaction, http-client, http-client-tls, http-media
, http-types, katip, mr-env, optparse-applicative
, postgresql-binary, postgresql-simple, postgresql-simple-migration
, random, raw-strings-qq, relude, req, safe, safe-exceptions
, servant, servant-client, servant-server, stdenv, system-filepath
, text, time, unix, unliftio-core, uuid, uuid-types, wai, wai-cors
, random, raw-strings-qq, relude, req, safe-exceptions, servant
, servant-client, servant-server, stdenv, system-filepath, text
, time, unix, unliftio-core, uuid, uuid-types, wai, wai-cors
, wai-extra, wai-logger, warp
}:
mkDerivation {
Expand All @@ -16,14 +16,14 @@ mkDerivation {
isLibrary = false;
isExecutable = true;
libraryHaskellDepends = [
aeson base base64-bytestring bits blaze-builder bytestring
case-insensitive containers contravariant-extras cookie cryptonite
file-embed hasql hasql-pool hasql-queue hasql-transaction
http-client http-client-tls http-media http-types katip mr-env
optparse-applicative postgresql-binary postgresql-simple
postgresql-simple-migration raw-strings-qq relude req safe
safe-exceptions servant servant-server system-filepath text time
unix unliftio-core uuid uuid-types wai wai-extra
aeson base base64-bytestring bytestring case-insensitive containers
contravariant-extras cookie cryptonite file-embed hasql hasql-pool
hasql-queue hasql-transaction http-client http-client-tls
http-media http-types katip mr-env optparse-applicative
postgresql-binary postgresql-simple postgresql-simple-migration
raw-strings-qq relude req safe-exceptions servant servant-server
system-filepath text time unix unliftio-core uuid uuid-types wai
wai-extra
];
executableHaskellDepends = [
aeson base base64-bytestring fakedata hasql hasql-pool hasql-queue
Expand Down
3 changes: 0 additions & 3 deletions hakatime.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ library libhaka
build-depends: base >= 4.9 && < 4.15
, aeson >= 1.4
, base64-bytestring
, bits
, bytestring
, case-insensitive
, containers
Expand All @@ -101,7 +100,6 @@ library libhaka
, postgresql-binary == 0.12.*
, raw-strings-qq
, safe-exceptions
, safe
, servant >= 0.17
, servant-server >= 0.17
, system-filepath
Expand All @@ -112,7 +110,6 @@ library libhaka
, wai == 3.2.*
, wai-extra
, http-types
, blaze-builder
, relude >= 0.6.0.0
, postgresql-simple
, postgresql-simple-migration
Expand Down
5 changes: 2 additions & 3 deletions src/Haka/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Haka.Cli
)
where

import Data.Bits.Extras (w16)
import Data.Version (showVersion)
import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.Migration
Expand All @@ -21,13 +20,13 @@ import System.Posix.Env.ByteString (getEnvDefault)

getDbSettings :: IO HasqlConn.Settings
getDbSettings = do
dbPort <- w16 <$> envAsInt "HAKA_DB_PORT" 5432
dbPort <- toIntegralSized <$> envAsInt "HAKA_DB_PORT" 5432
dbHost <- getEnvDefault "HAKA_DB_HOST" "localhost"
dbName <- getEnvDefault "HAKA_DB_NAME" "test"
dbUser <- getEnvDefault "HAKA_DB_USER" "test"
dbPass <- getEnvDefault "HAKA_DB_PASS" "test"
return $
HasqlConn.settings dbHost dbPort dbUser dbPass dbName
HasqlConn.settings dbHost (fromMaybe 5432 dbPort) dbUser dbPass dbName

newtype TokenOpts = TokenOpts {tUsername :: Text}
deriving (Eq, Show)
Expand Down
16 changes: 8 additions & 8 deletions src/Haka/Middleware.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Haka.Middleware (jsonResponse) where

import Blaze.ByteString.Builder (toLazyByteString)
import Blaze.ByteString.Builder.ByteString (fromByteString)
import Data.Aeson
import Data.ByteString.Builder
import Data.Text (isInfixOf)
import Network.HTTP.Types
import Network.Wai
Expand All @@ -21,7 +20,7 @@ responseModifier r
| otherwise = r

customErrorBody :: Response -> Text -> Text
customErrorBody (ResponseBuilder _ _ b) _ = toStrict $ decodeUtf8 $ toLazyByteString b
customErrorBody (ResponseBuilder _ _ b) _ = decodeUtf8 $ toLazyByteString b
customErrorBody (ResponseRaw _ res) e = customErrorBody res e
customErrorBody _ e = e

Expand All @@ -33,9 +32,10 @@ buildResponse st err msg =
responseBuilder
st
[("Content-Type", "application/json")]
( fromByteString . toStrict . encode $
object
[ "error" .= err,
"message" .= msg
]
( lazyByteString $
encode $
object
[ "error" .= err,
"message" .= msg
]
)
3 changes: 1 addition & 2 deletions src/Haka/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Data.UUID.V4 (nextRandom)
import Hasql.Pool (UsageError (..))
import qualified Hasql.Session as S
import qualified Relude.Unsafe as Unsafe
import Safe (headMay)
import System.IO (hFlush, hGetEcho, hSetEcho, putChar)
import Web.Cookie

Expand Down Expand Up @@ -146,7 +145,7 @@ toStrError err = toText (show err :: String)

getRefreshToken :: ByteString -> Maybe Text
getRefreshToken cookies =
let value = headMay $ map snd $ filter (\(k, _) -> k == "refresh_token") (parseCookies cookies)
let value = listToMaybe $ map snd $ filter (\(k, _) -> k == "refresh_token") (parseCookies cookies)
in case value of
Just v -> Just $ decodeUtf8 v
Nothing -> Nothing
Expand Down

0 comments on commit 8c6ec5a

Please sign in to comment.