{-# 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.IoTSecureTunneling.ListTunnels
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- List all tunnels for an Amazon Web Services account. Tunnels are listed
-- by creation time in descending order, newer tunnels will be listed
-- before older tunnels.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions ListTunnels>
-- action.
module Amazonka.IoTSecureTunneling.ListTunnels
  ( -- * Creating a Request
    ListTunnels (..),
    newListTunnels,

    -- * Request Lenses
    listTunnels_maxResults,
    listTunnels_nextToken,
    listTunnels_thingName,

    -- * Destructuring the Response
    ListTunnelsResponse (..),
    newListTunnelsResponse,

    -- * Response Lenses
    listTunnelsResponse_nextToken,
    listTunnelsResponse_tunnelSummaries,
    listTunnelsResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTSecureTunneling.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newListTunnels' smart constructor.
data ListTunnels = ListTunnels'
  { -- | The maximum number of results to return at once.
    ListTunnels -> Maybe Natural
maxResults :: Prelude.Maybe Prelude.Natural,
    -- | To retrieve the next set of results, the nextToken value from a previous
    -- response; otherwise null to receive the first set of results.
    ListTunnels -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the IoT thing associated with the destination device.
    ListTunnels -> Maybe Text
thingName :: Prelude.Maybe Prelude.Text
  }
  deriving (ListTunnels -> ListTunnels -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTunnels -> ListTunnels -> Bool
$c/= :: ListTunnels -> ListTunnels -> Bool
== :: ListTunnels -> ListTunnels -> Bool
$c== :: ListTunnels -> ListTunnels -> Bool
Prelude.Eq, ReadPrec [ListTunnels]
ReadPrec ListTunnels
Int -> ReadS ListTunnels
ReadS [ListTunnels]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTunnels]
$creadListPrec :: ReadPrec [ListTunnels]
readPrec :: ReadPrec ListTunnels
$creadPrec :: ReadPrec ListTunnels
readList :: ReadS [ListTunnels]
$creadList :: ReadS [ListTunnels]
readsPrec :: Int -> ReadS ListTunnels
$creadsPrec :: Int -> ReadS ListTunnels
Prelude.Read, Int -> ListTunnels -> ShowS
[ListTunnels] -> ShowS
ListTunnels -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTunnels] -> ShowS
$cshowList :: [ListTunnels] -> ShowS
show :: ListTunnels -> String
$cshow :: ListTunnels -> String
showsPrec :: Int -> ListTunnels -> ShowS
$cshowsPrec :: Int -> ListTunnels -> ShowS
Prelude.Show, forall x. Rep ListTunnels x -> ListTunnels
forall x. ListTunnels -> Rep ListTunnels x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTunnels x -> ListTunnels
$cfrom :: forall x. ListTunnels -> Rep ListTunnels x
Prelude.Generic)

-- |
-- Create a value of 'ListTunnels' 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:
--
-- 'maxResults', 'listTunnels_maxResults' - The maximum number of results to return at once.
--
-- 'nextToken', 'listTunnels_nextToken' - To retrieve the next set of results, the nextToken value from a previous
-- response; otherwise null to receive the first set of results.
--
-- 'thingName', 'listTunnels_thingName' - The name of the IoT thing associated with the destination device.
newListTunnels ::
  ListTunnels
newListTunnels :: ListTunnels
newListTunnels =
  ListTunnels'
    { $sel:maxResults:ListTunnels' :: Maybe Natural
maxResults = forall a. Maybe a
Prelude.Nothing,
      $sel:nextToken:ListTunnels' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:thingName:ListTunnels' :: Maybe Text
thingName = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum number of results to return at once.
listTunnels_maxResults :: Lens.Lens' ListTunnels (Prelude.Maybe Prelude.Natural)
listTunnels_maxResults :: Lens' ListTunnels (Maybe Natural)
listTunnels_maxResults = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTunnels' {Maybe Natural
maxResults :: Maybe Natural
$sel:maxResults:ListTunnels' :: ListTunnels -> Maybe Natural
maxResults} -> Maybe Natural
maxResults) (\s :: ListTunnels
s@ListTunnels' {} Maybe Natural
a -> ListTunnels
s {$sel:maxResults:ListTunnels' :: Maybe Natural
maxResults = Maybe Natural
a} :: ListTunnels)

