{-# 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.ELBV2.AddListenerCertificates
-- 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)
--
-- Adds the specified SSL server certificate to the certificate list for
-- the specified HTTPS or TLS listener.
--
-- If the certificate in already in the certificate list, the call is
-- successful but the certificate is not added again.
--
-- For more information, see
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/application/create-https-listener.html HTTPS listeners>
-- in the /Application Load Balancers Guide/ or
-- <https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-tls-listener.html TLS listeners>
-- in the /Network Load Balancers Guide/.
module Amazonka.ELBV2.AddListenerCertificates
  ( -- * Creating a Request
    AddListenerCertificates (..),
    newAddListenerCertificates,

    -- * Request Lenses
    addListenerCertificates_listenerArn,
    addListenerCertificates_certificates,

    -- * Destructuring the Response
    AddListenerCertificatesResponse (..),
    newAddListenerCertificatesResponse,

    -- * Response Lenses
    addListenerCertificatesResponse_certificates,
    addListenerCertificatesResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAddListenerCertificates' smart constructor.
data AddListenerCertificates = AddListenerCertificates'
  { -- | The Amazon Resource Name (ARN) of the listener.
    AddListenerCertificates -> Text
listenerArn :: Prelude.Text,
    -- | The certificate to add. You can specify one certificate per call. Set
    -- @CertificateArn@ to the certificate ARN but do not set @IsDefault@.
    AddListenerCertificates -> [Certificate]
certificates :: [Certificate]
  }
  deriving (AddListenerCertificates -> AddListenerCertificates -> Bool
(AddListenerCertificates -> AddListenerCertificates -> Bool)
-> (AddListenerCertificates -> AddListenerCertificates -> Bool)
-> Eq AddListenerCertificates
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddListenerCertificates -> AddListenerCertificates -> Bool
$c/= :: AddListenerCertificates -> AddListenerCertificates -> Bool
== :: AddListenerCertificates -> AddListenerCertificates -> Bool
$c== :: AddListenerCertificates -> AddListenerCertificates -> Bool
Prelude.Eq, ReadPrec [AddListenerCertificates]
ReadPrec AddListenerCertificates
Int -> ReadS AddListenerCertificates
ReadS [AddListenerCertificates]
(Int -> ReadS AddListenerCertificates)
-> ReadS [AddListenerCertificates]
-> ReadPrec AddListenerCertificates
-> ReadPrec [AddListenerCertificates]
-> Read AddListenerCertificates
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddListenerCertificates]
$creadListPrec :: ReadPrec [AddListenerCertificates]
readPrec :: ReadPrec AddListenerCertificates
$creadPrec :: ReadPrec AddListenerCertificates
readList :: ReadS [AddListenerCertificates]
$creadList :: ReadS [AddListenerCertificates]
readsPrec :: Int -> ReadS AddListenerCertificates
$creadsPrec :: Int -> ReadS AddListenerCertificates
Prelude.Read, Int -> AddListenerCertificates -> ShowS
[AddListenerCertificates] -> ShowS
AddListenerCertificates -> String
(Int -> AddListenerCertificates -> ShowS)
-> (AddListenerCertificates -> String)
-> ([AddListenerCertificates] -> ShowS)
-> Show AddListenerCertificates
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddListenerCertificates] -> ShowS
$cshowList :: [AddListenerCertificates] -> ShowS
show :: AddListenerCertificates -> String
$cshow :: AddListenerCertificates -> String
showsPrec :: Int -> AddListenerCertificates -> ShowS
$cshowsPrec :: Int -> AddListenerCertificates -> ShowS
Prelude.Show, (forall x.
 AddListenerCertificates -> Rep AddListenerCertificates x)
-> (forall x.
    Rep AddListenerCertificates x -> AddListenerCertificates)
-> Generic AddListenerCertificates
forall x. Rep AddListenerCertificates x -> AddListenerCertificates
forall x. AddListenerCertificates -> Rep AddListenerCertificates x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AddListenerCertificates x -> AddListenerCertificates
$cfrom :: forall x. AddListenerCertificates -> Rep AddListenerCertificates x
Prelude.Generic)

