{-# 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.DMS.TestConnection
-- 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)
--
-- Tests the connection between the replication instance and the endpoint.
module Amazonka.DMS.TestConnection
  ( -- * Creating a Request
    TestConnection (..),
    newTestConnection,

    -- * Request Lenses
    testConnection_replicationInstanceArn,
    testConnection_endpointArn,

    -- * Destructuring the Response
    TestConnectionResponse (..),
    newTestConnectionResponse,

    -- * Response Lenses
    testConnectionResponse_connection,
    testConnectionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.DMS.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:/ 'newTestConnection' smart constructor.
data TestConnection = TestConnection'
  { -- | The Amazon Resource Name (ARN) of the replication instance.
    TestConnection -> Text
replicationInstanceArn :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) string that uniquely identifies the
    -- endpoint.
    TestConnection -> Text
endpointArn :: Prelude.Text
  }
  deriving (TestConnection -> TestConnection -> Bool
(TestConnection -> TestConnection -> Bool)
-> (TestConnection -> TestConnection -> Bool) -> Eq TestConnection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TestConnection -> TestConnection -> Bool
$c/= :: TestConnection -> TestConnection -> Bool
== :: TestConnection -> TestConnection -> Bool
$c== :: TestConnection -> TestConnection -> Bool
Prelude.Eq, ReadPrec [TestConnection]
ReadPrec TestConnection
Int -> ReadS TestConnection
ReadS [TestConnection]
(Int -> ReadS TestConnection)
-> ReadS [TestConnection]
-> ReadPrec TestConnection
-> ReadPrec [TestConnection]
-> Read TestConnection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TestConnection]
$creadListPrec :: ReadPrec [TestConnection]
readPrec :: ReadPrec TestConnection
$creadPrec :: ReadPrec TestConnection
readList :: ReadS [TestConnection]
$creadList :: ReadS [TestConnection]
readsPrec :: Int -> ReadS TestConnection
$creadsPrec :: Int -> ReadS TestConnection
Prelude.Read, Int -> TestConnection -> ShowS
[TestConnection] -> ShowS
TestConnection -> String
(Int -> TestConnection -> ShowS)
-> (TestConnection -> String)
-> ([TestConnection] -> ShowS)
-> Show TestConnection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TestConnection] -> ShowS
$cshowList :: [TestConnection] -> ShowS
show :: TestConnection -> String
$cshow :: TestConnection -> String
showsPrec :: Int -> TestConnection -> ShowS
$cshowsPrec :: Int -> TestConnection -> ShowS
Prelude.Show, (forall x. TestConnection -> Rep TestConnection x)
-> (forall x. Rep TestConnection x -> TestConnection)
-> Generic TestConnection
forall x. Rep TestConnection x -> TestConnection
forall x. TestConnection -> Rep TestConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TestConnection x -> TestConnection
$cfrom :: forall x. TestConnection -> Rep TestConnection x
Prelude.Generic)

-- |
-- Create a value of 'TestConnection' 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:
--
-- 'replicationInstanceArn', 'testConnection_replicationInstanceArn' - The Amazon Resource Name (ARN) of the replication instance.
--
-- 'endpointArn', 'testConnection_endpointArn' - The Amazon Resource Name (ARN) string that uniquely identifies the
-- endpoint.
newTestConnection ::
  -- | 'replicationInstanceArn'
  Prelude.Text ->
  -- | 'endpointArn'
  Prelude.Text ->
  TestConnection
newTestConnection :: Text -> Text -> TestConnection
newTestConnection
  Text
pReplicationInstanceArn_
  Text
pEndpointArn_ =
    TestConnection' :: Text -> Text -> TestConnection
TestConnection'
      { $sel:replicationInstanceArn:TestConnection' :: Text
replicationInstanceArn =
          Text
pReplicationInstanceArn_,
        $sel:endpointArn:TestConnection' :: Text
endpointArn = Text
pEndpointArn_
      }

