{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.LakeFormation.BatchGrantPermissions
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Batch operation to grant permissions to the principal.
module Amazonka.LakeFormation.BatchGrantPermissions
  ( -- * Creating a Request
    BatchGrantPermissions (..),
    newBatchGrantPermissions,

    -- * Request Lenses
    batchGrantPermissions_catalogId,
    batchGrantPermissions_entries,

    -- * Destructuring the Response
    BatchGrantPermissionsResponse (..),
    newBatchGrantPermissionsResponse,

    -- * Response Lenses
    batchGrantPermissionsResponse_failures,
    batchGrantPermissionsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.LakeFormation.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newBatchGrantPermissions' smart constructor.
data BatchGrantPermissions = BatchGrantPermissions'
  { -- | The identifier for the Data Catalog. By default, the account ID. The
    -- Data Catalog is the persistent metadata store. It contains database
    -- definitions, table definitions, and other control information to manage
    -- your Lake Formation environment.
    BatchGrantPermissions -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | A list of up to 20 entries for resource permissions to be granted by
    -- batch operation to the principal.
    BatchGrantPermissions -> [BatchPermissionsRequestEntry]
entries :: [BatchPermissionsRequestEntry]
  }
  deriving (BatchGrantPermissions -> BatchGrantPermissions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchGrantPermissions -> BatchGrantPermissions -> Bool
$c/= :: BatchGrantPermissions -> BatchGrantPermissions -> Bool
== :: BatchGrantPermissions -> BatchGrantPermissions -> Bool
$c== :: BatchGrantPermissions -> BatchGrantPermissions -> Bool
Prelude.Eq, ReadPrec [BatchGrantPermissions]
ReadPrec BatchGrantPermissions
Int -> ReadS BatchGrantPermissions
ReadS [BatchGrantPermissions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchGrantPermissions]
$creadListPrec :: ReadPrec [BatchGrantPermissions]
readPrec :: ReadPrec BatchGrantPermissions
$creadPrec :: ReadPrec BatchGrantPermissions
readList :: ReadS [BatchGrantPermissions]
$creadList :: ReadS [BatchGrantPermissions]
readsPrec :: Int -> ReadS BatchGrantPermissions
$creadsPrec :: Int -> ReadS BatchGrantPermissions
Prelude.Read, Int -> BatchGrantPermissions -> ShowS
[BatchGrantPermissions] -> ShowS
BatchGrantPermissions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchGrantPermissions] -> ShowS
$cshowList :: [BatchGrantPermissions] -> ShowS
show :: BatchGrantPermissions -> String
$cshow :: BatchGrantPermissions -> String
showsPrec :: Int -> BatchGrantPermissions -> ShowS
$cshowsPrec :: Int -> BatchGrantPermissions -> ShowS
Prelude.Show, forall x. Rep BatchGrantPermissions x -> BatchGrantPermissions
forall x. BatchGrantPermissions -> Rep BatchGrantPermissions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BatchGrantPermissions x -> BatchGrantPermissions
$cfrom :: forall x. BatchGrantPermissions -> Rep BatchGrantPermissions x
Prelude.Generic)

-- |
-- Create a value of 'BatchGrantPermissions' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'catalogId', 'batchGrantPermissions_catalogId' - The identifier for the Data Catalog. By default, the account ID. The
-- Data Catalog is the persistent metadata store. It contains database
-- definitions, table definitions, and other control information to manage
-- your Lake Formation environment.
--
-- 'entries', 'batchGrantPermissions_entries' - A list of up to 20 entries for resource permissions to be granted by
-- batch operation to the principal.
newBatchGrantPermissions ::
  BatchGrantPermissions
newBatchGrantPermissions :: BatchGrantPermissions
newBatchGrantPermissions =
  BatchGrantPermissions'
    { $sel:catalogId:BatchGrantPermissions' :: Maybe Text
catalogId = forall a. Maybe a
Prelude.Nothing,
      $sel:entries:BatchGrantPermissions' :: [BatchPermissionsRequestEntry]
entries = forall a. Monoid a => a
Prelude.mempty
    }

-- | The identifier for the Data Catalog. By default, the account ID. The
-- Data Catalog is the persistent metadata store. It contains database
-- definitions, table definitions, and other control information to manage
-- your Lake Formation environment.
batchGrantPermissions_catalogId :: Lens.Lens' BatchGrantPermissions (Prelude.Maybe Prelude.Text)
batchGrantPermissions_catalogId :: Lens' BatchGrantPermissions (Maybe Text)
batchGrantPermissions_catalogId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGrantPermissions' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:BatchGrantPermissions' :: BatchGrantPermissions -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: BatchGrantPermissions
s@BatchGrantPermissions' {} Maybe Text
a -> BatchGrantPermissions
s {$sel:catalogId:BatchGrantPermissions' :: Maybe Text
catalogId = Maybe Text
a} :: BatchGrantPermissions)

