{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- 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_status,
    endpointAuthorization_allowedAllVPCs,
    endpointAuthorization_endpointCount,
    endpointAuthorization_grantor,
    endpointAuthorization_clusterIdentifier,
    endpointAuthorization_grantee,
    endpointAuthorization_allowedVPCs,
    endpointAuthorization_clusterStatus,
    endpointAuthorization_authorizeTime,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool)
-> (AuthorizeEndpointAccess -> AuthorizeEndpointAccess -> Bool)
-> Eq AuthorizeEndpointAccess
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]
(Int -> ReadS AuthorizeEndpointAccess)
-> ReadS [AuthorizeEndpointAccess]
-> ReadPrec AuthorizeEndpointAccess
-> ReadPrec [AuthorizeEndpointAccess]
-> Read 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
(Int -> AuthorizeEndpointAccess -> ShowS)
-> (AuthorizeEndpointAccess -> String)
-> ([AuthorizeEndpointAccess] -> ShowS)
-> Show AuthorizeEndpointAccess
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.
 AuthorizeEndpointAccess -> Rep AuthorizeEndpointAccess x)
-> (forall x.
    Rep AuthorizeEndpointAccess x -> AuthorizeEndpointAccess)
-> Generic AuthorizeEndpointAccess
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' :: Maybe Text -> Maybe [Text] -> Text -> AuthorizeEndpointAccess
AuthorizeEndpointAccess'
    { $sel:clusterIdentifier:AuthorizeEndpointAccess' :: Maybe Text
clusterIdentifier =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:vpcIds:AuthorizeEndpointAccess' :: Maybe [Text]
vpcIds = Maybe [Text]
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 :: (Maybe Text -> f (Maybe Text))
-> AuthorizeEndpointAccess -> f AuthorizeEndpointAccess
authorizeEndpointAccess_clusterIdentifier = (AuthorizeEndpointAccess -> Maybe Text)
-> (AuthorizeEndpointAccess
    -> Maybe Text -> AuthorizeEndpointAccess)
-> Lens
     AuthorizeEndpointAccess
     AuthorizeEndpointAccess
     (Maybe Text)
     (Maybe Text)
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 :: (Maybe [Text] -> f (Maybe [Text]))
-> AuthorizeEndpointAccess -> f AuthorizeEndpointAccess
authorizeEndpointAccess_vpcIds = (AuthorizeEndpointAccess -> Maybe [Text])
-> (AuthorizeEndpointAccess
    -> Maybe [Text] -> AuthorizeEndpointAccess)
-> Lens
     AuthorizeEndpointAccess
     AuthorizeEndpointAccess
     (Maybe [Text])
     (Maybe [Text])
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) ((Maybe [Text] -> f (Maybe [Text]))
 -> AuthorizeEndpointAccess -> f AuthorizeEndpointAccess)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> AuthorizeEndpointAccess
-> f AuthorizeEndpointAccess
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
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 AnIso [Text] [Text] [Text] [Text]
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 :: (Text -> f Text)
-> AuthorizeEndpointAccess -> f AuthorizeEndpointAccess
authorizeEndpointAccess_account = (AuthorizeEndpointAccess -> Text)
-> (AuthorizeEndpointAccess -> Text -> AuthorizeEndpointAccess)
-> Lens AuthorizeEndpointAccess AuthorizeEndpointAccess Text Text
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 :: AuthorizeEndpointAccess -> Request AuthorizeEndpointAccess
request = Service
-> AuthorizeEndpointAccess -> Request AuthorizeEndpointAccess
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AuthorizeEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AuthorizeEndpointAccess)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse AuthorizeEndpointAccess))
-> Logger
-> Service
-> Proxy AuthorizeEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AuthorizeEndpointAccess)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"AuthorizeEndpointAccessResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String EndpointAuthorization
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable AuthorizeEndpointAccess

instance Prelude.NFData AuthorizeEndpointAccess

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

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

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