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

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

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

import           Data.ByteString         ( ByteString )

import           GHC.Generics            ( Generic )

import           Network.DO.Spaces.Types
                 ( ACLResponse
                 , Action(..)
                 , Bucket
                 , MonadSpaces
                 , Object
                 , SpacesRequestBuilder(..)
                 )
import           Network.DO.Spaces.Utils ( aclP, xmlDocCursor )
import qualified Network.HTTP.Types      as H

-- | Get the full Access Control List associated with a 'Bucket'
data GetObjectACLs = GetObjectACLs { GetObjectACLs -> Bucket
bucket :: Bucket, GetObjectACLs -> Object
object :: Object }
    deriving ( Int -> GetObjectACLs -> ShowS
[GetObjectACLs] -> ShowS
GetObjectACLs -> String
(Int -> GetObjectACLs -> ShowS)
-> (GetObjectACLs -> String)
-> ([GetObjectACLs] -> ShowS)
-> Show GetObjectACLs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetObjectACLs] -> ShowS
$cshowList :: [GetObjectACLs] -> ShowS
show :: GetObjectACLs -> String
$cshow :: GetObjectACLs -> String
showsPrec :: Int -> GetObjectACLs -> ShowS
$cshowsPrec :: Int -> GetObjectACLs -> ShowS
Show, GetObjectACLs -> GetObjectACLs -> Bool
(GetObjectACLs -> GetObjectACLs -> Bool)
-> (GetObjectACLs -> GetObjectACLs -> Bool) -> Eq GetObjectACLs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetObjectACLs -> GetObjectACLs -> Bool
$c/= :: GetObjectACLs -> GetObjectACLs -> Bool
== :: GetObjectACLs -> GetObjectACLs -> Bool
$c== :: GetObjectACLs -> GetObjectACLs -> Bool
Eq, (forall x. GetObjectACLs -> Rep GetObjectACLs x)
-> (forall x. Rep GetObjectACLs x -> GetObjectACLs)
-> Generic GetObjectACLs
forall x. Rep GetObjectACLs x -> GetObjectACLs
forall x. GetObjectACLs -> Rep GetObjectACLs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetObjectACLs x -> GetObjectACLs
$cfrom :: forall x. GetObjectACLs -> Rep GetObjectACLs x
Generic )

type GetObjectACLsResponse = ACLResponse

instance MonadSpaces m => Action m GetObjectACLs where
    type ConsumedResponse GetObjectACLs = GetObjectACLsResponse

    buildRequest :: GetObjectACLs -> m SpacesRequestBuilder
buildRequest GetObjectACLs { Object
Bucket
object :: Object
bucket :: Bucket
$sel:object:GetObjectACLs :: GetObjectACLs -> Object
$sel:bucket:GetObjectACLs :: GetObjectACLs -> Bucket
.. } = do
        Spaces
spaces <- m Spaces
forall r (m :: * -> *). MonadReader r m => m r
ask
        SpacesRequestBuilder -> m SpacesRequestBuilder
forall (m :: * -> *) a. Monad m => a -> m a
return SpacesRequestBuilder :: Spaces
-> Maybe RequestBody
-> Maybe Method
-> [Header]
-> Maybe Bucket
-> Maybe Object
-> Maybe Query
-> Maybe Query
-> Maybe Region
-> SpacesRequestBuilder
SpacesRequestBuilder
               { $sel:bucket:SpacesRequestBuilder :: Maybe Bucket
bucket         = Bucket -> Maybe Bucket
forall a. a -> Maybe a
Just Bucket
bucket
               , $sel:object:SpacesRequestBuilder :: Maybe Object
object         = Object -> Maybe Object
forall a. a -> Maybe a
Just Object
object
               , $sel:method:SpacesRequestBuilder :: Maybe Method
method         = Maybe Method
forall a. Maybe a
Nothing
               , $sel:body:SpacesRequestBuilder :: Maybe RequestBody
body           = Maybe RequestBody
forall a. Maybe a
Nothing
               , $sel:overrideRegion:SpacesRequestBuilder :: Maybe Region
overrideRegion = Maybe Region
forall a. Maybe a
Nothing
               , $sel:queryString:SpacesRequestBuilder :: Maybe Query
queryString    = Maybe Query
forall a. Maybe a
Nothing
               , $sel:headers:SpacesRequestBuilder :: [Header]
headers        = [Header]
forall a. Monoid a => a
mempty
               , $sel:subresources:SpacesRequestBuilder :: Maybe Query
subresources   = Query -> Maybe Query
forall a. a -> Maybe a
Just
                     (Query -> Maybe Query) -> Query -> Maybe Query
forall a b. (a -> b) -> a -> b
$ Query -> Query
forall a. QueryLike a => a -> Query
H.toQuery [ ( ByteString
"acl" :: ByteString
                                   , Maybe ByteString
forall a. Maybe a
Nothing :: Maybe ByteString
                                   )
                                 ]
               , Spaces
$sel:spaces:SpacesRequestBuilder :: Spaces
spaces :: Spaces
..
               }

    consumeResponse :: RawResponse m -> m (ConsumedResponse GetObjectACLs)
consumeResponse RawResponse m
raw = Cursor Node -> m ACLResponse
forall (m :: * -> *). MonadThrow m => Cursor Node -> m ACLResponse
aclP (Cursor Node -> m ACLResponse) -> m (Cursor Node) -> m ACLResponse
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< RawResponse m -> m (Cursor Node)
forall (m :: * -> *).
(MonadIO m, MonadThrow m) =>
RawResponse m -> m (Cursor Node)
xmlDocCursor RawResponse m
raw