Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb25dd23c4 | ||
|
|
fafc203e1b | ||
|
|
3dcb276521 | ||
|
|
42103ab247 | ||
|
|
076d65a618 | ||
|
|
9a4e3889a9 | ||
|
|
c79a03a3af | ||
|
|
1beeab1e68 |
@ -37,13 +37,14 @@ import UnliftIO as Exports
|
|||||||
throwIO,
|
throwIO,
|
||||||
try,
|
try,
|
||||||
)
|
)
|
||||||
|
import qualified Data.Text.Encoding as T
|
||||||
|
|
||||||
-- | Apply a function on both elements of a pair
|
-- | Apply a function on both elements of a pair
|
||||||
both :: (a -> b) -> (a, a) -> (b, b)
|
both :: (a -> b) -> (a, a) -> (b, b)
|
||||||
both f (a, b) = (f a, f b)
|
both f (a, b) = (f a, f b)
|
||||||
|
|
||||||
showBS :: (Show a) => a -> ByteString
|
showBS :: Show a => a -> ByteString
|
||||||
showBS a = encodeUtf8 (show a :: Text)
|
showBS a = T.encodeUtf8 (show a :: Text)
|
||||||
|
|
||||||
toStrictBS :: LByteString -> ByteString
|
toStrictBS :: LByteString -> ByteString
|
||||||
toStrictBS = LB.toStrict
|
toStrictBS = LB.toStrict
|
||||||
|
|||||||
@ -41,13 +41,14 @@ module Network.Minio
|
|||||||
findFirst,
|
findFirst,
|
||||||
|
|
||||||
-- * Connecting to object storage
|
-- * Connecting to object storage
|
||||||
ConnectInfo,
|
ConnectInfo(..),
|
||||||
setRegion,
|
setRegion,
|
||||||
setCreds,
|
setCreds,
|
||||||
setCredsFrom,
|
setCredsFrom,
|
||||||
isConnectInfoSecure,
|
isConnectInfoSecure,
|
||||||
disableTLSCertValidation,
|
disableTLSCertValidation,
|
||||||
MinioConn,
|
MinioConn,
|
||||||
|
connect,
|
||||||
mkMinioConn,
|
mkMinioConn,
|
||||||
|
|
||||||
-- ** Connection helpers
|
-- ** Connection helpers
|
||||||
|
|||||||
@ -1068,7 +1068,7 @@ defaultS3ReqInfo =
|
|||||||
|
|
||||||
getS3Path :: Maybe Bucket -> Maybe Object -> ByteString
|
getS3Path :: Maybe Bucket -> Maybe Object -> ByteString
|
||||||
getS3Path b o =
|
getS3Path b o =
|
||||||
let segments = map encodeUtf8 $ catMaybes $ b : bool [] [o] (isJust b)
|
let segments = map TE.encodeUtf8 $ catMaybes $ b : bool [] [o] (isJust b)
|
||||||
in B.concat ["/", B.intercalate "/" segments]
|
in B.concat ["/", B.intercalate "/" segments]
|
||||||
|
|
||||||
type RegionMap = H.HashMap Bucket Region
|
type RegionMap = H.HashMap Bucket Region
|
||||||
@ -1084,10 +1084,12 @@ newtype Minio a = Minio
|
|||||||
Monad,
|
Monad,
|
||||||
MonadIO,
|
MonadIO,
|
||||||
MonadReader MinioConn,
|
MonadReader MinioConn,
|
||||||
MonadResource,
|
MonadResource
|
||||||
MonadUnliftIO
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
instance MonadUnliftIO Minio where
|
||||||
|
withRunInIO inner = Minio $ U.askUnliftIO >>= \(U.UnliftIO unliftIO) -> liftIO (inner $ \(Minio f) -> unliftIO f)
|
||||||
|
|
||||||
-- | MinioConn holds connection info and a connection pool to allow
|
-- | MinioConn holds connection info and a connection pool to allow
|
||||||
-- for efficient resource re-use.
|
-- for efficient resource re-use.
|
||||||
data MinioConn = MinioConn
|
data MinioConn = MinioConn
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import qualified Data.Aeson as Json
|
|||||||
import Data.ByteString.Builder (byteString, toLazyByteString)
|
import Data.ByteString.Builder (byteString, toLazyByteString)
|
||||||
import qualified Data.HashMap.Strict as H
|
import qualified Data.HashMap.Strict as H
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.Encoding as TE
|
||||||
import qualified Data.Time as Time
|
import qualified Data.Time as Time
|
||||||
import Lib.Prelude
|
import Lib.Prelude
|
||||||
import qualified Network.HTTP.Client as NClient
|
import qualified Network.HTTP.Client as NClient
|
||||||
@ -334,7 +335,7 @@ presignedPostPolicy p = do
|
|||||||
mkPair (PPCEquals k v) = Just (k, v)
|
mkPair (PPCEquals k v) = Just (k, v)
|
||||||
mkPair _ = Nothing
|
mkPair _ = Nothing
|
||||||
formFromPolicy =
|
formFromPolicy =
|
||||||
H.map encodeUtf8 $
|
H.map TE.encodeUtf8 $
|
||||||
H.fromList $
|
H.fromList $
|
||||||
mapMaybe
|
mapMaybe
|
||||||
mkPair
|
mkPair
|
||||||
|
|||||||
@ -109,6 +109,7 @@ where
|
|||||||
|
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.Encoding as TE
|
||||||
import Lib.Prelude
|
import Lib.Prelude
|
||||||
import qualified Network.HTTP.Conduit as NC
|
import qualified Network.HTTP.Conduit as NC
|
||||||
import qualified Network.HTTP.Types as HT
|
import qualified Network.HTTP.Types as HT
|
||||||
@ -389,7 +390,7 @@ putObjectPart bucket object uploadId partNumber headers payload = do
|
|||||||
srcInfoToHeaders :: SourceInfo -> [HT.Header]
|
srcInfoToHeaders :: SourceInfo -> [HT.Header]
|
||||||
srcInfoToHeaders srcInfo =
|
srcInfoToHeaders srcInfo =
|
||||||
( "x-amz-copy-source",
|
( "x-amz-copy-source",
|
||||||
encodeUtf8 $
|
TE.encodeUtf8 $
|
||||||
T.concat
|
T.concat
|
||||||
[ "/",
|
[ "/",
|
||||||
srcBucket srcInfo,
|
srcBucket srcInfo,
|
||||||
|
|||||||
@ -49,6 +49,8 @@ import Network.Minio.Data.Crypto
|
|||||||
import Network.Minio.Data.Time
|
import Network.Minio.Data.Time
|
||||||
import Network.Minio.Errors
|
import Network.Minio.Errors
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
|
import qualified Data.Text.Encoding as TE
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
-- these headers are not included in the string to sign when signing a
|
-- these headers are not included in the string to sign when signing a
|
||||||
-- request
|
-- request
|
||||||
@ -86,7 +88,7 @@ mkAuthHeader accessKey scope signedHeaderKeys sign =
|
|||||||
let authValue =
|
let authValue =
|
||||||
B.concat
|
B.concat
|
||||||
[ "AWS4-HMAC-SHA256 Credential=",
|
[ "AWS4-HMAC-SHA256 Credential=",
|
||||||
encodeUtf8 accessKey,
|
TE.encodeUtf8 accessKey,
|
||||||
"/",
|
"/",
|
||||||
scope,
|
scope,
|
||||||
", SignedHeaders=",
|
", SignedHeaders=",
|
||||||
@ -317,7 +319,7 @@ getSigningKey :: SignParams -> ByteString
|
|||||||
getSigningKey sp =
|
getSigningKey sp =
|
||||||
hmacSHA256RawBS "aws4_request"
|
hmacSHA256RawBS "aws4_request"
|
||||||
. hmacSHA256RawBS (toByteString $ spService sp)
|
. hmacSHA256RawBS (toByteString $ spService sp)
|
||||||
. hmacSHA256RawBS (encodeUtf8 $ fromMaybe "" $ spRegion sp)
|
. hmacSHA256RawBS (TE.encodeUtf8 $ fromMaybe "" $ spRegion sp)
|
||||||
. hmacSHA256RawBS (awsDateFormatBS $ spTimeStamp sp)
|
. hmacSHA256RawBS (awsDateFormatBS $ spTimeStamp sp)
|
||||||
$ B.concat ["AWS4", BA.convert $ spSecretKey sp]
|
$ B.concat ["AWS4", BA.convert $ spSecretKey sp]
|
||||||
|
|
||||||
|
|||||||
@ -184,10 +184,10 @@ httpLbs req mgr = do
|
|||||||
resp <- either throwIO return respE
|
resp <- either throwIO return respE
|
||||||
unless (isSuccessStatus $ NC.responseStatus resp) $
|
unless (isSuccessStatus $ NC.responseStatus resp) $
|
||||||
case contentTypeMay resp of
|
case contentTypeMay resp of
|
||||||
Just "application/xml" -> do
|
Just "application/xml" | expectBody -> do
|
||||||
sErr <- parseErrResponse $ NC.responseBody resp
|
sErr <- parseErrResponse $ NC.responseBody resp
|
||||||
throwIO sErr
|
throwIO sErr
|
||||||
Just "application/json" -> do
|
Just "application/json" | expectBody -> do
|
||||||
sErr <- parseErrResponseJSON $ NC.responseBody resp
|
sErr <- parseErrResponseJSON $ NC.responseBody resp
|
||||||
throwIO sErr
|
throwIO sErr
|
||||||
_ ->
|
_ ->
|
||||||
@ -204,6 +204,7 @@ httpLbs req mgr = do
|
|||||||
contentTypeMay resp =
|
contentTypeMay resp =
|
||||||
lookupHeader Hdr.hContentType $
|
lookupHeader Hdr.hContentType $
|
||||||
NC.responseHeaders resp
|
NC.responseHeaders resp
|
||||||
|
expectBody = NC.method req /= HT.methodHead
|
||||||
|
|
||||||
http ::
|
http ::
|
||||||
(MonadUnliftIO m, R.MonadResource m) =>
|
(MonadUnliftIO m, R.MonadResource m) =>
|
||||||
@ -215,7 +216,7 @@ http req mgr = do
|
|||||||
resp <- either throwIO return respE
|
resp <- either throwIO return respE
|
||||||
unless (isSuccessStatus $ NC.responseStatus resp) $
|
unless (isSuccessStatus $ NC.responseStatus resp) $
|
||||||
case contentTypeMay resp of
|
case contentTypeMay resp of
|
||||||
Just "application/xml" -> do
|
Just "application/xml" | expectBody -> do
|
||||||
respBody <- C.connect (NC.responseBody resp) CB.sinkLbs
|
respBody <- C.connect (NC.responseBody resp) CB.sinkLbs
|
||||||
sErr <- parseErrResponse respBody
|
sErr <- parseErrResponse respBody
|
||||||
throwIO sErr
|
throwIO sErr
|
||||||
@ -235,6 +236,7 @@ http req mgr = do
|
|||||||
contentTypeMay resp =
|
contentTypeMay resp =
|
||||||
lookupHeader Hdr.hContentType $
|
lookupHeader Hdr.hContentType $
|
||||||
NC.responseHeaders resp
|
NC.responseHeaders resp
|
||||||
|
expectBody = NC.method req /= HT.methodHead
|
||||||
|
|
||||||
-- Similar to mapConcurrently but limits the number of threads that
|
-- Similar to mapConcurrently but limits the number of threads that
|
||||||
-- can run using a quantity semaphore.
|
-- can run using a quantity semaphore.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user