Skip to content

Commit

Permalink
Replace CAS with funflow2 version
Browse files Browse the repository at this point in the history
Replaced the top-level cas directory with the version from funflow2.
  • Loading branch information
dorranh committed Jul 1, 2021
1 parent 98183e9 commit 915b8de
Show file tree
Hide file tree
Showing 33 changed files with 1,589 additions and 4,486 deletions.
467 changes: 261 additions & 206 deletions cas/hashable/src/Data/CAS/ContentHashable.hs

Large diffs are not rendered by default.

97 changes: 55 additions & 42 deletions cas/s3/src/Data/CAS/ContentHashable/S3.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}

-- | Hashing of S3 objects
--
Expand All @@ -12,16 +12,18 @@
module Data.CAS.ContentHashable.S3 where

import qualified Aws
import qualified Aws.S3 as S3
import Control.Monad ((>=>))
import Control.Monad.Trans.Resource (runResourceT)
import Data.Aeson
import Data.CAS.ContentHashable
import Data.Constraint
import Data.Reflection
import GHC.Generics (Generic)
import Network.HTTP.Conduit (newManager,
tlsManagerSettings)
import qualified Aws.S3 as S3
import Control.Monad ((>=>))
import Control.Monad.Trans.Resource (runResourceT)
import Data.Aeson
import Data.CAS.ContentHashable
import Data.Constraint
import Data.Reflection
import GHC.Generics (Generic)
import Network.HTTP.Conduit
( newManager,
tlsManagerSettings,
)

-- | Reference to an object in an S3 bucket
--
Expand All @@ -31,21 +33,25 @@ import Network.HTTP.Conduit (newManager,
-- - S3.Object (alias for Text)
-- - S3.ObjectInfo
data ObjectInBucket obj = ObjectInBucket
{ _oibBucket :: S3.Bucket
, _oibObject :: obj
} deriving (Show, Generic)
{ _oibBucket :: S3.Bucket,
_oibObject :: obj
}
deriving (Show, Generic)

-- | A lens to _oibBucket
oibBucket :: Functor f => (S3.Bucket -> f S3.Bucket) -> ObjectInBucket obj -> f (ObjectInBucket obj)
oibBucket f oib = rebuild <$> f (_oibBucket oib)
where rebuild b = oib{_oibBucket=b}
where
rebuild b = oib {_oibBucket = b}

-- | A lens to _oibObject
oibObject :: Functor f => (a -> f b) -> ObjectInBucket a -> f (ObjectInBucket b)
oibObject f oib = rebuild <$> f (_oibObject oib)
where rebuild o = oib{_oibObject=o}
where
rebuild o = oib {_oibObject = o}

instance FromJSON (ObjectInBucket S3.Object)

instance ToJSON (ObjectInBucket S3.Object)

class ObjectReference a where
Expand All @@ -72,28 +78,33 @@ instance ObjectReference S3.ObjectInfo where
-- We incorporate the bucket and name into this to give extra guarantees on
-- uniqueness, but we may be better abolishing this to deduplicate files
-- stored in multiple places.
instance (Given Aws.Configuration)
=> ContentHashable IO (ObjectInBucket S3.Object) where
contentHashUpdate ctx a = let
s3cfg = Aws.defServiceConfig :: S3.S3Configuration Aws.NormalQuery
in do
{- Set up a ResourceT region with an available HTTP manager. -}
mgr <- newManager tlsManagerSettings

{- Create a request object with S3.getObject and run the request with pureAws. -}
S3.GetObjectResponse { S3.gorMetadata = md } <- runResourceT $
Aws.pureAws given s3cfg mgr $
S3.getObject (_oibBucket a) (_oibObject a)

flip contentHashUpdate (_oibBucket a)
>=> flip contentHashUpdate (_oibObject a)
>=> flip contentHashUpdate (S3.omETag md)
$ ctx
instance
(Given Aws.Configuration) =>
ContentHashable IO (ObjectInBucket S3.Object)
where
contentHashUpdate ctx a =
let s3cfg = Aws.defServiceConfig :: S3.S3Configuration Aws.NormalQuery
in do
{- Set up a ResourceT region with an available HTTP manager. -}
mgr <- newManager tlsManagerSettings

{- Create a request object with S3.getObject and run the request with pureAws. -}
S3.GetObjectResponse {S3.gorMetadata = md} <-
runResourceT $
Aws.pureAws given s3cfg mgr $
S3.getObject (_oibBucket a) (_oibObject a)

flip contentHashUpdate (_oibBucket a)
>=> flip contentHashUpdate (_oibObject a)
>=> flip contentHashUpdate (S3.omETag md)
$ ctx

-- | Reified instance of the implication to allow us to use this as a
-- constraint.
instance (Given Aws.Configuration)
:=> ContentHashable IO (ObjectInBucket S3.Object) where
instance
(Given Aws.Configuration)
:=> ContentHashable IO (ObjectInBucket S3.Object)
where
ins = Sub Dict

-- | When we already have `ObjectInfo` (because we have, for example, queried
Expand All @@ -104,10 +115,12 @@ instance Monad m => ContentHashable m (ObjectInBucket S3.ObjectInfo) where
flip contentHashUpdate (_oibBucket a)
>=> flip contentHashUpdate (S3.objectKey $ _oibObject a)
>=> flip contentHashUpdate (S3.objectETag $ _oibObject a)
$ ctx
$ ctx

-- | Reified instance of the implication to allow us to use this as a
-- constraint.
instance (Given Aws.Configuration)
:=> ContentHashable IO (ObjectInBucket S3.ObjectInfo) where
instance
(Given Aws.Configuration)
:=> ContentHashable IO (ObjectInBucket S3.ObjectInfo)
where
ins = Sub Dict
2 changes: 1 addition & 1 deletion cas/store/cas-store.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: cas-store
Version: 1.0.1
Version: 1.1.0
Synopsis: A content-addressed storage
Description:
A content-addressed storage supporting a remote caching. The API mainly consists of the cacheKleisliIO function which takes a (a -> m b) function
Expand Down
4 changes: 4 additions & 0 deletions cas/store/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Version 1.1.0

- monad-control is no longer a dependency. cas-store is now using unliftio for
the same effect
Loading

0 comments on commit 915b8de

Please sign in to comment.