Move region to RequestInfo
Region is a request specific attribute, mostly applies to bucket operations.
This commit is contained in:
parent
342d0bc8ff
commit
45d5f9e676
@ -94,4 +94,4 @@ mkStreamRequest ri = do
|
||||
requestInfo :: Method -> Maybe Bucket -> Maybe Object
|
||||
-> Query -> [Header] -> Payload
|
||||
-> RequestInfo
|
||||
requestInfo m b o q h p = RequestInfo m b o q h p ""
|
||||
requestInfo m b o q h p = RequestInfo m b o q h p "" Nothing
|
||||
|
||||
@ -9,6 +9,7 @@ module Network.Minio.Data
|
||||
, Location
|
||||
, BucketInfo(..)
|
||||
, getPathFromRI
|
||||
, getRegionFromRI
|
||||
, Minio
|
||||
, MinioErr(..)
|
||||
, runMinio
|
||||
@ -38,12 +39,11 @@ data ConnectInfo = ConnectInfo {
|
||||
, connectAccessKey :: Text
|
||||
, connectSecretKey :: Text
|
||||
, connectIsSecure :: Bool
|
||||
, connectRegion :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
defaultConnectInfo :: ConnectInfo
|
||||
defaultConnectInfo =
|
||||
ConnectInfo "localhost" 9000 "minio" "minio123" False "us-east-1"
|
||||
ConnectInfo "localhost" 9000 "minio" "minio123" False
|
||||
|
||||
type Bucket = Text
|
||||
type Object = Text
|
||||
@ -68,6 +68,7 @@ data RequestInfo = RequestInfo {
|
||||
, headers :: [Header]
|
||||
, payload :: Payload
|
||||
, payloadHash :: ByteString
|
||||
, region :: Maybe Location
|
||||
}
|
||||
|
||||
|
||||
@ -77,6 +78,9 @@ getPathFromRI ri = B.concat $ parts
|
||||
objPart = maybe [] (\o -> ["/", encodeUtf8 o]) $ object ri
|
||||
parts = maybe ["/"] (\b -> "/" : encodeUtf8 b : objPart) $ bucket ri
|
||||
|
||||
getRegionFromRI :: RequestInfo -> Text
|
||||
getRegionFromRI ri = maybe "us-east-1" identity (region ri)
|
||||
|
||||
data MinioErr = MErrMsg ByteString
|
||||
| MErrHttp HttpException
|
||||
| MErrXml ByteString
|
||||
|
||||
@ -49,4 +49,3 @@ putBucket bucket location = do
|
||||
let httpStatus = NC.responseStatus resp
|
||||
when (httpStatus /= HT.ok200) $
|
||||
throwError $ MErrXml $ LBS.toStrict $ NC.responseBody resp
|
||||
return ()
|
||||
|
||||
@ -88,7 +88,7 @@ signV4AtTime ts ci ri =
|
||||
|
||||
authHeader = (mk "Authorization", authHeaderValue)
|
||||
|
||||
scope = getScope ts ci
|
||||
scope = getScope ts ri
|
||||
|
||||
authHeaderValue = B.concat [
|
||||
"AWS4-HMAC-SHA256 Credential=",
|
||||
@ -105,7 +105,7 @@ signV4AtTime ts ci ri =
|
||||
|
||||
signingKey = hmacSHA256RawBS "aws4_request"
|
||||
. hmacSHA256RawBS "s3"
|
||||
. hmacSHA256RawBS (encodeUtf8 $ connectRegion ci)
|
||||
. hmacSHA256RawBS (encodeUtf8 $ getRegionFromRI ri)
|
||||
. hmacSHA256RawBS (awsDateFormatBS ts)
|
||||
$ (B.concat ["AWS4", encodeUtf8 $ connectSecretKey ci])
|
||||
|
||||
@ -119,10 +119,10 @@ signV4AtTime ts ci ri =
|
||||
canonicalRequest = getCanonicalRequest ri headersToSign
|
||||
|
||||
|
||||
getScope :: UTCTime -> ConnectInfo -> ByteString
|
||||
getScope ts ci = B.intercalate "/" $ [
|
||||
getScope :: UTCTime -> RequestInfo -> ByteString
|
||||
getScope ts ri = B.intercalate "/" $ [
|
||||
pack $ Time.formatTime Time.defaultTimeLocale "%Y%m%d" ts,
|
||||
encodeUtf8 $ connectRegion ci, "s3", "aws4_request"
|
||||
encodeUtf8 $ getRegionFromRI ri, "s3", "aws4_request"
|
||||
]
|
||||
|
||||
getHeadersToSign :: [Header] -> [(ByteString, ByteString)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user