{-# 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.IoT.DescribeEndpoint
-- 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)
--
-- Returns a unique endpoint specific to the Amazon Web Services account
-- making the call.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions DescribeEndpoint>
-- action.
module Amazonka.IoT.DescribeEndpoint
  ( -- * Creating a Request
    DescribeEndpoint (..),
    newDescribeEndpoint,

    -- * Request Lenses
    describeEndpoint_endpointType,

    -- * Destructuring the Response
    DescribeEndpointResponse (..),
    newDescribeEndpointResponse,

    -- * Response Lenses
    describeEndpointResponse_endpointAddress,
    describeEndpointResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT.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

-- | The input for the DescribeEndpoint operation.
--
-- /See:/ 'newDescribeEndpoint' smart constructor.
data DescribeEndpoint = DescribeEndpoint'
  { -- | The endpoint type. Valid endpoint types include:
    --
    -- -   @iot:Data@ - Returns a VeriSign signed data endpoint.
    --
    -- -   @iot:Data-ATS@ - Returns an ATS signed data endpoint.
    --
    -- -   @iot:CredentialProvider@ - Returns an IoT credentials provider API
    --     endpoint.
    --
    -- -   @iot:Jobs@ - Returns an IoT device management Jobs API endpoint.
    --
    -- We strongly recommend that customers use the newer @iot:Data-ATS@
    -- endpoint type to avoid issues related to the widespread distrust of
    -- Symantec certificate authorities.
    DescribeEndpoint -> Maybe Text
endpointType :: Prelude.Maybe Prelude.Text
  }
  deriving (DescribeEndpoint -> DescribeEndpoint -> Bool
(DescribeEndpoint -> DescribeEndpoint -> Bool)
-> (DescribeEndpoint -> DescribeEndpoint -> Bool)
-> Eq DescribeEndpoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeEndpoint -> DescribeEndpoint -> Bool
$c/= :: DescribeEndpoint -> DescribeEndpoint -> Bool
== :: DescribeEndpoint -> DescribeEndpoint -> Bool
$c== :: DescribeEndpoint -> DescribeEndpoint -> Bool
Prelude.Eq, ReadPrec [DescribeEndpoint]
ReadPrec DescribeEndpoint
Int -> ReadS DescribeEndpoint
ReadS [DescribeEndpoint]
(Int -> ReadS DescribeEndpoint)
-> ReadS [DescribeEndpoint]
-> ReadPrec DescribeEndpoint
-> ReadPrec [DescribeEndpoint]
-> Read DescribeEndpoint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeEndpoint]
$creadListPrec :: ReadPrec [DescribeEndpoint]
readPrec :: ReadPrec DescribeEndpoint
$creadPrec :: ReadPrec DescribeEndpoint
readList :: ReadS [DescribeEndpoint]
$creadList :: ReadS [DescribeEndpoint]
readsPrec :: Int -> ReadS DescribeEndpoint
$creadsPrec :: Int -> ReadS DescribeEndpoint
Prelude.Read, Int -> DescribeEndpoint -> ShowS
[DescribeEndpoint] -> ShowS
DescribeEndpoint -> String
(Int -> DescribeEndpoint -> ShowS)
-> (DescribeEndpoint -> String)
-> ([DescribeEndpoint] -> ShowS)
-> Show DescribeEndpoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeEndpoint] -> ShowS
$cshowList :: [DescribeEndpoint] -> ShowS
show :: DescribeEndpoint -> String
$cshow :: DescribeEndpoint -> String
showsPrec :: Int -> DescribeEndpoint -> ShowS
$cshowsPrec :: Int -> DescribeEndpoint -> ShowS
Prelude.Show, (forall x. DescribeEndpoint -> Rep DescribeEndpoint x)
-> (forall x. Rep DescribeEndpoint x -> DescribeEndpoint)
-> Generic DescribeEndpoint
forall x. Rep DescribeEndpoint x -> DescribeEndpoint
forall x. DescribeEndpoint -> Rep DescribeEndpoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeEndpoint x -> DescribeEndpoint
$cfrom :: forall x. DescribeEndpoint -> Rep DescribeEndpoint x
Prelude.Generic)

