This commit is contained in:
committed by
Joe Nelson
parent
a6cce691b5
commit
65c9d549c1
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- #876, Read secret files as binary, discard final LF if any - @eric-brechemier
|
||||||
- #968, Treat blank proxy uri as missing - @begriffs
|
- #968, Treat blank proxy uri as missing - @begriffs
|
||||||
- #933, OpenAPI externals docs url to current version - @steve-chavez
|
- #933, OpenAPI externals docs url to current version - @steve-chavez
|
||||||
- #962, OpenAPI don't err on nonexistent schema - @steve-chavez
|
- #962, OpenAPI don't err on nonexistent schema - @steve-chavez
|
||||||
|
|||||||
+10
-7
@@ -16,13 +16,14 @@ import Protolude hiding (replace, hPutStrLn)
|
|||||||
import Control.Retry (RetryStatus, capDelay,
|
import Control.Retry (RetryStatus, capDelay,
|
||||||
exponentialBackoff,
|
exponentialBackoff,
|
||||||
retrying, rsPreviousDelay)
|
retrying, rsPreviousDelay)
|
||||||
import Data.ByteString.Base64 (decode)
|
|
||||||
import Data.IORef (IORef, atomicWriteIORef,
|
import Data.IORef (IORef, atomicWriteIORef,
|
||||||
newIORef, readIORef)
|
newIORef, readIORef)
|
||||||
import Data.String (IsString (..))
|
import Data.String (IsString (..))
|
||||||
import Data.Text (pack, replace, stripPrefix, strip)
|
import Data.Text (pack, replace, stripPrefix, strip)
|
||||||
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
|
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
|
||||||
import Data.Text.IO (hPutStrLn, readFile)
|
import Data.Text.IO (hPutStrLn)
|
||||||
|
import qualified Data.ByteString.Base64 as B64
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
import qualified Hasql.Decoders as HD
|
import qualified Hasql.Decoders as HD
|
||||||
import qualified Hasql.Encoders as HE
|
import qualified Hasql.Encoders as HE
|
||||||
import qualified Hasql.Pool as P
|
import qualified Hasql.Pool as P
|
||||||
@@ -264,14 +265,16 @@ loadSecretFile conf = extractAndTransform mSecret
|
|||||||
fmap setSecret $
|
fmap setSecret $
|
||||||
transformString isB64 =<<
|
transformString isB64 =<<
|
||||||
case stripPrefix "@" secret of
|
case stripPrefix "@" secret of
|
||||||
Nothing -> return secret
|
Nothing -> return . encodeUtf8 $ secret
|
||||||
Just filename -> readFile (toS filename)
|
Just filename -> chomp <$> BS.readFile (toS filename)
|
||||||
|
where
|
||||||
|
chomp bs = fromMaybe bs (BS.stripSuffix "\n" bs)
|
||||||
--
|
--
|
||||||
-- Turns the Base64url encoded JWT into Base64
|
-- Turns the Base64url encoded JWT into Base64
|
||||||
transformString :: Bool -> Text -> IO ByteString
|
transformString :: Bool -> ByteString -> IO ByteString
|
||||||
transformString False t = return . encodeUtf8 $ t
|
transformString False t = return t
|
||||||
transformString True t =
|
transformString True t =
|
||||||
case decode (encodeUtf8 $ strip $ replaceUrlChars t) of
|
case B64.decode $ encodeUtf8 $ strip $ replaceUrlChars $ decodeUtf8 t of
|
||||||
Left errMsg -> panic $ pack errMsg
|
Left errMsg -> panic $ pack errMsg
|
||||||
Right bs -> return bs
|
Right bs -> return bs
|
||||||
setSecret bs = conf {configJwtSecret = Just bs}
|
setSecret bs = conf {configJwtSecret = Just bs}
|
||||||
|
|||||||
+5
-5
@@ -93,13 +93,13 @@ totalTests=12
|
|||||||
echo "1..$totalTests"
|
echo "1..$totalTests"
|
||||||
|
|
||||||
readSecretFromFile word.noeol 'simple (no EOL)'
|
readSecretFromFile word.noeol 'simple (no EOL)'
|
||||||
skip readSecretFromFile word.txt 'simple'
|
readSecretFromFile word.txt 'simple'
|
||||||
readSecretFromFile ascii.noeol 'ASCII (no EOL)'
|
readSecretFromFile ascii.noeol 'ASCII (no EOL)'
|
||||||
skip readSecretFromFile ascii.txt 'ASCII'
|
readSecretFromFile ascii.txt 'ASCII'
|
||||||
readSecretFromFile utf8.noeol 'UTF-8 (no EOL)'
|
readSecretFromFile utf8.noeol 'UTF-8 (no EOL)'
|
||||||
skip readSecretFromFile utf8.txt 'UTF-8'
|
readSecretFromFile utf8.txt 'UTF-8'
|
||||||
skip readSecretFromFile binary.noeol 'binary'
|
readSecretFromFile binary.noeol 'binary'
|
||||||
skip readSecretFromFile binary.eol 'binary (+EOL)'
|
readSecretFromFile binary.eol 'binary (+EOL)'
|
||||||
|
|
||||||
readSecretFromFile word.b64 'Base64 (simple)'
|
readSecretFromFile word.b64 'Base64 (simple)'
|
||||||
readSecretFromFile ascii.b64 'Base64 (ASCII)'
|
readSecretFromFile ascii.b64 'Base64 (ASCII)'
|
||||||
|
|||||||
Reference in New Issue
Block a user