Skip to content

Commit 69b6cf5

Browse files
committed
Remove weeds
1 parent f2ae0f3 commit 69b6cf5

File tree

4 files changed

+79
-82
lines changed

4 files changed

+79
-82
lines changed

.hlint.yaml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# HLint configuration file
2+
# https://github.com/ndmitchell/hlint
3+
##########################
4+
5+
# This file contains a template configuration file, which is typically
6+
# placed as .hlint.yaml in the root of your project
7+
8+
9+
# Specify additional command line arguments
10+
#
11+
# - arguments: [--color, --cpp-simple, -XQuasiQuotes]
12+
13+
14+
# Control which extensions/flags/modules/functions can be used
15+
#
16+
- extensions:
17+
- name:
18+
- TemplateHaskell
19+
- OverloadedStrings
20+
- RecordWildCards
21+
- ScopedTypeVariables
22+
- DeriveGeneric
23+
- TypeApplications
24+
- FlexibleContexts
25+
- DeriveAnyClass
26+
- QuasiQuotes
27+
#
28+
# - flags:
29+
# - {name: -w, within: []} # -w is allowed nowhere
30+
#
31+
# - modules:
32+
# - {name: [Data.Set, Data.HashSet], as: Set} # if you import Data.Set qualified, it must be as 'Set'
33+
# - {name: Control.Arrow, within: []} # Certain modules are banned entirely
34+
#
35+
# - functions:
36+
# - {name: unsafePerformIO, within: []} # unsafePerformIO can only appear in no modules
37+
38+
39+
# Add custom hints for this project
40+
#
41+
# Will suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar"
42+
# - error: {lhs: "wibbleMany [x]", rhs: wibbleOne x}
43+
44+
45+
# Turn on hints that are off by default
46+
#
47+
# Ban "module X(module X) where", to require a real export list
48+
# - warn: {name: Use explicit module export list}
49+
#
50+
# Replace a $ b $ c with a . b $ c
51+
# - group: {name: dollar, enabled: true}
52+
#
53+
# Generalise map to fmap, ++ to <>
54+
# - group: {name: generalise, enabled: true}
55+
56+
57+
# Ignore some builtin hints
58+
# - ignore: {name: Use let}
59+
# - ignore: {name: Use const, within: SpecialModule} # Only within certain modules
60+
61+
62+
# Define some custom infix operators
63+
# - fixity: infixr 3 ~^#^~
64+
65+
66+
# To generate a suitable file for HLint do:
67+
# $ hlint --default > .hlint.yaml

package.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@ description: Please see the README on GitHub at <https://github.com/theam/aws-la
1616

1717
dependencies:
1818
- base >= 4.7 && < 5
19-
- mtl
20-
- http-client
2119

2220
library:
2321
dependencies:
2422
- aeson
2523
- bytestring
26-
- case-insensitive
27-
- conduit
28-
- directory
29-
- filepath
24+
- http-client
3025
- http-types
31-
- microlens-platform
3226
- optparse-generic
3327
- process
3428
- template-haskell
3529
- text
3630
- uuid
3731
- safe-exceptions-checked
32+
- path
33+
- path-io
3834
source-dirs: src
3935
exposed-modules:
4036
- Aws.Lambda
@@ -46,6 +42,7 @@ executables:
4642
main: Main.hs
4743
dependencies:
4844
- aws-lambda-haskell-runtime
45+
- http-client
4946

5047
tests:
5148
aws-lambda-haskell-runtime-test:
@@ -67,6 +64,7 @@ default-extensions:
6764
- TypeApplications
6865
- FlexibleContexts
6966
- DeriveAnyClass
67+
- QuasiQuotes
7068

7169
ghc-options:
7270
- -Wall

src/Aws/Lambda/Configuration.hs

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,19 @@ where
1212
import Data.Aeson
1313

1414
import Control.Monad
15-
import Control.Monad.Trans
1615
import qualified Data.ByteString.Lazy as LazyByteString
17-
import qualified Data.Conduit as Conduit
1816
import Data.Function ((&))
1917
import Data.Text (Text)
2018
import qualified Data.Text as Text
2119
import qualified Data.Text.Encoding as Encoding
22-
import Data.Void
2320
import GHC.Generics
2421
import Language.Haskell.TH
2522
import qualified Options.Generic as Options
26-
import qualified System.Directory as Directory
2723
import System.Exit (exitFailure, exitSuccess)
28-
import System.FilePath ((</>))
2924
import System.IO (hFlush, stderr, stdout)
30-
import System.IO.Error
31-
3225

