{-# 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.DirectConnect.AllocateHostedConnection
-- 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)
--
-- Creates a hosted connection on the specified interconnect or a link
-- aggregation group (LAG) of interconnects.
--
-- Allocates a VLAN number and a specified amount of capacity (bandwidth)
-- for use by a hosted connection on the specified interconnect or LAG of
-- interconnects. Amazon Web Services polices the hosted connection for the
-- specified capacity and the Direct Connect Partner must also police the
-- hosted connection for the specified capacity.
--
-- Intended for use by Direct Connect Partners only.
module Amazonka.DirectConnect.AllocateHostedConnection
  ( -- * Creating a Request
    AllocateHostedConnection (..),
    newAllocateHostedConnection,

    -- * Request Lenses
    allocateHostedConnection_tags,
    allocateHostedConnection_connectionId,
    allocateHostedConnection_ownerAccount,
    allocateHostedConnection_bandwidth,
    allocateHostedConnection_connectionName,
    allocateHostedConnection_vlan,

    -- * Destructuring the Response
    Connection (..),
    newConnection,

    -- * Response Lenses
    connection_lagId,
    connection_macSecCapable,
    connection_portEncryptionStatus,
    connection_vlan,
    connection_location,
    connection_awsDevice,
    connection_hasLogicalRedundancy,
    connection_connectionId,
    connection_awsLogicalDeviceId,
    connection_loaIssueTime,
    connection_partnerName,
    connection_connectionName,
    connection_encryptionMode,
    connection_bandwidth,
    connection_jumboFrameCapable,
    connection_ownerAccount,
    connection_region,
    connection_macSecKeys,
    connection_providerName,
    connection_awsDeviceV2,
    connection_connectionState,
    connection_tags,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DirectConnect.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:/ 'newAllocateHostedConnection' smart constructor.
data AllocateHostedConnection = AllocateHostedConnection'
  { -- | The tags associated with the connection.
    AllocateHostedConnection -> Maybe (NonEmpty Tag)
tags :: Prelude.Maybe (Prelude.NonEmpty Tag),
    -- | The ID of the interconnect or LAG.
    AllocateHostedConnection -> Text
connectionId :: Prelude.Text,
    -- | The ID of the Amazon Web Services account ID of the customer for the
    -- connection.
    AllocateHostedConnection -> Text
ownerAccount :: Prelude.Text,
    -- | The bandwidth of the connection. The possible values are 50Mbps,
    -- 100Mbps, 200Mbps, 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and
    -- 10Gbps. Note that only those Direct Connect Partners who have met
    -- specific requirements are allowed to create a 1Gbps, 2Gbps, 5Gbps or
    -- 10Gbps hosted connection.
    AllocateHostedConnection -> Text
bandwidth :: Prelude.Text,
    -- | The name of the hosted connection.
    AllocateHostedConnection -> Text
connectionName :: Prelude.Text,
    -- | The dedicated VLAN provisioned to the hosted connection.
    AllocateHostedConnection -> Int
vlan :: Prelude.Int
  }
  deriving (AllocateHostedConnection -> AllocateHostedConnection -> Bool
(AllocateHostedConnection -> AllocateHostedConnection -> Bool)
-> (AllocateHostedConnection -> AllocateHostedConnection -> Bool)
-> Eq AllocateHostedConnection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
$c/= :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
== :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
$c== :: AllocateHostedConnection -> AllocateHostedConnection -> Bool
Prelude.Eq, ReadPrec [AllocateHostedConnection]
ReadPrec AllocateHostedConnection
Int -> ReadS AllocateHostedConnection
ReadS [AllocateHostedConnection]
(Int -> ReadS AllocateHostedConnection)
-> ReadS [AllocateHostedConnection]
-> ReadPrec AllocateHostedConnection
-> ReadPrec [AllocateHostedConnection]
-> Read AllocateHostedConnection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllocateHostedConnection]
$creadListPrec :: ReadPrec [AllocateHostedConnection]
readPrec :: ReadPrec AllocateHostedConnection
$creadPrec :: ReadPrec AllocateHostedConnection
readList :: ReadS [AllocateHostedConnection]
$creadList :: ReadS [AllocateHostedConnection]
readsPrec :: Int -> ReadS AllocateHostedConnection
$creadsPrec :: Int -> ReadS AllocateHostedConnection
Prelude.Read, Int -> AllocateHostedConnection -> ShowS
[AllocateHostedConnection] -> ShowS
AllocateHostedConnection -> String
(Int -> AllocateHostedConnection -> ShowS)
-> (AllocateHostedConnection -> String)
-> ([AllocateHostedConnection] -> ShowS)
-> Show AllocateHostedConnection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllocateHostedConnection] -> ShowS
$cshowList :: [AllocateHostedConnection] -> ShowS
show :: AllocateHostedConnection -> String
$cshow :: AllocateHostedConnection -> String
showsPrec :: Int -> AllocateHostedConnection -> ShowS
$cshowsPrec :: Int -> AllocateHostedConnection -> ShowS
Prelude.Show, (forall x.
 AllocateHostedConnection -> Rep AllocateHostedConnection x)
