{-# 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.ModifyEndpointAccess
-- 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)
--
-- Modifies a Redshift-managed VPC endpoint.
module Amazonka.Redshift.ModifyEndpointAccess
  ( -- * Creating a Request
    ModifyEndpointAccess (..),
    newModifyEndpointAccess,

    -- * Request Lenses
    modifyEndpointAccess_vpcSecurityGroupIds,
    modifyEndpointAccess_endpointName,

    -- * Destructuring the Response
    EndpointAccess (..),
    newEndpointAccess,

    -- * Response Lenses
    endpointAccess_endpointName,
    endpointAccess_endpointCreateTime,
    endpointAccess_subnetGroupName,
    endpointAccess_address,
    endpointAccess_clusterIdentifier,
    endpointAccess_endpointStatus,
    endpointAccess_vpcSecurityGroups,
    endpointAccess_resourceOwner,
    endpointAccess_vpcEndpoint,
    endpointAccess_port,
  )
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:/ 'newModifyEndpointAccess' smart constructor.
data ModifyEndpointAccess = ModifyEndpointAccess'
  { -- | The complete list of VPC security groups associated with the endpoint
    -- after the endpoint is modified.
    ModifyEndpointAccess -> Maybe [Text]
vpcSecurityGroupIds :: Prelude.Maybe [Prelude.Text],
    -- | The endpoint to be modified.
    ModifyEndpointAccess -> Text
endpointName :: Prelude.Text
  }
  deriving (ModifyEndpointAccess -> ModifyEndpointAccess -> Bool
(ModifyEndpointAccess -> ModifyEndpointAccess -> Bool)
-> (ModifyEndpointAccess -> ModifyEndpointAccess -> Bool)
-> Eq ModifyEndpointAccess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModifyEndpointAccess -> ModifyEndpointAccess -> Bool
$c/= :: ModifyEndpointAccess -> ModifyEndpointAccess -> Bool
== :: ModifyEndpointAccess -> ModifyEndpointAccess -> Bool
$c== :: ModifyEndpointAccess -> ModifyEndpointAccess -> Bool
Prelude.Eq, ReadPrec [ModifyEndpointAccess]
ReadPrec ModifyEndpointAccess
Int -> ReadS ModifyEndpointAccess
ReadS [ModifyEndpointAccess]
(Int -> ReadS ModifyEndpointAccess)
-> ReadS [ModifyEndpointAccess]
-> ReadPrec ModifyEndpointAccess
-> ReadPrec [ModifyEndpointAccess]
-> Read ModifyEndpointAccess
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ModifyEndpointAccess]
$creadListPrec :: ReadPrec [ModifyEndpointAccess]
readPrec :: ReadPrec ModifyEndpointAccess
$creadPrec :: ReadPrec ModifyEndpointAccess
readList :: ReadS [ModifyEndpointAccess]
$creadList :: ReadS [ModifyEndpointAccess]
readsPrec :: Int -> ReadS ModifyEndpointAccess
$creadsPrec :: Int -> ReadS ModifyEndpointAccess
Prelude.Read, Int -> ModifyEndpointAccess -> ShowS
[ModifyEndpointAccess] -> ShowS
ModifyEndpointAccess -> String
(Int -> ModifyEndpointAccess -> ShowS)
-> (ModifyEndpointAccess -> String)
-> ([ModifyEndpointAccess] -> ShowS)
-> Show ModifyEndpointAccess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ModifyEndpointAccess] -> ShowS
$cshowList :: [ModifyEndpointAccess] -> ShowS
show :: ModifyEndpointAccess -> String
$cshow :: ModifyEndpointAccess -> String
showsPrec :: Int -> ModifyEndpointAccess -> ShowS
$cshowsPrec :: Int -> ModifyEndpointAccess -> ShowS
Prelude.Show, (forall x. ModifyEndpointAccess -> Rep ModifyEndpointAccess x)
-> (forall x. Rep ModifyEndpointAccess x -> ModifyEndpointAccess)
-> Generic ModifyEndpointAccess
forall x. Rep ModifyEndpointAccess x -> ModifyEndpointAccess
forall x. ModifyEndpointAccess -> Rep ModifyEndpointAccess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ModifyEndpointAccess x -> ModifyEndpointAccess
$cfrom :: forall x. ModifyEndpointAccess -> Rep ModifyEndpointAccess x
Prelude.Generic)

-- |
-- Create a value of 'ModifyEndpointAccess' 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:
--
-- 'vpcSecurityGroupIds', 'modifyEndpointAccess_vpcSecurityGroupIds' - The complete list of VPC security groups associated with the endpoint
-- after the endpoint is modified.
--
-- 'endpointName', 'modifyEndpointAccess_endpointName' - The endpoint to be modified.
newModifyEndpointAccess ::
  -- | 'endpointName'
  Prelude.Text ->
  ModifyEndpointAccess
