Skip to content

Commit

Permalink
Compatibility with envparse-0.5.0
Browse files Browse the repository at this point in the history
Immediately after implementing kept, envparse-0.5 was released and
Stackage nightly picked it up. In order to stay, we need to be
compatible.
  • Loading branch information
pbrisbin committed Jun 14, 2022
1 parent f4755af commit d35eb91
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
24 changes: 19 additions & 5 deletions library/Freckle/App/Env.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE CPP #-}

-- | Parse the shell environment for configuration
--
-- A minor extension of [envparse](https://hackage.haskell.org/package/envparse).
Expand Down Expand Up @@ -76,14 +78,26 @@ newtype On a = On a
flag :: Off a -> On a -> String -> Mod Flag a -> Parser Error a
flag (Off f) (On t) n m = Env.flag f t n m

-- | Modify a 'Parser' so all variables are as if they used 'keep'
-- | Modify a 'Parser' so variables are never removed after reading
--
-- In @envparse-0.4@, read variables are removed from the environment. This is
-- often problematic (e.g. in tests that repeatedly load an app and re-read the
-- environment), and the security benefits are minor. This function will make
-- them all behave as if @keep@ was used.
--
-- By default, read variables are removed from the environment. This is often
-- problematic (e.g. in tests that repeatedly load an app and re-read the
-- environment), and the security benefits are minor.
-- In @envparse-0.5@, the default is reversed and @sensitive@ can be used to
-- explicitly unset read variables. This function will make them all behave as
-- if @sensitive@ was /not/ used.
--
kept :: Parser e a -> Parser e a
kept = Parser . hoistAlt (\v -> v { varfKeep = True }) . unParser
kept = Parser . hoistAlt go . unParser
where
go v =
#if MIN_VERSION_envparse(0,5,0)
v { varfSensitive = False }
#else
v { varfKeep = True }
#endif

-- | Create a 'Reader' from a simple parser function
--
Expand Down
2 changes: 1 addition & 1 deletion stack-nightly.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: nightly-2022-06-06
resolver: nightly-2022-06-14
extra-deps:
- Blammo-1.0.0.1
- context-0.2.0.0
Expand Down
8 changes: 4 additions & 4 deletions stack-nightly.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packages:
hackage: scientist-0.0.0.0
snapshots:
- completed:
size: 605110
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/6/6.yaml
sha256: 26ea900ee8601fee24ff84981e92f304d384c73ee32d5504299133b5eb177e87
original: nightly-2022-06-06
size: 611629
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/6/14.yaml
sha256: 0053bc98eb1eae51d523de1ea060941285b4692e93d539b49e64429d50071fe4
original: nightly-2022-06-14

0 comments on commit d35eb91

Please sign in to comment.