-- |
-- Create a value of 'AddListenerCertificates' 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:
--
-- 'listenerArn', 'addListenerCertificates_listenerArn' - The Amazon Resource Name (ARN) of the listener.
--
-- 'certificates', 'addListenerCertificates_certificates' - The certificate to add. You can specify one certificate per call. Set
-- @CertificateArn@ to the certificate ARN but do not set @IsDefault@.
newAddListenerCertificates ::
  -- | 'listenerArn'
  Prelude.Text ->
  AddListenerCertificates
newAddListenerCertificates :: Text -> AddListenerCertificates
newAddListenerCertificates Text
pListenerArn_ =
  AddListenerCertificates' :: Text -> [Certificate] -> AddListenerCertificates
AddListenerCertificates'
    { $sel:listenerArn:AddListenerCertificates' :: Text
listenerArn =
        Text
pListenerArn_,
      $sel:certificates:AddListenerCertificates' :: [Certificate]
certificates = [Certificate]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The Amazon Resource Name (ARN) of the listener.
addListenerCertificates_listenerArn :: Lens.Lens' AddListenerCertificates Prelude.Text
addListenerCertificates_listenerArn :: (Text -> f Text)
-> AddListenerCertificates -> f AddListenerCertificates
addListenerCertificates_listenerArn = (AddListenerCertificates -> Text)
-> (AddListenerCertificates -> Text -> AddListenerCertificates)
-> Lens AddListenerCertificates AddListenerCertificates Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddListenerCertificates' {Text
listenerArn :: Text
$sel:listenerArn:AddListenerCertificates' :: AddListenerCertificates -> Text
listenerArn} -> Text
listenerArn) (\s :: AddListenerCertificates
s@AddListenerCertificates' {} Text
a -> AddListenerCertificates
s {$sel:listenerArn:AddListenerCertificates' :: Text
listenerArn = Text
a} :: AddListenerCertificates)

-- | The certificate to add. You can specify one certificate per call. Set
-- @CertificateArn@ to the certificate ARN but do not set @IsDefault@.
addListenerCertificates_certificates :: Lens.Lens' AddListenerCertificates [Certificate]
addListenerCertificates_certificates :: ([Certificate] -> f [Certificate])
-> AddListenerCertificates -> f AddListenerCertificates
addListenerCertificates_certificates = (AddListenerCertificates -> [Certificate])
-> (AddListenerCertificates
    -> [Certificate] -> AddListenerCertificates)
-> Lens
     AddListenerCertificates
     AddListenerCertificates
     [Certificate]
     [Certificate]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddListenerCertificates' {[Certificate]
certificates :: [Certificate]
$sel:certificates:AddListenerCertificates' :: AddListenerCertificates -> [Certificate]
certificates} -> [Certificate]
certificates) (\s :: AddListenerCertificates
s@AddListenerCertificates' {} [Certificate]
a -> AddListenerCertificates
s {$sel:certificates:AddListenerCertificates' :: [Certificate]
certificates = [Certificate]
a} :: AddListenerCertificates) (([Certificate] -> f [Certificate])
 -> AddListenerCertificates -> f AddListenerCertificates)
-> (([Certificate] -> f [Certificate])
    -> [Certificate] -> f [Certificate])
-> ([Certificate] -> f [Certificate])
-> AddListenerCertificates
-> f AddListenerCertificates
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Certificate] -> f [Certificate])
-> [Certificate] -> f [Certificate]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest AddListenerCertificates where
  type
    AWSResponse AddListenerCertificates =
      AddListenerCertificatesResponse
  request :: AddListenerCertificates -> Request AddListenerCertificates
request = Service
-> AddListenerCertificates -> Request AddListenerCertificates
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AddListenerCertificates
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddListenerCertificates)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse AddListenerCertificates))
-> Logger
-> Service
-> Proxy AddListenerCertificates
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AddListenerCertificates)))
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
"AddListenerCertificatesResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Maybe [Certificate] -> Int -> AddListenerCertificatesResponse
AddListenerCertificatesResponse'
            (Maybe [Certificate] -> Int -> AddListenerCertificatesResponse)
