{-# 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.Redshift.AuthorizeEndpointAccess
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Grants access to a cluster.
module Amazonka.Redshift.AuthorizeEndpointAccess
  ( -- * Creating a Request
    AuthorizeEndpointAccess (..),
    newAuthorizeEndpointAccess,

    -- * Request Lenses
    authorizeEndpointAccess_clusterIdentifier,
    authorizeEndpointAccess_vpcIds,
    authorizeEndpointAccess_account,

    -- * Destructuring the Response
    EndpointAuthorization (..),
    newEndpointAuthorization,

    -- * Response Lenses
    endpointAuthorization_allowedAllVPCs,
    endpointAuthorization_allowedVPCs,
    endpointAuthorization_authorizeTime,
    endpointAuthorization_clusterIdentifier,
    endpointAuthorization_clusterStatus,
    endpointAuthorization_endpointCount,
    endpointAuthorization_grantee,
    endpointAuthorization_grantor,
    endpointAuthorization_status,
  )
where

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

-- | /See:/ 'newAuthorizeEndpointAccess' smart constructor.
data AuthorizeEndpointAccess = AuthorizeEndpointAccess'
  { -- | The cluster identifier of the cluster to grant access to.
    AuthorizeEndpointAccess -> Maybe Text
clusterIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The virtual private cloud (VPC) identifiers to grant access to.
    AuthorizeEndpointAccess -> Maybe [Text]
vpcIds :: Prelude.Maybe [Prelude.Text],
    -- | The Amazon Web Services account ID to grant access to.
    AuthorizeEndpointAccess -> Text
account :: Prelude.Text
  }
  deriving (AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool
$c/= :: AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool
== :: AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool
$c== :: AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool
Prelude.Eq, ReadPrec [AuthorizeEndpointAccess]
ReadPrec AuthorizeEndpointAccess
Int -> ReadS AuthorizeEndpointAccess
ReadS [AuthorizeEndpointAccess]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AuthorizeEndpointAccess]
$creadListPrec :: ReadPrec [AuthorizeEndpointAccess]
readPrec :: ReadPrec AuthorizeEndpointAccess
$creadPrec :: ReadPrec AuthorizeEndpointAccess
readList :: ReadS [AuthorizeEndpointAccess]
$creadList :: ReadS [AuthorizeEndpointAccess]
readsPrec :: Int -> ReadS AuthorizeEndpointAccess
$creadsPrec :: Int -> ReadS AuthorizeEndpointAccess
Prelude.Read, Int -> AuthorizeEndpointAccess -> ShowS
[AuthorizeEndpointAccess] -> ShowS
AuthorizeEndpointAccess -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthorizeEndpointAccess] -> ShowS
$cshowList :: [AuthorizeEndpointAccess] -> ShowS
show :: AuthorizeEndpointAccess -> String
$cshow :: AuthorizeEndpointAccess -> String
showsPrec :: Int -> AuthorizeEndpointAccess -> ShowS
$cshowsPrec :: Int -> AuthorizeEndpointAccess -> ShowS
Prelude.Show, forall x. Rep AuthorizeEndpointAccess x -> AuthorizeEndpointAccess
forall x. AuthorizeEndpointAccess -> Rep AuthorizeEndpointAccess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AuthorizeEndpointAccess x -> AuthorizeEndpointAccess
$cfrom :: forall x. AuthorizeEndpointAccess -> Rep AuthorizeEndpointAccess x
Prelude.Generic)

-- |
-- Create a value of 'AuthorizeEndpointAccess' 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:
--
-- 'clusterIdentifier', 'authorizeEndpointAccess_clusterIdentifier' - The cluster identifier of the cluster to grant access to.
--
-- 'vpcIds', 'authorizeEndpointAccess_vpcIds' - The virtual private cloud (VPC) identifiers to grant access to.
--
-- 'account', 'authorizeEndpointAccess_account' - The Amazon Web Services account ID to grant access to.
newAuthorizeEndpointAccess ::
  -- | 'account'
  Prelude.Text ->
  AuthorizeEndpointAccess
newAuthorizeEndpointAccess :: Text -> AuthorizeEndpointAccess
newAuthorizeEndpointAccess Text
pAccount_ =
  AuthorizeEndpointAccess'
    { $sel:clusterIdentifier:AuthorizeEndpointAccess' :: Maybe Text
clusterIdentifier =
        forall a. Maybe a
Prelude.Nothing,
      $sel:vpcIds:AuthorizeEndpointAccess' :: Maybe [Text]
vpcIds = forall a. Maybe a
Prelude.Nothing,
      $sel:account:AuthorizeEndpointAccess' :: Text
account = Text
pAccount_
    }

