packages feed

do-spaces-0.2: src/Network/DO/Spaces/Actions/SetObjectACLs.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

-- |
-- Module      : Network.DO.Spaces.Actions.SetObjectACLs
-- Copyright   : (c) 2021 Rory Tyler Hayford
-- License     : BSD-3-Clause
-- Maintainer  : rory.hayford@protonmail.com
-- Stability   : experimental
-- Portability : GHC
--
module Network.DO.Spaces.Actions.SetObjectACLs
    ( SetObjectACLs(..)
    , SetObjectACLsResponse
    ) where

import           Control.Monad.Reader        ( MonadReader(ask) )

import           Data.ByteString             ( ByteString )

import           GHC.Generics                ( Generic )

import           Network.DO.Spaces.Types
import           Network.DO.Spaces.Utils
import           Network.HTTP.Client.Conduit ( RequestBody(RequestBodyLBS) )
import qualified Network.HTTP.Types          as H

-- | Get the full Access Control List associated with a 'Bucket'
data SetObjectACLs = SetObjectACLs
    { bucket :: Bucket
    , object :: Object
    , owner  :: Owner -- ^ The object owner
    , acls   :: [Grant]
    }
    deriving stock ( Show, Eq, Generic )

type SetObjectACLsResponse = ()

instance MonadSpaces m => Action m SetObjectACLs where
    type ConsumedResponse SetObjectACLs = SetObjectACLsResponse

    buildRequest soa@SetObjectACLs { .. } = do
        spaces <- ask
        pure SpacesRequestBuilder
             { bucket         = Just bucket
             , object         = Just object
             , method         = Just PUT
             , body           = Just . RequestBodyLBS $ writeACLSetter soa
             , overrideRegion = Nothing
             , queryString    = Nothing
             , headers        = mempty
             , subresources   = Just
                   $ H.toQuery [ ( "acl" :: ByteString
                                 , Nothing :: Maybe ByteString
                                 )
                               ]
             , ..
             }

    consumeResponse _ = pure ()