Skip to content

Commit

Permalink
Accept GetObjectOptions in statObject (minio#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
donatello authored and harshavardhana committed Apr 14, 2019
1 parent af3b75e commit bd455b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/Network/Minio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,10 @@ getObject :: Bucket -> Object -> GetObjectOptions
getObject bucket object opts = snd <$> getObject' bucket object []
(gooToHeaders opts)

-- | Get an object's metadata from the object store.
statObject :: Bucket -> Object -> Minio ObjectInfo
statObject = headObject
-- | Get an object's metadata from the object store. It accepts the
-- same options as GetObject.
statObject :: Bucket -> Object -> GetObjectOptions -> Minio ObjectInfo
statObject b o opts = headObject b o $ gooToHeaders opts

-- | Creates a new bucket in the object store. The Region can be
-- optionally specified. If not specified, it will use the region
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Minio/CopyObject.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ copyObjectInternal b' o srcInfo = do
sObject = srcObject srcInfo

-- get source object size with a head request
oi <- headObject sBucket sObject
oi <- headObject sBucket sObject []
let srcSize = oiSize oi

-- check that byte offsets are valid if specified in cps
Expand Down
5 changes: 3 additions & 2 deletions src/Network/Minio/S3API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,12 @@ listIncompleteParts' bucket object uploadId maxParts partNumMarker = do
]

-- | Get metadata of an object.
headObject :: Bucket -> Object -> Minio ObjectInfo
headObject bucket object = do
headObject :: Bucket -> Object -> [HT.Header] -> Minio ObjectInfo
headObject bucket object reqHeaders = do
resp <- executeRequest $ defaultS3ReqInfo { riMethod = HT.methodHead
, riBucket = Just bucket
, riObject = Just object
, riHeaders = reqHeaders
}

let
Expand Down
20 changes: 10 additions & 10 deletions test/LiveServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ basicTests = funTestWithBucket "Basic tests" $
fPutObject bucket object inputFile defaultPutObjectOptions

step "get metadata of the object"
res <- statObject bucket object
res <- statObject bucket object defaultGetObjectOptions
liftIO $ (oiSize res) @?= 0

step "delete object"
Expand Down Expand Up @@ -650,7 +650,7 @@ putObjectContentTypeTest = funTestWithBucket "putObject contentType tests" $
}

-- retrieve obj info to check
oi <- headObject bucket object
oi <- headObject bucket object []
let m = oiMetadata oi

step "Validate content-type"
Expand All @@ -661,7 +661,7 @@ putObjectContentTypeTest = funTestWithBucket "putObject contentType tests" $
pooContentEncoding = Just "identity"
}

oiCE <- headObject bucket object
oiCE <- headObject bucket object []
let m' = oiMetadata oiCE

step "Validate content-encoding"
Expand All @@ -686,7 +686,7 @@ putObjectContentLanguageTest = funTestWithBucket "putObject contentLanguage test
}

-- retrieve obj info to check
oi <- headObject bucket object
oi <- headObject bucket object []
let m = oiMetadata oi

step "Validate content-language"
Expand Down Expand Up @@ -722,7 +722,7 @@ putObjectStorageClassTest = funTestWithBucket "putObject storageClass tests" $
removeObject bucket object

-- retrieve obj info to check
oi' <- headObject bucket object'
oi' <- headObject bucket object' []
let m' = oiMetadata oi'

step "Validate x-amz-storage-class rrs"
Expand Down Expand Up @@ -757,7 +757,7 @@ copyObjectTests = funTestWithBucket "copyObject related tests" $
(etag, modTime) <- copyObjectSingle bucket objCopy srcInfo []

-- retrieve obj info to check
oi <- headObject bucket objCopy
oi <- headObject bucket objCopy []
let t = oiModTime oi
let e = oiETag oi
let s = oiSize oi
Expand Down Expand Up @@ -798,7 +798,7 @@ copyObjectTests = funTestWithBucket "copyObject related tests" $
void $ completeMultipartUpload bucket copyObj uid parts

step "verify copied object size"
oi' <- headObject bucket copyObj
oi' <- headObject bucket copyObj []
let s' = oiSize oi'

liftIO $ (s' == mb15) @? "Size failed to match"
Expand All @@ -822,7 +822,7 @@ copyObjectTests = funTestWithBucket "copyObject related tests" $
copyObject defaultDestinationInfo {dstBucket = bucket, dstObject = cp} defaultSourceInfo {srcBucket = bucket, srcObject = src}

step "verify uploaded objects"
uploadedSizes <- fmap oiSize <$> forM copyObjs (headObject bucket)
uploadedSizes <- fmap oiSize <$> forM copyObjs (\o -> headObject bucket o [])

liftIO $ (sizes == uploadedSizes) @? "Uploaded obj sizes failed to match"

Expand All @@ -844,7 +844,7 @@ copyObjectTests = funTestWithBucket "copyObject related tests" $
}

step "verify uploaded object"
cSize <- oiSize <$> headObject bucket copyObj
cSize <- oiSize <$> headObject bucket copyObj []

liftIO $ (cSize == 10 * 1024 * 1024) @? "Uploaded obj size mismatched!"

Expand All @@ -870,7 +870,7 @@ getNPutSSECTest =
fPutObject bucket obj rFile putOpts

step "Stat object without key - should fail"
headRes <- try $ statObject bucket obj
headRes <- try $ statObject bucket obj defaultGetObjectOptions
case headRes of
Right _ -> liftIO $ assertFailure "Cannot perform head object on encrypted object without specifying key"
Left ex@(NC.HttpExceptionRequest _ (NC.StatusCodeException rsp _))
Expand Down

0 comments on commit bd455b2

Please sign in to comment.