26+
import Path
27+
import qualified Path.IO as PathIO
3328

3429
import Aws.Lambda.ThHelpers
3530

@@ -69,12 +64,11 @@ dispatcherCaseQ fileNames = do
6964

7065
handlerCaseQ :: Text -> Q Match
7166
handlerCaseQ lambdaHandler = do
72-
let pattern = LitP (StringL $ Text.unpack lambdaHandler)
67+
let pat = LitP (StringL $ Text.unpack lambdaHandler)
7368
body <- [e|do
7469
result <- $(eName qualifiedName) (decodeObj $(eName "eventObject")) (decodeObj $(eName "contextObject"))
75-
either (returnAndFail $(eName "executionUuid")) (returnAndSucceed $(eName "executionUuid")) result
76-
|]
77-
pure $ Match pattern (NormalB body) []
70+
either (returnAndFail $(eName "executionUuid")) (returnAndSucceed $(eName "executionUuid")) result |]
71+
pure $ Match pat (NormalB body) []
7872
where
7973
qualifiedName =
8074
lambdaHandler
@@ -123,51 +117,11 @@ decodeObj x =
123117
Left e -> error e
124118
Right v -> v
125119

126-
127-
data DirContent = DirList [FilePath] [FilePath]
128-
| DirError IOError
129-
data DirData = DirData FilePath DirContent
130-
131-
132-
-- Produces directory data
133-
walk :: FilePath -> Conduit.ConduitM () DirData IO ()
134-
walk path = do
135-
result <- lift $ tryIOError listdir
136-
case result of
137-
Right dl@(DirList subdirs _) -> do
138-
Conduit.yield (DirData path dl)
139-
forM_ subdirs (walk . (path </>))
140-
Right e -> Conduit.yield (DirData path e)
141-
Left e -> Conduit.yield (DirData path (DirError e))
142-
where
143-
listdir = do
144-
entries <- filterHidden <$> Directory.getDirectoryContents path
145-
subdirs <- filterM isDir entries
146-
files <- filterM isFile entries
147-
return $ DirList subdirs files
148-
where
149-
isFile entry = Directory.doesFileExist (path </> entry)
150-
isDir entry = Directory.doesDirectoryExist (path </> entry)
151-
filterHidden paths = filter (\p -> head p /= '.' && p /= "node_modules") paths
152-
153-
154-
-- Consume directories
155-
myVisitor :: Conduit.ConduitM DirData Void IO [FilePath]
156-
myVisitor = loop []
157-
where
158-
loop n = do
159-
r <- Conduit.await
160-
case r of
161-
Nothing -> return n
162-
Just result -> loop (process result <> n)
163-
process (DirData _ (DirError _)) = []
164-
process (DirData dir (DirList _ files)) = map (\f -> dir <> "/" <> f) files
165-
166-
167120
getHandlers :: IO [Text]
168121
getHandlers = do
169-
files <- Conduit.runConduit $ walk "." Conduit..| myVisitor
122+
(_, files) <- PathIO.listDirRecurRel [reldir|.|]
170123
handlerFiles <- files
124+
& fmap toFilePath
171125
& fmap Text.pack
172126
& filter (Text.isSuffixOf ".hs")
173127
& filterM containsHandler

src/Aws/Lambda/Runtime/Error.hs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Aws.Lambda.Runtime.Error
22
( EnvironmentVariableNotSet(..)
3-
, ApiConnection(..)
4-
, ApiHeaderNotSet(..)
53
, Parsing(..)
64
, Invocation(..)
75
) where
@@ -19,26 +17,6 @@ instance ToJSON EnvironmentVariableNotSet where
1917
, "errorMessage" .= msg
2018
]
2119

22-
data ApiConnection =
23-
ApiConnection
24-
deriving (Show, Exception)
25-
26-
instance ToJSON ApiConnection where
27-
toJSON ApiConnection = object
28-
[ "errorType" .= ("ApiConnection" :: String)
29-
, "errorMessage" .= ("Could not connect to API to retrieve AWS Lambda parameters" :: String)
30-
]
31-
32-
newtype ApiHeaderNotSet =
33-
ApiHeaderNotSet String
34-
deriving (Show, Exception)
35-
36-
instance ToJSON ApiHeaderNotSet where
37-
toJSON (ApiHeaderNotSet headerName) = object
38-
[ "errorType" .= ("ApiHeaderNotSet" :: String)
39-
, "errorMessage" .= headerName
40-
]
41-
4220
data Parsing = Parsing
4321
{ errorMessage :: String
4422
, actualValue :: String

0 commit comments

Comments
 (0)