-- | The cluster identifier of the cluster to grant access to.
authorizeEndpointAccess_clusterIdentifier :: Lens.Lens' AuthorizeEndpointAccess (Prelude.Maybe Prelude.Text)
authorizeEndpointAccess_clusterIdentifier :: Lens' AuthorizeEndpointAccess (Maybe Text)
authorizeEndpointAccess_clusterIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizeEndpointAccess' {Maybe Text
clusterIdentifier :: Maybe Text
$sel:clusterIdentifier:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe Text
clusterIdentifier} -> Maybe Text
clusterIdentifier) (\s :: AuthorizeEndpointAccess
s@AuthorizeEndpointAccess' {} Maybe Text
a -> AuthorizeEndpointAccess
s {$sel:clusterIdentifier:AuthorizeEndpointAccess' :: Maybe Text
clusterIdentifier = Maybe Text
a} :: AuthorizeEndpointAccess)

-- | The virtual private cloud (VPC) identifiers to grant access to.
authorizeEndpointAccess_vpcIds :: Lens.Lens' AuthorizeEndpointAccess (Prelude.Maybe [Prelude.Text])
authorizeEndpointAccess_vpcIds :: Lens' AuthorizeEndpointAccess (Maybe [Text])
authorizeEndpointAccess_vpcIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizeEndpointAccess' {Maybe [Text]
vpcIds :: Maybe [Text]
$sel:vpcIds:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe [Text]
vpcIds} -> Maybe [Text]
vpcIds) (\s :: AuthorizeEndpointAccess
s@AuthorizeEndpointAccess' {} Maybe [Text]
a -> AuthorizeEndpointAccess
s {$sel:vpcIds:AuthorizeEndpointAccess' :: Maybe [Text]
vpcIds = Maybe [Text]
a} :: AuthorizeEndpointAccess) 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 Amazon Web Services account ID to grant access to.
authorizeEndpointAccess_account :: Lens.Lens' AuthorizeEndpointAccess Prelude.Text
authorizeEndpointAccess_account :: Lens' AuthorizeEndpointAccess Text
authorizeEndpointAccess_account = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthorizeEndpointAccess' {Text
account :: Text
$sel:account:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Text
account} -> Text
account) (\s :: AuthorizeEndpointAccess
s@AuthorizeEndpointAccess' {} Text
a -> AuthorizeEndpointAccess
s {$sel:account:AuthorizeEndpointAccess' :: Text
account = Text
a} :: AuthorizeEndpointAccess)

instance Core.AWSRequest AuthorizeEndpointAccess where
  type
    AWSResponse AuthorizeEndpointAccess =
      EndpointAuthorization
  request :: (Service -> Service)
-> AuthorizeEndpointAccess -> Request AuthorizeEndpointAccess
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AuthorizeEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AuthorizeEndpointAccess)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"AuthorizeEndpointAccessResult"
      (\Int
s ResponseHeaders
h [Node]
x -> forall a. FromXML a => [Node] -> Either String a
Data.parseXML [Node]
x)

instance Prelude.Hashable AuthorizeEndpointAccess where
  hashWithSalt :: Int -> AuthorizeEndpointAccess -> Int
hashWithSalt Int
_salt AuthorizeEndpointAccess' {Maybe [Text]
Maybe Text
Text
account :: Text
vpcIds :: Maybe [Text]
clusterIdentifier :: Maybe Text
$sel:account:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Text
$sel:vpcIds:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe [Text]
$sel:clusterIdentifier:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clusterIdentifier
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
vpcIds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
account

instance Prelude.NFData AuthorizeEndpointAccess where
  rnf :: AuthorizeEndpointAccess -> ()
rnf AuthorizeEndpointAccess' {Maybe [Text]
Maybe Text
Text
account :: Text
vpcIds :: Maybe [Text]
clusterIdentifier :: Maybe Text
$sel:account:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Text
$sel:vpcIds:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe [Text]
$sel:clusterIdentifier:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clusterIdentifier
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
vpcIds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
account

instance Data.ToHeaders AuthorizeEndpointAccess where
  toHeaders :: AuthorizeEndpointAccess -> ResponseHeaders
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery AuthorizeEndpointAccess where
  toQuery :: AuthorizeEndpointAccess -> QueryString
toQuery AuthorizeEndpointAccess' {Maybe [Text]
Maybe Text
Text
account :: Text
vpcIds :: Maybe [Text]
clusterIdentifier :: Maybe Text
$sel:account:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Text
$sel:vpcIds:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe [Text]
$sel:clusterIdentifier:AuthorizeEndpointAccess' :: AuthorizeEndpointAccess -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"AuthorizeEndpointAccess" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2012-12-01" :: Prelude.ByteString),
        ByteString
"ClusterIdentifier" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
clusterIdentifier,
        ByteString
"VpcIds"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: forall a. ToQuery a => a -> QueryString
Data.toQuery
            ( forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Data.toQueryList ByteString
"VpcIdentifier"
                forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
vpcIds
            ),
        ByteString
"Account" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
account
      ]