newModifyEndpointAccess :: Text -> ModifyEndpointAccess
newModifyEndpointAccess Text
pEndpointName_ =
  ModifyEndpointAccess' :: Maybe [Text] -> Text -> ModifyEndpointAccess
ModifyEndpointAccess'
    { $sel:vpcSecurityGroupIds:ModifyEndpointAccess' :: Maybe [Text]
vpcSecurityGroupIds =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:endpointName:ModifyEndpointAccess' :: Text
endpointName = Text
pEndpointName_
    }

-- | The complete list of VPC security groups associated with the endpoint
-- after the endpoint is modified.
modifyEndpointAccess_vpcSecurityGroupIds :: Lens.Lens' ModifyEndpointAccess (Prelude.Maybe [Prelude.Text])
modifyEndpointAccess_vpcSecurityGroupIds :: (Maybe [Text] -> f (Maybe [Text]))
-> ModifyEndpointAccess -> f ModifyEndpointAccess
modifyEndpointAccess_vpcSecurityGroupIds = (ModifyEndpointAccess -> Maybe [Text])
-> (ModifyEndpointAccess -> Maybe [Text] -> ModifyEndpointAccess)
-> Lens
     ModifyEndpointAccess
     ModifyEndpointAccess
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyEndpointAccess' {Maybe [Text]
vpcSecurityGroupIds :: Maybe [Text]
$sel:vpcSecurityGroupIds:ModifyEndpointAccess' :: ModifyEndpointAccess -> Maybe [Text]
vpcSecurityGroupIds} -> Maybe [Text]
vpcSecurityGroupIds) (\s :: ModifyEndpointAccess
s@ModifyEndpointAccess' {} Maybe [Text]
a -> ModifyEndpointAccess
s {$sel:vpcSecurityGroupIds:ModifyEndpointAccess' :: Maybe [Text]
vpcSecurityGroupIds = Maybe [Text]
a} :: ModifyEndpointAccess) ((Maybe [Text] -> f (Maybe [Text]))
 -> ModifyEndpointAccess -> f ModifyEndpointAccess)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> ModifyEndpointAccess
-> f ModifyEndpointAccess
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 endpoint to be modified.
modifyEndpointAccess_endpointName :: Lens.Lens' ModifyEndpointAccess Prelude.Text
modifyEndpointAccess_endpointName :: (Text -> f Text) -> ModifyEndpointAccess -> f ModifyEndpointAccess
modifyEndpointAccess_endpointName = (ModifyEndpointAccess -> Text)
-> (ModifyEndpointAccess -> Text -> ModifyEndpointAccess)
-> Lens ModifyEndpointAccess ModifyEndpointAccess Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ModifyEndpointAccess' {Text
endpointName :: Text
$sel:endpointName:ModifyEndpointAccess' :: ModifyEndpointAccess -> Text
endpointName} -> Text
endpointName) (\s :: ModifyEndpointAccess
s@ModifyEndpointAccess' {} Text
a -> ModifyEndpointAccess
s {$sel:endpointName:ModifyEndpointAccess' :: Text
endpointName = Text
a} :: ModifyEndpointAccess)

instance Core.AWSRequest ModifyEndpointAccess where
  type
    AWSResponse ModifyEndpointAccess =
      EndpointAccess
  request :: ModifyEndpointAccess -> Request ModifyEndpointAccess
request = Service -> ModifyEndpointAccess -> Request ModifyEndpointAccess
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy ModifyEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ModifyEndpointAccess)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse ModifyEndpointAccess))
-> Logger
-> Service
-> Proxy ModifyEndpointAccess
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ModifyEndpointAccess)))
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
"ModifyEndpointAccessResult"
      (\Int
s ResponseHeaders
h [Node]
x -> [Node] -> Either String EndpointAccess
forall a. FromXML a => [Node] -> Either String a
Core.parseXML [Node]
x)

instance Prelude.Hashable ModifyEndpointAccess

instance Prelude.NFData ModifyEndpointAccess

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

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

instance Core.ToQuery ModifyEndpointAccess where
  toQuery :: ModifyEndpointAccess -> QueryString
toQuery ModifyEndpointAccess' {Maybe [Text]
Text
endpointName :: Text
vpcSecurityGroupIds :: Maybe [Text]
$sel:endpointName:ModifyEndpointAccess' :: ModifyEndpointAccess -> Text
$sel:vpcSecurityGroupIds:ModifyEndpointAccess' :: ModifyEndpointAccess -> 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
"ModifyEndpointAccess" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2012-12-01" :: Prelude.ByteString),
        ByteString
"VpcSecurityGroupIds"
          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
"VpcSecurityGroupId"
                ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
vpcSecurityGroupIds
            ),
        ByteString
"EndpointName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
endpointName
      ]