-- | The Amazon Resource Name (ARN) of the replication instance.
testConnection_replicationInstanceArn :: Lens.Lens' TestConnection Prelude.Text
testConnection_replicationInstanceArn :: (Text -> f Text) -> TestConnection -> f TestConnection
testConnection_replicationInstanceArn = (TestConnection -> Text)
-> (TestConnection -> Text -> TestConnection)
-> Lens TestConnection TestConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestConnection' {Text
replicationInstanceArn :: Text
$sel:replicationInstanceArn:TestConnection' :: TestConnection -> Text
replicationInstanceArn} -> Text
replicationInstanceArn) (\s :: TestConnection
s@TestConnection' {} Text
a -> TestConnection
s {$sel:replicationInstanceArn:TestConnection' :: Text
replicationInstanceArn = Text
a} :: TestConnection)

-- | The Amazon Resource Name (ARN) string that uniquely identifies the
-- endpoint.
testConnection_endpointArn :: Lens.Lens' TestConnection Prelude.Text
testConnection_endpointArn :: (Text -> f Text) -> TestConnection -> f TestConnection
testConnection_endpointArn = (TestConnection -> Text)
-> (TestConnection -> Text -> TestConnection)
-> Lens TestConnection TestConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestConnection' {Text
endpointArn :: Text
$sel:endpointArn:TestConnection' :: TestConnection -> Text
endpointArn} -> Text
endpointArn) (\s :: TestConnection
s@TestConnection' {} Text
a -> TestConnection
s {$sel:endpointArn:TestConnection' :: Text
endpointArn = Text
a} :: TestConnection)

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

instance Prelude.NFData TestConnection

instance Core.ToHeaders TestConnection where
  toHeaders :: TestConnection -> ResponseHeaders
toHeaders =
    ResponseHeaders -> TestConnection -> 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
"AmazonDMSv20160101.TestConnection" ::
                          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 TestConnection where
  toJSON :: TestConnection -> Value
toJSON TestConnection' {Text
endpointArn :: Text
replicationInstanceArn :: Text
$sel:endpointArn:TestConnection' :: TestConnection -> Text
$sel:replicationInstanceArn:TestConnection' :: TestConnection -> 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
"ReplicationInstanceArn"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
replicationInstanceArn
              ),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"EndpointArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
endpointArn)
          ]
      )

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

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

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

-- |
-- Create a value of 'TestConnectionResponse' 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:
--
-- 'connection', 'testConnectionResponse_connection' - The connection tested.
--
-- 'httpStatus', 'testConnectionResponse_httpStatus' - The response's http status code.
newTestConnectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TestConnectionResponse
newTestConnectionResponse :: Int -> TestConnectionResponse
newTestConnectionResponse Int
pHttpStatus_ =
  TestConnectionResponse' :: Maybe Connection -> Int -> TestConnectionResponse
TestConnectionResponse'
    { $sel:connection:TestConnectionResponse' :: Maybe Connection
connection =
        Maybe Connection
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TestConnectionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The connection tested.
testConnectionResponse_connection :: Lens.Lens' TestConnectionResponse (Prelude.Maybe Connection)
testConnectionResponse_connection :: (Maybe Connection -> f (Maybe Connection))
-> TestConnectionResponse -> f TestConnectionResponse
testConnectionResponse_connection = (TestConnectionResponse -> Maybe Connection)
-> (TestConnectionResponse
    -> Maybe Connection -> TestConnectionResponse)
-> Lens
     TestConnectionResponse
     TestConnectionResponse
     (Maybe Connection)
     (Maybe Connection)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TestConnectionResponse' {Maybe Connection
connection :: Maybe Connection
$sel:connection:TestConnectionResponse' :: TestConnectionResponse -> Maybe Connection
connection} -> Maybe Connection
connection) (\s :: TestConnectionResponse
s@TestConnectionResponse' {} Maybe Connection
a -> TestConnectionResponse
s {$sel:connection:TestConnectionResponse' :: Maybe Connection
connection = Maybe Connection
a} :: TestConnectionResponse)

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

instance Prelude.NFData TestConnectionResponse