{-# 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.GlobalAccelerator.ProvisionByoipCidr
-- 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)
--
-- Provisions an IP address range to use with your AWS resources through
-- bring your own IP addresses (BYOIP) and creates a corresponding address
-- pool. After the address range is provisioned, it is ready to be
-- advertised using
-- <https://docs.aws.amazon.com/global-accelerator/latest/api/AdvertiseByoipCidr.html AdvertiseByoipCidr>.
--
-- For more information, see
-- <https://docs.aws.amazon.com/global-accelerator/latest/dg/using-byoip.html Bring Your Own IP Addresses (BYOIP)>
-- in the /AWS Global Accelerator Developer Guide/.
module Amazonka.GlobalAccelerator.ProvisionByoipCidr
  ( -- * Creating a Request
    ProvisionByoipCidr (..),
    newProvisionByoipCidr,

    -- * Request Lenses
    provisionByoipCidr_cidr,
    provisionByoipCidr_cidrAuthorizationContext,

    -- * Destructuring the Response
    ProvisionByoipCidrResponse (..),
    newProvisionByoipCidrResponse,

    -- * Response Lenses
    provisionByoipCidrResponse_byoipCidr,
    provisionByoipCidrResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.GlobalAccelerator.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:/ 'newProvisionByoipCidr' smart constructor.
data ProvisionByoipCidr = ProvisionByoipCidr'
  { -- | The public IPv4 address range, in CIDR notation. The most specific IP
    -- prefix that you can specify is \/24. The address range cannot overlap
    -- with another address range that you\'ve brought to this or another
    -- Region.
    ProvisionByoipCidr -> Text
cidr :: Prelude.Text,
    -- | A signed document that proves that you are authorized to bring the
    -- specified IP address range to Amazon using BYOIP.
    ProvisionByoipCidr -> CidrAuthorizationContext
cidrAuthorizationContext :: CidrAuthorizationContext
  }
  deriving (ProvisionByoipCidr -> ProvisionByoipCidr -> Bool
(ProvisionByoipCidr -> ProvisionByoipCidr -> Bool)
-> (ProvisionByoipCidr -> ProvisionByoipCidr -> Bool)
-> Eq ProvisionByoipCidr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProvisionByoipCidr -> ProvisionByoipCidr -> Bool
$c/= :: ProvisionByoipCidr -> ProvisionByoipCidr -> Bool
== :: ProvisionByoipCidr -> ProvisionByoipCidr -> Bool
$c== :: ProvisionByoipCidr -> ProvisionByoipCidr -> Bool
Prelude.Eq, ReadPrec [ProvisionByoipCidr]
ReadPrec ProvisionByoipCidr
Int -> ReadS ProvisionByoipCidr
ReadS [ProvisionByoipCidr]
(Int -> ReadS ProvisionByoipCidr)
-> ReadS [ProvisionByoipCidr]
-> ReadPrec ProvisionByoipCidr
-> ReadPrec [ProvisionByoipCidr]
-> Read ProvisionByoipCidr
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProvisionByoipCidr]
$creadListPrec :: ReadPrec [ProvisionByoipCidr]
readPrec :: ReadPrec ProvisionByoipCidr
$creadPrec :: ReadPrec ProvisionByoipCidr
readList :: ReadS [ProvisionByoipCidr]
$creadList :: ReadS [ProvisionByoipCidr]
readsPrec :: Int -> ReadS ProvisionByoipCidr
$creadsPrec :: Int -> ReadS ProvisionByoipCidr
Prelude.Read, Int -> ProvisionByoipCidr -> ShowS
[ProvisionByoipCidr] -> ShowS
ProvisionByoipCidr -> String
(Int -> ProvisionByoipCidr -> ShowS)
-> (ProvisionByoipCidr -> String)
-> ([ProvisionByoipCidr] -> ShowS)
-> Show ProvisionByoipCidr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProvisionByoipCidr] -> ShowS
$cshowList :: [ProvisionByoipCidr] -> ShowS
show :: ProvisionByoipCidr -> String
$cshow :: ProvisionByoipCidr -> String
showsPrec :: Int -> ProvisionByoipCidr -> ShowS
$cshowsPrec :: Int -> ProvisionByoipCidr -> ShowS
Prelude.Show, (forall x. ProvisionByoipCidr -> Rep ProvisionByoipCidr x)
-> (forall x. Rep ProvisionByoipCidr x -> ProvisionByoipCidr)
-> Generic ProvisionByoipCidr
forall x. Rep ProvisionByoipCidr x -> ProvisionByoipCidr
forall x. ProvisionByoipCidr -> Rep ProvisionByoipCidr x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProvisionByoipCidr x -> ProvisionByoipCidr
$cfrom :: forall x. ProvisionByoipCidr -> Rep ProvisionByoipCidr x
Prelude.Generic)