-- | To retrieve the next set of results, the nextToken value from a previous
-- response; otherwise null to receive the first set of results.
listTunnels_nextToken :: Lens.Lens' ListTunnels (Prelude.Maybe Prelude.Text)
listTunnels_nextToken :: Lens' ListTunnels (Maybe Text)
listTunnels_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTunnels' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTunnels' :: ListTunnels -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTunnels
s@ListTunnels' {} Maybe Text
a -> ListTunnels
s {$sel:nextToken:ListTunnels' :: Maybe Text
nextToken = Maybe Text
a} :: ListTunnels)

-- | The name of the IoT thing associated with the destination device.
listTunnels_thingName :: Lens.Lens' ListTunnels (Prelude.Maybe Prelude.Text)
listTunnels_thingName :: Lens' ListTunnels (Maybe Text)
listTunnels_thingName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTunnels' {Maybe Text
thingName :: Maybe Text
$sel:thingName:ListTunnels' :: ListTunnels -> Maybe Text
thingName} -> Maybe Text
thingName) (\s :: ListTunnels
s@ListTunnels' {} Maybe Text
a -> ListTunnels
s {$sel:thingName:ListTunnels' :: Maybe Text
thingName = Maybe Text
a} :: ListTunnels)

instance Core.AWSRequest ListTunnels where
  type AWSResponse ListTunnels = ListTunnelsResponse
  request :: (Service -> Service) -> ListTunnels -> Request ListTunnels
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ListTunnels
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ListTunnels)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe [TunnelSummary] -> Int -> ListTunnelsResponse
ListTunnelsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"nextToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"tunnelSummaries"
                            forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ListTunnels where
  hashWithSalt :: Int -> ListTunnels -> Int
hashWithSalt Int
_salt ListTunnels' {Maybe Natural
Maybe Text
thingName :: Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:thingName:ListTunnels' :: ListTunnels -> Maybe Text
$sel:nextToken:ListTunnels' :: ListTunnels -> Maybe Text
$sel:maxResults:ListTunnels' :: ListTunnels -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxResults
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
nextToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
thingName

instance Prelude.NFData ListTunnels where
  rnf :: ListTunnels -> ()
rnf ListTunnels' {Maybe Natural
Maybe Text
thingName :: Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:thingName:ListTunnels' :: ListTunnels -> Maybe Text
$sel:nextToken:ListTunnels' :: ListTunnels -> Maybe Text
$sel:maxResults:ListTunnels' :: ListTunnels -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxResults
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
thingName

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

instance Data.ToJSON ListTunnels where
  toJSON :: ListTunnels -> Value
toJSON ListTunnels' {Maybe Natural
Maybe Text
thingName :: Maybe Text
nextToken :: Maybe Text
maxResults :: Maybe Natural
$sel:thingName:ListTunnels' :: ListTunnels -> Maybe Text
$sel:nextToken:ListTunnels' :: ListTunnels -> Maybe Text
$sel:maxResults:ListTunnels' :: ListTunnels -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"maxResults" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxResults,
            (Key
"nextToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
nextToken,
            (Key
"thingName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
thingName
          ]
      )

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

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