-> Either String (Maybe [Certificate])
-> Either String (Int -> AddListenerCertificatesResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Certificates" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                            Either String [Node]
-> ([Node] -> Either String (Maybe [Certificate]))
-> Either String (Maybe [Certificate])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Certificate])
-> [Node] -> Either String (Maybe [Certificate])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Certificate]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                        )
            Either String (Int -> AddListenerCertificatesResponse)
-> Either String Int
-> Either String AddListenerCertificatesResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable AddListenerCertificates

instance Prelude.NFData AddListenerCertificates

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

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

instance Core.ToQuery AddListenerCertificates where
  toQuery :: AddListenerCertificates -> QueryString
toQuery AddListenerCertificates' {[Certificate]
Text
certificates :: [Certificate]
listenerArn :: Text
$sel:certificates:AddListenerCertificates' :: AddListenerCertificates -> [Certificate]
$sel:listenerArn:AddListenerCertificates' :: AddListenerCertificates -> 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
"AddListenerCertificates" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2015-12-01" :: Prelude.ByteString),
        ByteString
"ListenerArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
listenerArn,
        ByteString
"Certificates"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: ByteString -> [Certificate] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" [Certificate]
certificates
      ]

-- | /See:/ 'newAddListenerCertificatesResponse' smart constructor.
data AddListenerCertificatesResponse = AddListenerCertificatesResponse'
  { -- | Information about the certificates in the certificate list.
    AddListenerCertificatesResponse -> Maybe [Certificate]
certificates :: Prelude.Maybe [Certificate],
    -- | The response's http status code.
    AddListenerCertificatesResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (AddListenerCertificatesResponse
-> AddListenerCertificatesResponse -> Bool
(AddListenerCertificatesResponse
 -> AddListenerCertificatesResponse -> Bool)
-> (AddListenerCertificatesResponse
    -> AddListenerCertificatesResponse -> Bool)
-> Eq AddListenerCertificatesResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AddListenerCertificatesResponse
-> AddListenerCertificatesResponse -> Bool
$c/= :: AddListenerCertificatesResponse
-> AddListenerCertificatesResponse -> Bool
== :: AddListenerCertificatesResponse
-> AddListenerCertificatesResponse -> Bool
$c== :: AddListenerCertificatesResponse
-> AddListenerCertificatesResponse -> Bool
Prelude.Eq, ReadPrec [AddListenerCertificatesResponse]
ReadPrec AddListenerCertificatesResponse
Int -> ReadS AddListenerCertificatesResponse
ReadS [AddListenerCertificatesResponse]
(Int -> ReadS AddListenerCertificatesResponse)
-> ReadS [AddListenerCertificatesResponse]
-> ReadPrec AddListenerCertificatesResponse
-> ReadPrec [AddListenerCertificatesResponse]
-> Read AddListenerCertificatesResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AddListenerCertificatesResponse]
$creadListPrec :: ReadPrec [AddListenerCertificatesResponse]
readPrec :: ReadPrec AddListenerCertificatesResponse
$creadPrec :: ReadPrec AddListenerCertificatesResponse
readList :: ReadS [AddListenerCertificatesResponse]
$creadList :: ReadS [AddListenerCertificatesResponse]
readsPrec :: Int -> ReadS AddListenerCertificatesResponse
$creadsPrec :: Int -> ReadS AddListenerCertificatesResponse
Prelude.Read, Int -> AddListenerCertificatesResponse -> ShowS
[AddListenerCertificatesResponse] -> ShowS
AddListenerCertificatesResponse -> String
(Int -> AddListenerCertificatesResponse -> ShowS)
-> (AddListenerCertificatesResponse -> String)
-> ([AddListenerCertificatesResponse] -> ShowS)
-> Show AddListenerCertificatesResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddListenerCertificatesResponse] -> ShowS
$cshowList :: [AddListenerCertificatesResponse] -> ShowS
show :: AddListenerCertificatesResponse -> String
$cshow :: AddListenerCertificatesResponse -> String
showsPrec :: Int -> AddListenerCertificatesResponse -> ShowS
$cshowsPrec :: Int -> AddListenerCertificatesResponse -> ShowS
Prelude.Show, (forall x.
 AddListenerCertificatesResponse
 -> Rep AddListenerCertificatesResponse x)