-> (forall x.
    Rep AllocateHostedConnection x -> AllocateHostedConnection)
-> Generic AllocateHostedConnection
forall x.
Rep AllocateHostedConnection x -> AllocateHostedConnection
forall x.
AllocateHostedConnection -> Rep AllocateHostedConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep AllocateHostedConnection x -> AllocateHostedConnection
$cfrom :: forall x.
AllocateHostedConnection -> Rep AllocateHostedConnection x
Prelude.Generic)

-- |
-- Create a value of 'AllocateHostedConnection' 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:
--
-- 'tags', 'allocateHostedConnection_tags' - The tags associated with the connection.
--
-- 'connectionId', 'allocateHostedConnection_connectionId' - The ID of the interconnect or LAG.
--
-- 'ownerAccount', 'allocateHostedConnection_ownerAccount' - The ID of the Amazon Web Services account ID of the customer for the
-- connection.
--
-- 'bandwidth', 'allocateHostedConnection_bandwidth' - The bandwidth of the connection. The possible values are 50Mbps,
-- 100Mbps, 200Mbps, 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and
-- 10Gbps. Note that only those Direct Connect Partners who have met
-- specific requirements are allowed to create a 1Gbps, 2Gbps, 5Gbps or
-- 10Gbps hosted connection.
--
-- 'connectionName', 'allocateHostedConnection_connectionName' - The name of the hosted connection.
--
-- 'vlan', 'allocateHostedConnection_vlan' - The dedicated VLAN provisioned to the hosted connection.
newAllocateHostedConnection ::
  -- | 'connectionId'
  Prelude.Text ->
  -- | 'ownerAccount'
  Prelude.Text ->
  -- | 'bandwidth'
  Prelude.Text ->
  -- | 'connectionName'
  Prelude.Text ->
  -- | 'vlan'
  Prelude.Int ->
  AllocateHostedConnection
newAllocateHostedConnection :: Text -> Text -> Text -> Text -> Int -> AllocateHostedConnection
newAllocateHostedConnection
  Text
pConnectionId_
  Text
pOwnerAccount_
  Text
pBandwidth_
  Text
pConnectionName_
  Int
pVlan_ =
    AllocateHostedConnection' :: Maybe (NonEmpty Tag)
-> Text -> Text -> Text -> Text -> Int -> AllocateHostedConnection
AllocateHostedConnection'
      { $sel:tags:AllocateHostedConnection' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
forall a. Maybe a
Prelude.Nothing,
        $sel:connectionId:AllocateHostedConnection' :: Text
connectionId = Text
pConnectionId_,
        $sel:ownerAccount:AllocateHostedConnection' :: Text
ownerAccount = Text
pOwnerAccount_,
        $sel:bandwidth:AllocateHostedConnection' :: Text
bandwidth = Text
pBandwidth_,
        $sel:connectionName:AllocateHostedConnection' :: Text
connectionName = Text
pConnectionName_,
        $sel:vlan:AllocateHostedConnection' :: Int
vlan = Int
pVlan_
      }