-- | /See:/ 'newListTunnelsResponse' smart constructor.
data ListTunnelsResponse = ListTunnelsResponse'
  { -- | The token to use to get the next set of results, or null if there are no
    -- additional results.
    ListTunnelsResponse -> Maybe Text
nextToken :: Prelude.Maybe Prelude.Text,
    -- | A short description of the tunnels in an Amazon Web Services account.
    ListTunnelsResponse -> Maybe [TunnelSummary]
tunnelSummaries :: Prelude.Maybe [TunnelSummary],
    -- | The response's http status code.
    ListTunnelsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListTunnelsResponse -> ListTunnelsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListTunnelsResponse -> ListTunnelsResponse -> Bool
$c/= :: ListTunnelsResponse -> ListTunnelsResponse -> Bool
== :: ListTunnelsResponse -> ListTunnelsResponse -> Bool
$c== :: ListTunnelsResponse -> ListTunnelsResponse -> Bool
Prelude.Eq, ReadPrec [ListTunnelsResponse]
ReadPrec ListTunnelsResponse
Int -> ReadS ListTunnelsResponse
ReadS [ListTunnelsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListTunnelsResponse]
$creadListPrec :: ReadPrec [ListTunnelsResponse]
readPrec :: ReadPrec ListTunnelsResponse
$creadPrec :: ReadPrec ListTunnelsResponse
readList :: ReadS [ListTunnelsResponse]
$creadList :: ReadS [ListTunnelsResponse]
readsPrec :: Int -> ReadS ListTunnelsResponse
$creadsPrec :: Int -> ReadS ListTunnelsResponse
Prelude.Read, Int -> ListTunnelsResponse -> ShowS
[ListTunnelsResponse] -> ShowS
ListTunnelsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListTunnelsResponse] -> ShowS
$cshowList :: [ListTunnelsResponse] -> ShowS
show :: ListTunnelsResponse -> String
$cshow :: ListTunnelsResponse -> String
showsPrec :: Int -> ListTunnelsResponse -> ShowS
$cshowsPrec :: Int -> ListTunnelsResponse -> ShowS
Prelude.Show, forall x. Rep ListTunnelsResponse x -> ListTunnelsResponse
forall x. ListTunnelsResponse -> Rep ListTunnelsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListTunnelsResponse x -> ListTunnelsResponse
$cfrom :: forall x. ListTunnelsResponse -> Rep ListTunnelsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListTunnelsResponse' 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:
--
-- 'nextToken', 'listTunnelsResponse_nextToken' - The token to use to get the next set of results, or null if there are no
-- additional results.
--
-- 'tunnelSummaries', 'listTunnelsResponse_tunnelSummaries' - A short description of the tunnels in an Amazon Web Services account.
--
-- 'httpStatus', 'listTunnelsResponse_httpStatus' - The response's http status code.
newListTunnelsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListTunnelsResponse
newListTunnelsResponse :: Int -> ListTunnelsResponse
newListTunnelsResponse Int
pHttpStatus_ =
  ListTunnelsResponse'
    { $sel:nextToken:ListTunnelsResponse' :: Maybe Text
nextToken = forall a. Maybe a
Prelude.Nothing,
      $sel:tunnelSummaries:ListTunnelsResponse' :: Maybe [TunnelSummary]
tunnelSummaries = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListTunnelsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The token to use to get the next set of results, or null if there are no
-- additional results.
listTunnelsResponse_nextToken :: Lens.Lens' ListTunnelsResponse (Prelude.Maybe Prelude.Text)
listTunnelsResponse_nextToken :: Lens' ListTunnelsResponse (Maybe Text)
listTunnelsResponse_nextToken = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTunnelsResponse' {Maybe Text
nextToken :: Maybe Text
$sel:nextToken:ListTunnelsResponse' :: ListTunnelsResponse -> Maybe Text
nextToken} -> Maybe Text
nextToken) (\s :: ListTunnelsResponse
s@ListTunnelsResponse' {} Maybe Text
a -> ListTunnelsResponse
s {$sel:nextToken:ListTunnelsResponse' :: Maybe Text
nextToken = Maybe Text
a} :: ListTunnelsResponse)

-- | A short description of the tunnels in an Amazon Web Services account.
listTunnelsResponse_tunnelSummaries :: Lens.Lens' ListTunnelsResponse (Prelude.Maybe [TunnelSummary])
listTunnelsResponse_tunnelSummaries :: Lens' ListTunnelsResponse (Maybe [TunnelSummary])
listTunnelsResponse_tunnelSummaries = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListTunnelsResponse' {Maybe [TunnelSummary]
tunnelSummaries :: Maybe [TunnelSummary]
$sel:tunnelSummaries:ListTunnelsResponse' :: ListTunnelsResponse -> Maybe [TunnelSummary]
tunnelSummaries} -> Maybe [TunnelSummary]
tunnelSummaries) (\s :: ListTunnelsResponse
s@ListTunnelsResponse' {} Maybe [TunnelSummary]
a -> ListTunnelsResponse
s {$sel:tunnelSummaries:ListTunnelsResponse' :: Maybe [TunnelSummary]
tunnelSummaries = Maybe [TunnelSummary]
a} :: ListTunnelsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListTunnelsResponse where
  rnf :: ListTunnelsResponse -> ()
rnf ListTunnelsResponse' {Int
Maybe [TunnelSummary]
Maybe Text
httpStatus :: Int
tunnelSummaries :: Maybe [TunnelSummary]
nextToken :: Maybe Text
$sel:httpStatus:ListTunnelsResponse' :: ListTunnelsResponse -> Int
$sel:tunnelSummaries:ListTunnelsResponse' :: ListTunnelsResponse -> Maybe [TunnelSummary]
$sel:nextToken:ListTunnelsResponse' :: ListTunnelsResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
nextToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [TunnelSummary]
tunnelSummaries
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus