Add missing Haddock documentation (#110)

This commit is contained in:
Aditya Manthramurthy 2019-04-02 14:08:19 -07:00 committed by Harshavardhana
parent aa9072de39
commit b1a11de8b3
4 changed files with 112 additions and 32 deletions

View File

@ -14,7 +14,14 @@
-- limitations under the License. -- limitations under the License.
-- --
-- |
-- Module: Network.Minio
-- Copyright: (c) 2017-2019 Minio Dev Team
-- License: Apache 2.0
-- Maintainer: Minio Dev Team <dev@minio.io>
--
-- Types and functions to access S3 compatible object storage servers
-- like Minio.
module Network.Minio module Network.Minio
( (

View File

@ -85,9 +85,11 @@ awsRegionMap = Map.fromList [
, ("sa-east-1", "s3-sa-east-1.amazonaws.com") , ("sa-east-1", "s3-sa-east-1.amazonaws.com")
] ]
-- | Connection Info data type. To create a 'ConnectInfo' value, use one -- | Connection Info data type. To create a 'ConnectInfo' value,
-- of the provided smart constructors or override fields of the -- enable the @OverloadedStrings@ language extension and use the
-- Default instance. -- `IsString` instance to provide a URL, for example:
--
-- > let c :: ConnectInfo = "https://play.minio.io:9000"
data ConnectInfo = ConnectInfo { data ConnectInfo = ConnectInfo {
connectHost :: Text connectHost :: Text
, connectPort :: Int , connectPort :: Int
@ -111,6 +113,7 @@ instance IsString ConnectInfo where
, connectAutoDiscoverRegion = True , connectAutoDiscoverRegion = True
} }
-- | Contains access key and secret key to access object storage.
data Credentials = Credentials { cAccessKey :: Text data Credentials = Credentials { cAccessKey :: Text
, cSecretKey :: Text , cSecretKey :: Text
} deriving (Eq, Show) } deriving (Eq, Show)
@ -125,6 +128,7 @@ findFirst [] = return Nothing
findFirst (f:fs) = do c <- f findFirst (f:fs) = do c <- f
maybe (findFirst fs) (return . Just) c maybe (findFirst fs) (return . Just) c
-- | This Provider loads `Credentials` from @~\/.aws\/credentials@
fromAWSConfigFile :: Provider fromAWSConfigFile :: Provider
fromAWSConfigFile = do fromAWSConfigFile = do
credsE <- runExceptT $ do credsE <- runExceptT $ do
@ -140,18 +144,25 @@ fromAWSConfigFile = do
return $ Credentials akey skey return $ Credentials akey skey
return $ hush credsE return $ hush credsE
-- | This Provider loads `Credentials` from @AWS_ACCESS_KEY_ID@ and
-- @AWS_SECRET_ACCESS_KEY@ environment variables.
fromAWSEnv :: Provider fromAWSEnv :: Provider
fromAWSEnv = runMaybeT $ do fromAWSEnv = runMaybeT $ do
akey <- MaybeT $ Env.lookupEnv "AWS_ACCESS_KEY_ID" akey <- MaybeT $ Env.lookupEnv "AWS_ACCESS_KEY_ID"
skey <- MaybeT $ Env.lookupEnv "AWS_SECRET_ACCESS_KEY" skey <- MaybeT $ Env.lookupEnv "AWS_SECRET_ACCESS_KEY"
return $ Credentials (T.pack akey) (T.pack skey) return $ Credentials (T.pack akey) (T.pack skey)
-- | This Provider loads `Credentials` from @MINIO_ACCESS_KEY@ and
-- @MINIO_SECRET_KEY@ environment variables.
fromMinioEnv :: Provider fromMinioEnv :: Provider
fromMinioEnv = runMaybeT $ do fromMinioEnv = runMaybeT $ do
akey <- MaybeT $ Env.lookupEnv "MINIO_ACCESS_KEY" akey <- MaybeT $ Env.lookupEnv "MINIO_ACCESS_KEY"
skey <- MaybeT $ Env.lookupEnv "MINIO_SECRET_KEY" skey <- MaybeT $ Env.lookupEnv "MINIO_SECRET_KEY"
return $ Credentials (T.pack akey) (T.pack skey) return $ Credentials (T.pack akey) (T.pack skey)
-- | setCredsFrom retrieves access credentials from the first
-- `Provider` form the given list that succeeds and sets it in the
-- `ConnectInfo`.
setCredsFrom :: [Provider] -> ConnectInfo -> IO ConnectInfo setCredsFrom :: [Provider] -> ConnectInfo -> IO ConnectInfo
setCredsFrom ps ci = do pMay <- findFirst ps setCredsFrom ps ci = do pMay <- findFirst ps
maybe maybe
@ -159,12 +170,14 @@ setCredsFrom ps ci = do pMay <- findFirst ps
(return . (flip setCreds ci)) (return . (flip setCreds ci))
pMay pMay
-- | setCreds sets the given `Credentials` in the `ConnectInfo`.
setCreds :: Credentials -> ConnectInfo -> ConnectInfo setCreds :: Credentials -> ConnectInfo -> ConnectInfo
setCreds (Credentials accessKey secretKey) connInfo = setCreds (Credentials accessKey secretKey) connInfo =
connInfo { connectAccessKey = accessKey connInfo { connectAccessKey = accessKey
, connectSecretKey = secretKey , connectSecretKey = secretKey
} }
-- | Set the S3 region parameter in the `ConnectInfo`
setRegion :: Region -> ConnectInfo -> ConnectInfo setRegion :: Region -> ConnectInfo -> ConnectInfo
setRegion r connInfo = connInfo { connectRegion = r setRegion r connInfo = connInfo { connectRegion = r
, connectAutoDiscoverRegion = False , connectAutoDiscoverRegion = False
@ -218,9 +231,9 @@ type Region = Text
-- | A type alias to represent an Entity-Tag returned by S3-compatible APIs. -- | A type alias to represent an Entity-Tag returned by S3-compatible APIs.
type ETag = Text type ETag = Text
-- | -- | Data type for options in PutObject call. Start with the empty
-- Data type represents various options specified for PutObject call. -- `defaultPutObjectOptions` and use various the various poo*
-- To specify PutObject options use the poo* accessors. -- accessors.
data PutObjectOptions = PutObjectOptions { data PutObjectOptions = PutObjectOptions {
-- | Set a standard MIME type describing the format of the object. -- | Set a standard MIME type describing the format of the object.
pooContentType :: Maybe Text pooContentType :: Maybe Text
@ -235,8 +248,8 @@ data PutObjectOptions = PutObjectOptions {
, pooCacheControl :: Maybe Text , pooCacheControl :: Maybe Text
-- | Set to describe the language(s) intended for the audience. -- | Set to describe the language(s) intended for the audience.
, pooContentLanguage :: Maybe Text , pooContentLanguage :: Maybe Text
-- | Set to 'STANDARD' or 'REDUCED_REDUNDANCY' depending on your -- | Set to @STANDARD@ or @REDUCED_REDUNDANCY@ depending on your
-- performance needs, storage class is 'STANDARD' by default (i.e -- performance needs, storage class is @STANDARD@ by default (i.e
-- when Nothing is passed). -- when Nothing is passed).
, pooStorageClass :: Maybe Text , pooStorageClass :: Maybe Text
-- | Set user defined metadata to store with the object. -- | Set user defined metadata to store with the object.
@ -245,7 +258,7 @@ data PutObjectOptions = PutObjectOptions {
, pooNumThreads :: Maybe Word , pooNumThreads :: Maybe Word
} deriving (Show, Eq) } deriving (Show, Eq)
-- Provide a default instance -- | Provide default `PutObjectOptions`.
defaultPutObjectOptions :: PutObjectOptions defaultPutObjectOptions :: PutObjectOptions
defaultPutObjectOptions = PutObjectOptions Nothing Nothing Nothing Nothing Nothing Nothing [] Nothing defaultPutObjectOptions = PutObjectOptions Nothing Nothing Nothing Nothing Nothing Nothing [] Nothing
@ -347,37 +360,56 @@ data ListObjectsV1Result = ListObjectsV1Result {
} deriving (Show, Eq) } deriving (Show, Eq)
-- | Represents information about an object. -- | Represents information about an object.
data ObjectInfo = ObjectInfo { data ObjectInfo = ObjectInfo
oiObject :: Object { oiObject :: Object -- ^ Oject key
, oiModTime :: UTCTime , oiModTime :: UTCTime -- ^ Mdification time of the object
, oiETag :: ETag , oiETag :: ETag -- ^ ETag of the object
, oiSize :: Int64 , oiSize :: Int64 -- ^ Size of the object in bytes
, oiMetadata :: Map.Map Text Text , oiMetadata :: Map.Map Text Text -- ^ A map of the metadata
-- key-value pairs
} deriving (Show, Eq) } deriving (Show, Eq)
-- | Represents source object in server-side copy object -- | Represents source object in server-side copy object
data SourceInfo = SourceInfo { data SourceInfo = SourceInfo
srcBucket :: Text { srcBucket :: Text -- ^ Bucket containing the source object
, srcObject :: Text , srcObject :: Text -- ^ Source object key
, srcRange :: Maybe (Int64, Int64) , srcRange :: Maybe (Int64, Int64) -- ^ Source object
, srcIfMatch :: Maybe Text -- byte-range
, srcIfNoneMatch :: Maybe Text -- (inclusive)
, srcIfModifiedSince :: Maybe UTCTime , srcIfMatch :: Maybe Text -- ^ ETag condition on source -
, srcIfUnmodifiedSince :: Maybe UTCTime -- object is copied only if the
-- source object's ETag matches
-- this value.
, srcIfNoneMatch :: Maybe Text -- ^ ETag not match condition
-- on source - object is copied
-- if ETag does not match this
-- value.
, srcIfModifiedSince :: Maybe UTCTime -- ^ Copy source object only
-- if the source has been
-- modified since this time.
, srcIfUnmodifiedSince :: Maybe UTCTime -- ^ Copy source object only
-- if the source has been
-- un-modified since this
-- given time.
} deriving (Show, Eq) } deriving (Show, Eq)
-- | Provide a default for `SourceInfo`
defaultSourceInfo :: SourceInfo defaultSourceInfo :: SourceInfo
defaultSourceInfo = SourceInfo "" "" Nothing Nothing Nothing Nothing Nothing defaultSourceInfo = SourceInfo "" "" Nothing Nothing Nothing Nothing Nothing
-- | Represents destination object in server-side copy object -- | Represents destination object in server-side copy object
data DestinationInfo = DestinationInfo data DestinationInfo = DestinationInfo
{ dstBucket :: Text { dstBucket :: Text -- ^ Destination bucket
, dstObject :: Text , dstObject :: Text -- ^ Destination object key
} deriving (Show, Eq) } deriving (Show, Eq)
-- | Provide a default for `DestinationInfo`
defaultDestinationInfo :: DestinationInfo defaultDestinationInfo :: DestinationInfo
defaultDestinationInfo = DestinationInfo "" "" defaultDestinationInfo = DestinationInfo "" ""
-- | Data type for options when getting an object from the
-- service. Start with the empty `defaultGetObjectOptions` and modify
-- it using the goo* functions.
data GetObjectOptions = GetObjectOptions { data GetObjectOptions = GetObjectOptions {
-- | Set object's data of given offset begin and end, -- | Set object's data of given offset begin and end,
-- [ByteRangeFromTo 0 9] means first ten bytes of the source object. -- [ByteRangeFromTo 0 9] means first ten bytes of the source object.
@ -394,6 +426,7 @@ data GetObjectOptions = GetObjectOptions {
, gooIfModifiedSince :: Maybe UTCTime , gooIfModifiedSince :: Maybe UTCTime
} deriving (Show, Eq) } deriving (Show, Eq)
-- | Provide default `GetObjectOptions`.
defaultGetObjectOptions :: GetObjectOptions defaultGetObjectOptions :: GetObjectOptions
defaultGetObjectOptions = GetObjectOptions Nothing Nothing Nothing Nothing Nothing defaultGetObjectOptions = GetObjectOptions Nothing Nothing Nothing Nothing Nothing
@ -451,24 +484,33 @@ textToEvent t = case t of
_ -> Nothing _ -> Nothing
-- | Filter data type - part of notification configuration
data Filter = Filter data Filter = Filter
{ fFilter :: FilterKey { fFilter :: FilterKey
} deriving (Show, Eq) } deriving (Show, Eq)
-- | defaultFilter is empty, used to create a notification
-- configuration.
defaultFilter :: Filter defaultFilter :: Filter
defaultFilter = Filter defaultFilterKey defaultFilter = Filter defaultFilterKey
-- | FilterKey contains FilterRules, and is part of a Filter.
data FilterKey = FilterKey data FilterKey = FilterKey
{ fkKey :: FilterRules { fkKey :: FilterRules
} deriving (Show, Eq) } deriving (Show, Eq)
-- | defaultFilterKey is empty, used to create notification
-- configuration.
defaultFilterKey :: FilterKey defaultFilterKey :: FilterKey
defaultFilterKey = FilterKey defaultFilterRules defaultFilterKey = FilterKey defaultFilterRules
-- | FilterRules represents a collection of `FilterRule`s.
data FilterRules = FilterRules data FilterRules = FilterRules
{ frFilterRules :: [FilterRule] { frFilterRules :: [FilterRule]
} deriving (Show, Eq) } deriving (Show, Eq)
-- | defaultFilterRules is empty, used to create notification
-- configuration.
defaultFilterRules :: FilterRules defaultFilterRules :: FilterRules
defaultFilterRules = FilterRules [] defaultFilterRules = FilterRules []
@ -479,14 +521,15 @@ defaultFilterRules = FilterRules []
-- > let suffixRule = FilterRule "suffix" ".jpg" -- > let suffixRule = FilterRule "suffix" ".jpg"
-- > let prefixRule = FilterRule "prefix" "images/" -- > let prefixRule = FilterRule "prefix" "images/"
-- --
-- The `suffixRule` restricts the notification to be triggered only -- The @suffixRule@ restricts the notification to be triggered only
-- for objects having a suffix of ".jpg", and the `prefixRule` -- for objects having a suffix of ".jpg", and the @prefixRule@
-- restricts it to objects having a prefix of "images/". -- restricts it to objects having a prefix of "images/".
data FilterRule = FilterRule data FilterRule = FilterRule
{ frName :: Text { frName :: Text
, frValue :: Text , frValue :: Text
} deriving (Show, Eq) } deriving (Show, Eq)
-- | Arn is an alias of Text
type Arn = Text type Arn = Text
-- | A data-type representing the configuration for a particular -- | A data-type representing the configuration for a particular
@ -510,6 +553,7 @@ data Notification = Notification
, nCloudFunctionConfigurations :: [NotificationConfig] , nCloudFunctionConfigurations :: [NotificationConfig]
} deriving (Eq, Show) } deriving (Eq, Show)
-- | The default notification configuration is empty.
defaultNotification :: Notification defaultNotification :: Notification
defaultNotification = Notification [] [] [] defaultNotification = Notification [] [] []
@ -540,11 +584,15 @@ data InputSerialization = InputSerialization
, isFormatInfo :: InputFormatInfo , isFormatInfo :: InputFormatInfo
} deriving (Eq, Show) } deriving (Eq, Show)
-- | Data type representing the compression setting in a Select
-- request.
data CompressionType = CompressionTypeNone data CompressionType = CompressionTypeNone
| CompressionTypeGzip | CompressionTypeGzip
| CompressionTypeBzip2 | CompressionTypeBzip2
deriving (Eq, Show) deriving (Eq, Show)
-- | Data type representing input object format information in a
-- Select request.
data InputFormatInfo = InputFormatCSV CSVInputProp data InputFormatInfo = InputFormatCSV CSVInputProp
| InputFormatJSON JSONInputProp | InputFormatJSON JSONInputProp
| InputFormatParquet | InputFormatParquet
@ -634,15 +682,19 @@ instance Monoid CSVProp where
defaultCSVProp :: CSVProp defaultCSVProp :: CSVProp
defaultCSVProp = mempty defaultCSVProp = mempty
-- | Specify the CSV record delimiter property.
recordDelimiter :: Text -> CSVProp recordDelimiter :: Text -> CSVProp
recordDelimiter = CSVProp . H.singleton "RecordDelimiter" recordDelimiter = CSVProp . H.singleton "RecordDelimiter"
-- | Specify the CSV field delimiter property.
fieldDelimiter :: Text -> CSVProp fieldDelimiter :: Text -> CSVProp
fieldDelimiter = CSVProp . H.singleton "FieldDelimiter" fieldDelimiter = CSVProp . H.singleton "FieldDelimiter"
-- | Specify the CSV quote character property.
quoteCharacter :: Text -> CSVProp quoteCharacter :: Text -> CSVProp
quoteCharacter = CSVProp . H.singleton "QuoteCharacter" quoteCharacter = CSVProp . H.singleton "QuoteCharacter"
-- | Specify the CSV quote-escape character property.
quoteEscapeCharacter :: Text -> CSVProp quoteEscapeCharacter :: Text -> CSVProp
quoteEscapeCharacter = CSVProp . H.singleton "QuoteEscapeCharacter" quoteEscapeCharacter = CSVProp . H.singleton "QuoteEscapeCharacter"
@ -654,6 +706,7 @@ data FileHeaderInfo
| FileHeaderIgnore -- ^ Header are present, but should be ignored | FileHeaderIgnore -- ^ Header are present, but should be ignored
deriving (Eq, Show) deriving (Eq, Show)
-- | Specify the CSV file header info property.
fileHeaderInfo :: FileHeaderInfo -> CSVProp fileHeaderInfo :: FileHeaderInfo -> CSVProp
fileHeaderInfo = CSVProp . H.singleton "FileHeaderInfo" . toString fileHeaderInfo = CSVProp . H.singleton "FileHeaderInfo" . toString
where where
@ -661,9 +714,12 @@ fileHeaderInfo = CSVProp . H.singleton "FileHeaderInfo" . toString
toString FileHeaderUse = "USE" toString FileHeaderUse = "USE"
toString FileHeaderIgnore = "IGNORE" toString FileHeaderIgnore = "IGNORE"
-- | Specify the CSV comment character property. Lines starting with
-- this character are ignored by the server.
commentCharacter :: Text -> CSVProp commentCharacter :: Text -> CSVProp
commentCharacter = CSVProp . H.singleton "Comments" commentCharacter = CSVProp . H.singleton "Comments"
-- | Allow quoted record delimiters inside a row using this property.
allowQuotedRecordDelimiter :: CSVProp allowQuotedRecordDelimiter :: CSVProp
allowQuotedRecordDelimiter = CSVProp $ H.singleton "AllowQuotedRecordDelimiter" "TRUE" allowQuotedRecordDelimiter = CSVProp $ H.singleton "AllowQuotedRecordDelimiter" "TRUE"
@ -698,6 +754,7 @@ quoteFields q = CSVProp $ H.singleton "QuoteFields" $
QuoteFieldsAsNeeded -> "ASNEEDED" QuoteFieldsAsNeeded -> "ASNEEDED"
QuoteFieldsAlways -> "ALWAYS" QuoteFieldsAlways -> "ALWAYS"
-- | Represent the QuoteField setting.
data QuoteFields = QuoteFieldsAsNeeded | QuoteFieldsAlways data QuoteFields = QuoteFieldsAsNeeded | QuoteFieldsAlways
deriving (Eq, Show) deriving (Eq, Show)
@ -732,12 +789,15 @@ msgHeaderValueType = 7
type MessageHeader = (MsgHeaderName, Text) type MessageHeader = (MsgHeaderName, Text)
-- | Represent the progress event returned in the Select response.
data Progress = Progress { pBytesScanned :: Int64 data Progress = Progress { pBytesScanned :: Int64
, pBytesProcessed :: Int64 , pBytesProcessed :: Int64
, pBytesReturned :: Int64 , pBytesReturned :: Int64
} }
deriving (Eq, Show) deriving (Eq, Show)
-- | Represent the stats event returned at the end of the Select
-- response.
type Stats = Progress type Stats = Progress
-------------------------------------------------------------------------- --------------------------------------------------------------------------
@ -791,6 +851,8 @@ type UrlExpiry = Int
type RegionMap = Map.Map Bucket Region type RegionMap = Map.Map Bucket Region
-- | The Minio Monad - all computations accessing object storage
-- happens in it.
newtype Minio a = Minio { newtype Minio a = Minio {
unMinio :: ReaderT MinioConn (ResourceT IO) a unMinio :: ReaderT MinioConn (ResourceT IO) a
} }
@ -808,7 +870,8 @@ instance MonadUnliftIO Minio where
withUnliftIO $ \u -> withUnliftIO $ \u ->
return (UnliftIO (unliftIO u . flip runReaderT r . unMinio)) return (UnliftIO (unliftIO u . flip runReaderT r . unMinio))
-- | MinioConn holds connection info and a connection pool -- | MinioConn holds connection info and a connection pool to allow
-- for efficient resource re-use.
data MinioConn = MinioConn data MinioConn = MinioConn
{ mcConnInfo :: ConnectInfo { mcConnInfo :: ConnectInfo
, mcConnManager :: NC.Manager , mcConnManager :: NC.Manager
@ -826,7 +889,9 @@ instance HasSvcNamespace MinioConn where
"http://s3.amazonaws.com/doc/2006-03-01/" "http://s3.amazonaws.com/doc/2006-03-01/"
-- | Takes connection information and returns a connection object to -- | Takes connection information and returns a connection object to
-- be passed to 'runMinio' -- be passed to 'runMinio'. The returned value can be kept in the
-- application environment and passed to `runMinioWith` whenever
-- object storage is accessed.
connect :: ConnectInfo -> IO MinioConn connect :: ConnectInfo -> IO MinioConn
connect ci = do connect ci = do
let settings | connectIsSecure ci = NC.tlsManagerSettings let settings | connectIsSecure ci = NC.tlsManagerSettings
@ -834,7 +899,9 @@ connect ci = do
mgr <- NC.newManager settings mgr <- NC.newManager settings
mkMinioConn ci mgr mkMinioConn ci mgr
-- | Run the computation accessing object storage using the given
-- `MinioConn`. This reuses connections, but otherwise it is similar
-- to `runMinio`.
runMinioWith :: MinioConn -> Minio a -> IO (Either MinioErr a) runMinioWith :: MinioConn -> Minio a -> IO (Either MinioErr a)
runMinioWith conn m = runResourceT . flip runReaderT conn . unMinio $ runMinioWith conn m = runResourceT . flip runReaderT conn . unMinio $
fmap Right m `U.catches` fmap Right m `U.catches`
@ -849,6 +916,8 @@ runMinioWith conn m = runResourceT . flip runReaderT conn . unMinio $
handlerFE = return . Left . MErrIO handlerFE = return . Left . MErrIO
handlerValidation = return . Left . MErrValidation handlerValidation = return . Left . MErrValidation
-- | Given `ConnectInfo` and a HTTP connection manager, create a
-- `MinioConn`.
mkMinioConn :: ConnectInfo -> NC.Manager -> IO MinioConn mkMinioConn :: ConnectInfo -> NC.Manager -> IO MinioConn
mkMinioConn ci mgr = do mkMinioConn ci mgr = do
rMapMVar <- M.newMVar Map.empty rMapMVar <- M.newMVar Map.empty

View File

@ -47,7 +47,7 @@ import Network.Minio.Utils
-- --
-- For streams also, a size may be provided. This is useful to limit -- For streams also, a size may be provided. This is useful to limit
-- the input - if it is not provided, upload will continue until the -- the input - if it is not provided, upload will continue until the
-- stream ends or the object reaches `maxObjectsize` size. -- stream ends or the object reaches `maxObjectSize` size.
data ObjectData m data ObjectData m
= ODFile FilePath (Maybe Int64) -- ^ Takes filepath and optional = ODFile FilePath (Maybe Int64) -- ^ Takes filepath and optional
-- size. -- size.

View File

@ -145,6 +145,10 @@ putBucket bucket location = do
maxSinglePutObjectSizeBytes :: Int64 maxSinglePutObjectSizeBytes :: Int64
maxSinglePutObjectSizeBytes = 5 * 1024 * 1024 * 1024 maxSinglePutObjectSizeBytes = 5 * 1024 * 1024 * 1024
-- | PUT an object into the service. This function performs a single
-- PUT object call and uses a strict ByteString as the object
-- data. `putObjectSingle` is preferable as the object data will not
-- be resident in memory.
putObjectSingle' :: Bucket -> Object -> [HT.Header] -> ByteString -> Minio ETag putObjectSingle' :: Bucket -> Object -> [HT.Header] -> ByteString -> Minio ETag
putObjectSingle' bucket object headers bs = do putObjectSingle' bucket object headers bs = do
let size = fromIntegral (BS.length bs) let size = fromIntegral (BS.length bs)