-- |
-- Create a value of 'DescribeEndpoint' 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:
--
-- 'endpointType', 'describeEndpoint_endpointType' - The endpoint type. Valid endpoint types include:
--
-- -   @iot:Data@ - Returns a VeriSign signed data endpoint.
--
-- -   @iot:Data-ATS@ - Returns an ATS signed data endpoint.
--
-- -   @iot:CredentialProvider@ - Returns an IoT credentials provider API
--     endpoint.
--
-- -   @iot:Jobs@ - Returns an IoT device management Jobs API endpoint.
--
-- We strongly recommend that customers use the newer @iot:Data-ATS@
-- endpoint type to avoid issues related to the widespread distrust of
-- Symantec certificate authorities.
newDescribeEndpoint ::
  DescribeEndpoint
newDescribeEndpoint :: DescribeEndpoint
newDescribeEndpoint =
  DescribeEndpoint' :: Maybe Text -> DescribeEndpoint
DescribeEndpoint' {$sel:endpointType:DescribeEndpoint' :: Maybe Text
endpointType = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The endpoint type. Valid endpoint types include:
--
-- -   @iot:Data@ - Returns a VeriSign signed data endpoint.
--
-- -   @iot:Data-ATS@ - Returns an ATS signed data endpoint.
--
-- -   @iot:CredentialProvider@ - Returns an IoT credentials provider API
--     endpoint.
--
-- -   @iot:Jobs@ - Returns an IoT device management Jobs API endpoint.
--
-- We strongly recommend that customers use the newer @iot:Data-ATS@
-- endpoint type to avoid issues related to the widespread distrust of
-- Symantec certificate authorities.
describeEndpoint_endpointType :: Lens.Lens' DescribeEndpoint (Prelude.Maybe Prelude.Text)
describeEndpoint_endpointType :: (Maybe Text -> f (Maybe Text))
-> DescribeEndpoint -> f DescribeEndpoint
describeEndpoint_endpointType = (DescribeEndpoint -> Maybe Text)
-> (DescribeEndpoint -> Maybe Text -> DescribeEndpoint)
-> Lens DescribeEndpoint DescribeEndpoint (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEndpoint' {Maybe Text
endpointType :: Maybe Text
$sel:endpointType:DescribeEndpoint' :: DescribeEndpoint -> Maybe Text
endpointType} -> Maybe Text
endpointType) (\s :: DescribeEndpoint
s@DescribeEndpoint' {} Maybe Text
a -> DescribeEndpoint
s {$sel:endpointType:DescribeEndpoint' :: Maybe Text
endpointType = Maybe Text
a} :: DescribeEndpoint)

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

instance Prelude.NFData DescribeEndpoint

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

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

instance Core.ToQuery DescribeEndpoint where
  toQuery :: DescribeEndpoint -> QueryString
toQuery DescribeEndpoint' {Maybe Text
endpointType :: Maybe Text
$sel:endpointType:DescribeEndpoint' :: DescribeEndpoint -> Maybe Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"endpointType" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
endpointType]