-- |
-- Create a value of 'ProvisionByoipCidr' 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:
--
-- 'cidr', 'provisionByoipCidr_cidr' - The public IPv4 address range, in CIDR notation. The most specific IP
-- prefix that you can specify is \/24. The address range cannot overlap
-- with another address range that you\'ve brought to this or another
-- Region.
--
-- 'cidrAuthorizationContext', 'provisionByoipCidr_cidrAuthorizationContext' - A signed document that proves that you are authorized to bring the
-- specified IP address range to Amazon using BYOIP.
newProvisionByoipCidr ::
  -- | 'cidr'
  Prelude.Text ->
  -- | 'cidrAuthorizationContext'
  CidrAuthorizationContext ->
  ProvisionByoipCidr
newProvisionByoipCidr :: Text -> CidrAuthorizationContext -> ProvisionByoipCidr
newProvisionByoipCidr
  Text
pCidr_
  CidrAuthorizationContext
pCidrAuthorizationContext_ =
    ProvisionByoipCidr' :: Text -> CidrAuthorizationContext -> ProvisionByoipCidr
ProvisionByoipCidr'
      { $sel:cidr:ProvisionByoipCidr' :: Text
cidr = Text
pCidr_,
        $sel:cidrAuthorizationContext:ProvisionByoipCidr' :: CidrAuthorizationContext
cidrAuthorizationContext =
          CidrAuthorizationContext
pCidrAuthorizationContext_
      }

-- | The public IPv4 address range, in CIDR notation. The most specific IP
-- prefix that you can specify is \/24. The address range cannot overlap
-- with another address range that you\'ve brought to this or another
-- Region.
provisionByoipCidr_cidr :: Lens.Lens' ProvisionByoipCidr Prelude.Text
provisionByoipCidr_cidr :: (Text -> f Text) -> ProvisionByoipCidr -> f ProvisionByoipCidr
provisionByoipCidr_cidr = (ProvisionByoipCidr -> Text)
-> (ProvisionByoipCidr -> Text -> ProvisionByoipCidr)
-> Lens ProvisionByoipCidr ProvisionByoipCidr Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisionByoipCidr' {Text
cidr :: Text
$sel:cidr:ProvisionByoipCidr' :: ProvisionByoipCidr -> Text
cidr} -> Text
cidr) (\s :: ProvisionByoipCidr
s@ProvisionByoipCidr' {} Text
a -> ProvisionByoipCidr
s {$sel:cidr:ProvisionByoipCidr' :: Text
cidr = Text
a} :: ProvisionByoipCidr)

-- | A signed document that proves that you are authorized to bring the
-- specified IP address range to Amazon using BYOIP.
provisionByoipCidr_cidrAuthorizationContext :: Lens.Lens' ProvisionByoipCidr CidrAuthorizationContext
provisionByoipCidr_cidrAuthorizationContext :: (CidrAuthorizationContext -> f CidrAuthorizationContext)
-> ProvisionByoipCidr -> f ProvisionByoipCidr
provisionByoipCidr_cidrAuthorizationContext = (ProvisionByoipCidr -> CidrAuthorizationContext)
-> (ProvisionByoipCidr
    -> CidrAuthorizationContext -> ProvisionByoipCidr)
-> Lens
     ProvisionByoipCidr
     ProvisionByoipCidr
     CidrAuthorizationContext
     CidrAuthorizationContext
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisionByoipCidr' {CidrAuthorizationContext
cidrAuthorizationContext :: CidrAuthorizationContext
$sel:cidrAuthorizationContext:ProvisionByoipCidr' :: ProvisionByoipCidr -> CidrAuthorizationContext
cidrAuthorizationContext} -> CidrAuthorizationContext
cidrAuthorizationContext) (\s :: ProvisionByoipCidr
s@ProvisionByoipCidr' {} CidrAuthorizationContext
a -> ProvisionByoipCidr
s {$sel:cidrAuthorizationContext:ProvisionByoipCidr' :: CidrAuthorizationContext
cidrAuthorizationContext = CidrAuthorizationContext
a} :: ProvisionByoipCidr)