-- | The tags associated with the connection.
allocateHostedConnection_tags :: Lens.Lens' AllocateHostedConnection (Prelude.Maybe (Prelude.NonEmpty Tag))
allocateHostedConnection_tags :: (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> AllocateHostedConnection -> f AllocateHostedConnection
allocateHostedConnection_tags = (AllocateHostedConnection -> Maybe (NonEmpty Tag))
-> (AllocateHostedConnection
    -> Maybe (NonEmpty Tag) -> AllocateHostedConnection)
-> Lens
     AllocateHostedConnection
     AllocateHostedConnection
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Maybe (NonEmpty Tag)
tags :: Maybe (NonEmpty Tag)
$sel:tags:AllocateHostedConnection' :: AllocateHostedConnection -> Maybe (NonEmpty Tag)
tags} -> Maybe (NonEmpty Tag)
tags) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Maybe (NonEmpty Tag)
a -> AllocateHostedConnection
s {$sel:tags:AllocateHostedConnection' :: Maybe (NonEmpty Tag)
tags = Maybe (NonEmpty Tag)
a} :: AllocateHostedConnection) ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
 -> AllocateHostedConnection -> f AllocateHostedConnection)
-> ((Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
    -> Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> (Maybe (NonEmpty Tag) -> f (Maybe (NonEmpty Tag)))
-> AllocateHostedConnection
-> f AllocateHostedConnection
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag)
-> Iso
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
     (Maybe (NonEmpty Tag))
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 (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag) (NonEmpty Tag)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The ID of the interconnect or LAG.
allocateHostedConnection_connectionId :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_connectionId :: (Text -> f Text)
-> AllocateHostedConnection -> f AllocateHostedConnection
allocateHostedConnection_connectionId = (AllocateHostedConnection -> Text)
-> (AllocateHostedConnection -> Text -> AllocateHostedConnection)
-> Lens AllocateHostedConnection AllocateHostedConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
connectionId :: Text
$sel:connectionId:AllocateHostedConnection' :: AllocateHostedConnection -> Text
connectionId} -> Text
connectionId) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:connectionId:AllocateHostedConnection' :: Text
connectionId = Text
a} :: AllocateHostedConnection)

-- | The ID of the Amazon Web Services account ID of the customer for the
-- connection.
allocateHostedConnection_ownerAccount :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_ownerAccount :: (Text -> f Text)
-> AllocateHostedConnection -> f AllocateHostedConnection
allocateHostedConnection_ownerAccount = (AllocateHostedConnection -> Text)
-> (AllocateHostedConnection -> Text -> AllocateHostedConnection)
-> Lens AllocateHostedConnection AllocateHostedConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
ownerAccount :: Text
$sel:ownerAccount:AllocateHostedConnection' :: AllocateHostedConnection -> Text
ownerAccount} -> Text
ownerAccount) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:ownerAccount:AllocateHostedConnection' :: Text
ownerAccount = Text
a} :: AllocateHostedConnection)

-- | The bandwidth of the connection. The possible values are 50Mbps,
-- 100Mbps, 200Mbps, 300Mbps, 400Mbps, 500Mbps, 1Gbps, 2Gbps, 5Gbps, and
-- 10Gbps. Note that only those Direct Connect Partners who have met
-- specific requirements are allowed to create a 1Gbps, 2Gbps, 5Gbps or
-- 10Gbps hosted connection.
allocateHostedConnection_bandwidth :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_bandwidth :: (Text -> f Text)
-> AllocateHostedConnection -> f AllocateHostedConnection
allocateHostedConnection_bandwidth = (AllocateHostedConnection -> Text)
-> (AllocateHostedConnection -> Text -> AllocateHostedConnection)
-> Lens AllocateHostedConnection AllocateHostedConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
bandwidth :: Text
$sel:bandwidth:AllocateHostedConnection' :: AllocateHostedConnection -> Text
bandwidth} -> Text
bandwidth) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:bandwidth:AllocateHostedConnection' :: Text
bandwidth = Text
a} :: AllocateHostedConnection)