-- | The output from the DescribeEndpoint operation.
--
-- /See:/ 'newDescribeEndpointResponse' smart constructor.
data DescribeEndpointResponse = DescribeEndpointResponse'
  { -- | The endpoint. The format of the endpoint is as follows:
    -- /identifier/.iot./region/.amazonaws.com.
    DescribeEndpointResponse -> Maybe Text
endpointAddress :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DescribeEndpointResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeEndpointResponse -> DescribeEndpointResponse -> Bool
(DescribeEndpointResponse -> DescribeEndpointResponse -> Bool)
-> (DescribeEndpointResponse -> DescribeEndpointResponse -> Bool)
-> Eq DescribeEndpointResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeEndpointResponse -> DescribeEndpointResponse -> Bool
$c/= :: DescribeEndpointResponse -> DescribeEndpointResponse -> Bool
== :: DescribeEndpointResponse -> DescribeEndpointResponse -> Bool
$c== :: DescribeEndpointResponse -> DescribeEndpointResponse -> Bool
Prelude.Eq, ReadPrec [DescribeEndpointResponse]
ReadPrec DescribeEndpointResponse
Int -> ReadS DescribeEndpointResponse
ReadS [DescribeEndpointResponse]
(Int -> ReadS DescribeEndpointResponse)
-> ReadS [DescribeEndpointResponse]
-> ReadPrec DescribeEndpointResponse
-> ReadPrec [DescribeEndpointResponse]
-> Read DescribeEndpointResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeEndpointResponse]
$creadListPrec :: ReadPrec [DescribeEndpointResponse]
readPrec :: ReadPrec DescribeEndpointResponse
$creadPrec :: ReadPrec DescribeEndpointResponse
readList :: ReadS [DescribeEndpointResponse]
$creadList :: ReadS [DescribeEndpointResponse]
readsPrec :: Int -> ReadS DescribeEndpointResponse
$creadsPrec :: Int -> ReadS DescribeEndpointResponse
Prelude.Read, Int -> DescribeEndpointResponse -> ShowS
[DescribeEndpointResponse] -> ShowS
DescribeEndpointResponse -> String
(Int -> DescribeEndpointResponse -> ShowS)
-> (DescribeEndpointResponse -> String)
-> ([DescribeEndpointResponse] -> ShowS)
-> Show DescribeEndpointResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeEndpointResponse] -> ShowS
$cshowList :: [DescribeEndpointResponse] -> ShowS
show :: DescribeEndpointResponse -> String
$cshow :: DescribeEndpointResponse -> String
showsPrec :: Int -> DescribeEndpointResponse -> ShowS
$cshowsPrec :: Int -> DescribeEndpointResponse -> ShowS
Prelude.Show, (forall x.
 DescribeEndpointResponse -> Rep DescribeEndpointResponse x)
-> (forall x.
    Rep DescribeEndpointResponse x -> DescribeEndpointResponse)
-> Generic DescribeEndpointResponse
forall x.
Rep DescribeEndpointResponse x -> DescribeEndpointResponse
forall x.
DescribeEndpointResponse -> Rep DescribeEndpointResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeEndpointResponse x -> DescribeEndpointResponse
$cfrom :: forall x.
DescribeEndpointResponse -> Rep DescribeEndpointResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeEndpointResponse' 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:
--
-- 'endpointAddress', 'describeEndpointResponse_endpointAddress' - The endpoint. The format of the endpoint is as follows:
-- /identifier/.iot./region/.amazonaws.com.
--
-- 'httpStatus', 'describeEndpointResponse_httpStatus' - The response's http status code.
newDescribeEndpointResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeEndpointResponse
newDescribeEndpointResponse :: Int -> DescribeEndpointResponse
newDescribeEndpointResponse Int
pHttpStatus_ =
  DescribeEndpointResponse' :: Maybe Text -> Int -> DescribeEndpointResponse
DescribeEndpointResponse'
    { $sel:endpointAddress:DescribeEndpointResponse' :: Maybe Text
endpointAddress =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeEndpointResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The endpoint. The format of the endpoint is as follows:
-- /identifier/.iot./region/.amazonaws.com.
describeEndpointResponse_endpointAddress :: Lens.Lens' DescribeEndpointResponse (Prelude.Maybe Prelude.Text)
describeEndpointResponse_endpointAddress :: (Maybe Text -> f (Maybe Text))
-> DescribeEndpointResponse -> f DescribeEndpointResponse
describeEndpointResponse_endpointAddress = (DescribeEndpointResponse -> Maybe Text)
-> (DescribeEndpointResponse
    -> Maybe Text -> DescribeEndpointResponse)
-> Lens
     DescribeEndpointResponse
     DescribeEndpointResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEndpointResponse' {Maybe Text
endpointAddress :: Maybe Text
$sel:endpointAddress:DescribeEndpointResponse' :: DescribeEndpointResponse -> Maybe Text
endpointAddress} -> Maybe Text
endpointAddress) (\s :: DescribeEndpointResponse
s@DescribeEndpointResponse' {} Maybe Text
a -> DescribeEndpointResponse
s {$sel:endpointAddress:DescribeEndpointResponse' :: Maybe Text
endpointAddress = Maybe Text
a} :: DescribeEndpointResponse)

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

instance Prelude.NFData DescribeEndpointResponse