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

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

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

import           Data.ByteString         ( ByteString )

import           GHC.Generics            ( Generic )

import           Network.DO.Spaces.Types
                 ( ACLResponse
                 , Action(..)
                 , Bucket
                 , MonadSpaces
                 , 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 GetBucketACLs = GetBucketACLs { GetBucketACLs -> Bucket
bucket :: Bucket }
    deriving ( Int -> GetBucketACLs -> ShowS
[GetBucketACLs] -> ShowS
GetBucketACLs -> String
(Int -> GetBucketACLs -> ShowS)
-> (GetBucketACLs -> String)
-> ([GetBucketACLs] -> ShowS)
-> Show GetBucketACLs
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetBucketACLs] -> ShowS
$cshowList :: [GetBucketACLs] -> ShowS
show :: GetBucketACLs -> String
$cshow :: GetBucketACLs -> String
showsPrec :: Int -> GetBucketACLs -> ShowS
$cshowsPrec :: Int -> GetBucketACLs -> ShowS
Show, GetBucketACLs -> GetBucketACLs -> Bool
(GetBucketACLs -> GetBucketACLs -> Bool)
-> (GetBucketACLs -> GetBucketACLs -> Bool) -> Eq GetBucketACLs
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetBucketACLs -> GetBucketACLs -> Bool
$c/= :: GetBucketACLs -> GetBucketACLs -> Bool
== :: GetBucketACLs -> GetBucketACLs -> Bool
$c== :: GetBucketACLs -> GetBucketACLs -> Bool
Eq, (forall x. GetBucketACLs -> Rep GetBucketACLs x)
-> (forall x. Rep GetBucketACLs x -> GetBucketACLs)
-> Generic GetBucketACLs
forall x. Rep GetBucketACLs x -> GetBucketACLs
forall x. GetBucketACLs -> Rep GetBucketACLs x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetBucketACLs x -> GetBucketACLs
$cfrom :: forall x. GetBucketACLs -> Rep GetBucketACLs x
Generic )

type GetBucketACLsResponse = ACLResponse

instance MonadSpaces m => Action m GetBucketACLs where
    type ConsumedResponse GetBucketACLs = GetBucketACLsResponse

    buildRequest :: GetBucketACLs -> m SpacesRequestBuilder
buildRequest GetBucketACLs { Bucket
bucket :: Bucket
$sel:bucket:GetBucketACLs :: GetBucketACLs -> 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: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:object:SpacesRequestBuilder :: Maybe Object
object         = Maybe Object
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 GetBucketACLs)
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