-- | The name of the hosted connection.
allocateHostedConnection_connectionName :: Lens.Lens' AllocateHostedConnection Prelude.Text
allocateHostedConnection_connectionName :: (Text -> f Text)
-> AllocateHostedConnection -> f AllocateHostedConnection
allocateHostedConnection_connectionName = (AllocateHostedConnection -> Text)
-> (AllocateHostedConnection -> Text -> AllocateHostedConnection)
-> Lens AllocateHostedConnection AllocateHostedConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Text
connectionName :: Text
$sel:connectionName:AllocateHostedConnection' :: AllocateHostedConnection -> Text
connectionName} -> Text
connectionName) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Text
a -> AllocateHostedConnection
s {$sel:connectionName:AllocateHostedConnection' :: Text
connectionName = Text
a} :: AllocateHostedConnection)

-- | The dedicated VLAN provisioned to the hosted connection.
allocateHostedConnection_vlan :: Lens.Lens' AllocateHostedConnection Prelude.Int
allocateHostedConnection_vlan :: (Int -> f Int)
-> AllocateHostedConnection -> f AllocateHostedConnection
allocateHostedConnection_vlan = (AllocateHostedConnection -> Int)
-> (AllocateHostedConnection -> Int -> AllocateHostedConnection)
-> Lens AllocateHostedConnection AllocateHostedConnection Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllocateHostedConnection' {Int
vlan :: Int
$sel:vlan:AllocateHostedConnection' :: AllocateHostedConnection -> Int
vlan} -> Int
vlan) (\s :: AllocateHostedConnection
s@AllocateHostedConnection' {} Int
a -> AllocateHostedConnection
s {$sel:vlan:AllocateHostedConnection' :: Int
vlan = Int
a} :: AllocateHostedConnection)

instance Core.AWSRequest AllocateHostedConnection where
  type
    AWSResponse AllocateHostedConnection =
      Connection
  request :: AllocateHostedConnection -> Request AllocateHostedConnection
request = Service
-> AllocateHostedConnection -> Request AllocateHostedConnection
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AllocateHostedConnection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AllocateHostedConnection)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse AllocateHostedConnection))
-> Logger
-> Service
-> Proxy AllocateHostedConnection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AllocateHostedConnection)))
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 -> Object -> Either String Connection
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable AllocateHostedConnection

instance Prelude.NFData AllocateHostedConnection

instance Core.ToHeaders AllocateHostedConnection where
  toHeaders :: AllocateHostedConnection -> ResponseHeaders
toHeaders =
    ResponseHeaders -> AllocateHostedConnection -> 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
"OvertureService.AllocateHostedConnection" ::
                          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 AllocateHostedConnection where
  toJSON :: AllocateHostedConnection -> Value
toJSON AllocateHostedConnection' {Int
Maybe (NonEmpty Tag)
Text
vlan :: Int
connectionName :: Text
bandwidth :: Text
ownerAccount :: Text
connectionId :: Text
tags :: Maybe (NonEmpty Tag)
$sel:vlan:AllocateHostedConnection' :: AllocateHostedConnection -> Int
$sel:connectionName:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:bandwidth:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:ownerAccount:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:connectionId:AllocateHostedConnection' :: AllocateHostedConnection -> Text
$sel:tags:AllocateHostedConnection' :: AllocateHostedConnection -> Maybe (NonEmpty Tag)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"tags" Text -> NonEmpty Tag -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty Tag -> Pair) -> Maybe (NonEmpty Tag) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty Tag)
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"connectionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ownerAccount" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ownerAccount),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"bandwidth" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
bandwidth),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"connectionName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"vlan" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Int
vlan)
          ]
      )

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

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