-- | A list of up to 20 entries for resource permissions to be granted by
-- batch operation to the principal.
batchGrantPermissions_entries :: Lens.Lens' BatchGrantPermissions [BatchPermissionsRequestEntry]
batchGrantPermissions_entries :: Lens' BatchGrantPermissions [BatchPermissionsRequestEntry]
batchGrantPermissions_entries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGrantPermissions' {[BatchPermissionsRequestEntry]
entries :: [BatchPermissionsRequestEntry]
$sel:entries:BatchGrantPermissions' :: BatchGrantPermissions -> [BatchPermissionsRequestEntry]
entries} -> [BatchPermissionsRequestEntry]
entries) (\s :: BatchGrantPermissions
s@BatchGrantPermissions' {} [BatchPermissionsRequestEntry]
a -> BatchGrantPermissions
s {$sel:entries:BatchGrantPermissions' :: [BatchPermissionsRequestEntry]
entries = [BatchPermissionsRequestEntry]
a} :: BatchGrantPermissions) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest BatchGrantPermissions where
  type
    AWSResponse BatchGrantPermissions =
      BatchGrantPermissionsResponse
  request :: (Service -> Service)
-> BatchGrantPermissions -> Request BatchGrantPermissions
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy BatchGrantPermissions
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse BatchGrantPermissions)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [BatchPermissionsFailureEntry]
-> Int -> BatchGrantPermissionsResponse
BatchGrantPermissionsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Failures" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable BatchGrantPermissions where
  hashWithSalt :: Int -> BatchGrantPermissions -> Int
hashWithSalt Int
_salt BatchGrantPermissions' {[BatchPermissionsRequestEntry]
Maybe Text
entries :: [BatchPermissionsRequestEntry]
catalogId :: Maybe Text
$sel:entries:BatchGrantPermissions' :: BatchGrantPermissions -> [BatchPermissionsRequestEntry]
$sel:catalogId:BatchGrantPermissions' :: BatchGrantPermissions -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
catalogId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [BatchPermissionsRequestEntry]
entries

instance Prelude.NFData BatchGrantPermissions where
  rnf :: BatchGrantPermissions -> ()
rnf BatchGrantPermissions' {[BatchPermissionsRequestEntry]
Maybe Text
entries :: [BatchPermissionsRequestEntry]
catalogId :: Maybe Text
$sel:entries:BatchGrantPermissions' :: BatchGrantPermissions -> [BatchPermissionsRequestEntry]
$sel:catalogId:BatchGrantPermissions' :: BatchGrantPermissions -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
catalogId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [BatchPermissionsRequestEntry]
entries

instance Data.ToHeaders BatchGrantPermissions where
  toHeaders :: BatchGrantPermissions -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON BatchGrantPermissions where
  toJSON :: BatchGrantPermissions -> Value
toJSON BatchGrantPermissions' {[BatchPermissionsRequestEntry]
Maybe Text
entries :: [BatchPermissionsRequestEntry]
catalogId :: Maybe Text
$sel:entries:BatchGrantPermissions' :: BatchGrantPermissions -> [BatchPermissionsRequestEntry]
$sel:catalogId:BatchGrantPermissions' :: BatchGrantPermissions -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CatalogId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            forall a. a -> Maybe a
Prelude.Just (Key
"Entries" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [BatchPermissionsRequestEntry]
entries)
          ]
      )

instance Data.ToPath BatchGrantPermissions where
  toPath :: BatchGrantPermissions -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/BatchGrantPermissions"

instance Data.ToQuery BatchGrantPermissions where
  toQuery :: BatchGrantPermissions -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newBatchGrantPermissionsResponse' smart constructor.