-> (forall x.
    Rep AddListenerCertificatesResponse x
    -> AddListenerCertificatesResponse)
-> Generic AddListenerCertificatesResponse
forall x.
Rep AddListenerCertificatesResponse x
-> AddListenerCertificatesResponse
forall x.
AddListenerCertificatesResponse
-> Rep AddListenerCertificatesResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AddListenerCertificatesResponse x
-> AddListenerCertificatesResponse
$cfrom :: forall x.
AddListenerCertificatesResponse
-> Rep AddListenerCertificatesResponse x
Prelude.Generic)

-- |
-- Create a value of 'AddListenerCertificatesResponse' 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:
--
-- 'certificates', 'addListenerCertificatesResponse_certificates' - Information about the certificates in the certificate list.
--
-- 'httpStatus', 'addListenerCertificatesResponse_httpStatus' - The response's http status code.
newAddListenerCertificatesResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  AddListenerCertificatesResponse
newAddListenerCertificatesResponse :: Int -> AddListenerCertificatesResponse
newAddListenerCertificatesResponse Int
pHttpStatus_ =
  AddListenerCertificatesResponse' :: Maybe [Certificate] -> Int -> AddListenerCertificatesResponse
AddListenerCertificatesResponse'
    { $sel:certificates:AddListenerCertificatesResponse' :: Maybe [Certificate]
certificates =
        Maybe [Certificate]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:AddListenerCertificatesResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the certificates in the certificate list.
addListenerCertificatesResponse_certificates :: Lens.Lens' AddListenerCertificatesResponse (Prelude.Maybe [Certificate])
addListenerCertificatesResponse_certificates :: (Maybe [Certificate] -> f (Maybe [Certificate]))
-> AddListenerCertificatesResponse
-> f AddListenerCertificatesResponse
addListenerCertificatesResponse_certificates = (AddListenerCertificatesResponse -> Maybe [Certificate])
-> (AddListenerCertificatesResponse
    -> Maybe [Certificate] -> AddListenerCertificatesResponse)
-> Lens
     AddListenerCertificatesResponse
     AddListenerCertificatesResponse
     (Maybe [Certificate])
     (Maybe [Certificate])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AddListenerCertificatesResponse' {Maybe [Certificate]
certificates :: Maybe [Certificate]
$sel:certificates:AddListenerCertificatesResponse' :: AddListenerCertificatesResponse -> Maybe [Certificate]
certificates} -> Maybe [Certificate]
certificates) (\s :: AddListenerCertificatesResponse
s@AddListenerCertificatesResponse' {} Maybe [Certificate]
a -> AddListenerCertificatesResponse
s {$sel:certificates:AddListenerCertificatesResponse' :: Maybe [Certificate]
certificates = Maybe [Certificate]
a} :: AddListenerCertificatesResponse) ((Maybe [Certificate] -> f (Maybe [Certificate]))
 -> AddListenerCertificatesResponse
 -> f AddListenerCertificatesResponse)
-> ((Maybe [Certificate] -> f (Maybe [Certificate]))
    -> Maybe [Certificate] -> f (Maybe [Certificate]))
-> (Maybe [Certificate] -> f (Maybe [Certificate]))
-> AddListenerCertificatesResponse
-> f AddListenerCertificatesResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Certificate] [Certificate] [Certificate] [Certificate]
-> Iso
     (Maybe [Certificate])
     (Maybe [Certificate])
     (Maybe [Certificate])
     (Maybe [Certificate])
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 [Certificate] [Certificate] [Certificate] [Certificate]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance
  Prelude.NFData
    AddListenerCertificatesResponse