instance Core.AWSRequest ProvisionByoipCidr where
  type
    AWSResponse ProvisionByoipCidr =
      ProvisionByoipCidrResponse
  request :: ProvisionByoipCidr -> Request ProvisionByoipCidr
request = Service -> ProvisionByoipCidr -> Request ProvisionByoipCidr
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ProvisionByoipCidr
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ProvisionByoipCidr)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ProvisionByoipCidr))
-> Logger
-> Service
-> Proxy ProvisionByoipCidr
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse ProvisionByoipCidr)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe ByoipCidr -> Int -> ProvisionByoipCidrResponse
ProvisionByoipCidrResponse'
            (Maybe ByoipCidr -> Int -> ProvisionByoipCidrResponse)
-> Either String (Maybe ByoipCidr)
-> Either String (Int -> ProvisionByoipCidrResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe ByoipCidr)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ByoipCidr")
            Either String (Int -> ProvisionByoipCidrResponse)
-> Either String Int -> Either String ProvisionByoipCidrResponse
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 ProvisionByoipCidr

instance Prelude.NFData ProvisionByoipCidr

instance Core.ToHeaders ProvisionByoipCidr where
  toHeaders :: ProvisionByoipCidr -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ProvisionByoipCidr -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"GlobalAccelerator_V20180706.ProvisionByoipCidr" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON ProvisionByoipCidr where
  toJSON :: ProvisionByoipCidr -> Value
toJSON ProvisionByoipCidr' {Text
CidrAuthorizationContext
cidrAuthorizationContext :: CidrAuthorizationContext
cidr :: Text
$sel:cidrAuthorizationContext:ProvisionByoipCidr' :: ProvisionByoipCidr -> CidrAuthorizationContext
$sel:cidr:ProvisionByoipCidr' :: ProvisionByoipCidr -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Cidr" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
cidr),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"CidrAuthorizationContext"
                  Text -> CidrAuthorizationContext -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CidrAuthorizationContext
cidrAuthorizationContext
              )
          ]
      )

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

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

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

-- |
-- Create a value of 'ProvisionByoipCidrResponse' 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:
--
-- 'byoipCidr', 'provisionByoipCidrResponse_byoipCidr' - Information about the address range.
--
-- 'httpStatus', 'provisionByoipCidrResponse_httpStatus' - The response's http status code.
newProvisionByoipCidrResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ProvisionByoipCidrResponse
newProvisionByoipCidrResponse :: Int -> ProvisionByoipCidrResponse
newProvisionByoipCidrResponse Int
pHttpStatus_ =
  ProvisionByoipCidrResponse' :: Maybe ByoipCidr -> Int -> ProvisionByoipCidrResponse
ProvisionByoipCidrResponse'
    { $sel:byoipCidr:ProvisionByoipCidrResponse' :: Maybe ByoipCidr
byoipCidr =
        Maybe ByoipCidr
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ProvisionByoipCidrResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Information about the address range.
provisionByoipCidrResponse_byoipCidr :: Lens.Lens' ProvisionByoipCidrResponse (Prelude.Maybe ByoipCidr)
provisionByoipCidrResponse_byoipCidr :: (Maybe ByoipCidr -> f (Maybe ByoipCidr))
-> ProvisionByoipCidrResponse -> f ProvisionByoipCidrResponse
provisionByoipCidrResponse_byoipCidr = (ProvisionByoipCidrResponse -> Maybe ByoipCidr)
-> (ProvisionByoipCidrResponse
    -> Maybe ByoipCidr -> ProvisionByoipCidrResponse)
-> Lens
     ProvisionByoipCidrResponse
     ProvisionByoipCidrResponse
     (Maybe ByoipCidr)
     (Maybe ByoipCidr)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProvisionByoipCidrResponse' {Maybe ByoipCidr
byoipCidr :: Maybe ByoipCidr
$sel:byoipCidr:ProvisionByoipCidrResponse' :: ProvisionByoipCidrResponse -> Maybe ByoipCidr
byoipCidr} -> Maybe ByoipCidr
byoipCidr) (\s :: ProvisionByoipCidrResponse
s@ProvisionByoipCidrResponse' {} Maybe ByoipCidr
a -> ProvisionByoipCidrResponse
s {$sel:byoipCidr:ProvisionByoipCidrResponse' :: Maybe ByoipCidr
byoipCidr = Maybe ByoipCidr
a} :: ProvisionByoipCidrResponse)

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

instance Prelude.NFData ProvisionByoipCidrResponse