data BatchGrantPermissionsResponse = BatchGrantPermissionsResponse'
  { -- | A list of failures to grant permissions to the resources.
    BatchGrantPermissionsResponse
-> Maybe [BatchPermissionsFailureEntry]
failures :: Prelude.Maybe [BatchPermissionsFailureEntry],
    -- | The response's http status code.
    BatchGrantPermissionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BatchGrantPermissionsResponse
-> BatchGrantPermissionsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BatchGrantPermissionsResponse
-> BatchGrantPermissionsResponse -> Bool
$c/= :: BatchGrantPermissionsResponse
-> BatchGrantPermissionsResponse -> Bool
== :: BatchGrantPermissionsResponse
-> BatchGrantPermissionsResponse -> Bool
$c== :: BatchGrantPermissionsResponse
-> BatchGrantPermissionsResponse -> Bool
Prelude.Eq, ReadPrec [BatchGrantPermissionsResponse]
ReadPrec BatchGrantPermissionsResponse
Int -> ReadS BatchGrantPermissionsResponse
ReadS [BatchGrantPermissionsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BatchGrantPermissionsResponse]
$creadListPrec :: ReadPrec [BatchGrantPermissionsResponse]
readPrec :: ReadPrec BatchGrantPermissionsResponse
$creadPrec :: ReadPrec BatchGrantPermissionsResponse
readList :: ReadS [BatchGrantPermissionsResponse]
$creadList :: ReadS [BatchGrantPermissionsResponse]
readsPrec :: Int -> ReadS BatchGrantPermissionsResponse
$creadsPrec :: Int -> ReadS BatchGrantPermissionsResponse
Prelude.Read, Int -> BatchGrantPermissionsResponse -> ShowS
[BatchGrantPermissionsResponse] -> ShowS
BatchGrantPermissionsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BatchGrantPermissionsResponse] -> ShowS
$cshowList :: [BatchGrantPermissionsResponse] -> ShowS
show :: BatchGrantPermissionsResponse -> String
$cshow :: BatchGrantPermissionsResponse -> String
showsPrec :: Int -> BatchGrantPermissionsResponse -> ShowS
$cshowsPrec :: Int -> BatchGrantPermissionsResponse -> ShowS
Prelude.Show, forall x.
Rep BatchGrantPermissionsResponse x
-> BatchGrantPermissionsResponse
forall x.
BatchGrantPermissionsResponse
-> Rep BatchGrantPermissionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BatchGrantPermissionsResponse x
-> BatchGrantPermissionsResponse
$cfrom :: forall x.
BatchGrantPermissionsResponse
-> Rep BatchGrantPermissionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'BatchGrantPermissionsResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'failures', 'batchGrantPermissionsResponse_failures' - A list of failures to grant permissions to the resources.
--
-- 'httpStatus', 'batchGrantPermissionsResponse_httpStatus' - The response's http status code.
newBatchGrantPermissionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BatchGrantPermissionsResponse
newBatchGrantPermissionsResponse :: Int -> BatchGrantPermissionsResponse
newBatchGrantPermissionsResponse Int
pHttpStatus_ =
  BatchGrantPermissionsResponse'
    { $sel:failures:BatchGrantPermissionsResponse' :: Maybe [BatchPermissionsFailureEntry]
failures =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BatchGrantPermissionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A list of failures to grant permissions to the resources.
batchGrantPermissionsResponse_failures :: Lens.Lens' BatchGrantPermissionsResponse (Prelude.Maybe [BatchPermissionsFailureEntry])
batchGrantPermissionsResponse_failures :: Lens'
  BatchGrantPermissionsResponse
  (Maybe [BatchPermissionsFailureEntry])
batchGrantPermissionsResponse_failures = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGrantPermissionsResponse' {Maybe [BatchPermissionsFailureEntry]
failures :: Maybe [BatchPermissionsFailureEntry]
$sel:failures:BatchGrantPermissionsResponse' :: BatchGrantPermissionsResponse
-> Maybe [BatchPermissionsFailureEntry]
failures} -> Maybe [BatchPermissionsFailureEntry]
failures) (\s :: BatchGrantPermissionsResponse
s@BatchGrantPermissionsResponse' {} Maybe [BatchPermissionsFailureEntry]
a -> BatchGrantPermissionsResponse
s {$sel:failures:BatchGrantPermissionsResponse' :: Maybe [BatchPermissionsFailureEntry]
failures = Maybe [BatchPermissionsFailureEntry]
a} :: BatchGrantPermissionsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response's http status code.
batchGrantPermissionsResponse_httpStatus :: Lens.Lens' BatchGrantPermissionsResponse Prelude.Int
batchGrantPermissionsResponse_httpStatus :: Lens' BatchGrantPermissionsResponse Int
batchGrantPermissionsResponse_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BatchGrantPermissionsResponse' {Int
httpStatus :: Int
$sel:httpStatus:BatchGrantPermissionsResponse' :: BatchGrantPermissionsResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BatchGrantPermissionsResponse
s@BatchGrantPermissionsResponse' {} Int
a -> BatchGrantPermissionsResponse
s {$sel:httpStatus:BatchGrantPermissionsResponse' :: Int
httpStatus = Int
a} :: BatchGrantPermissionsResponse)

instance Prelude.NFData BatchGrantPermissionsResponse where
  rnf :: BatchGrantPermissionsResponse -> ()
rnf BatchGrantPermissionsResponse' {Int
Maybe [BatchPermissionsFailureEntry]
httpStatus :: Int
failures :: Maybe [BatchPermissionsFailureEntry]
$sel:httpStatus:BatchGrantPermissionsResponse' :: BatchGrantPermissionsResponse -> Int
$sel:failures:BatchGrantPermissionsResponse' :: BatchGrantPermissionsResponse
-> Maybe [BatchPermissionsFailureEntry]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [BatchPermissionsFailureEntry]
failures
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus