{-# 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.ListPolicyVersions
-- 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)
--
-- Lists the versions of the specified policy and identifies the default
-- version.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions ListPolicyVersions>
-- action.
module Amazonka.IoT.ListPolicyVersions
  ( -- * Creating a Request
    ListPolicyVersions (..),
    newListPolicyVersions,

    -- * Request Lenses
    listPolicyVersions_policyName,

    -- * Destructuring the Response
    ListPolicyVersionsResponse (..),
    newListPolicyVersionsResponse,

    -- * Response Lenses
    listPolicyVersionsResponse_policyVersions,
    listPolicyVersionsResponse_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 ListPolicyVersions operation.
--
-- /See:/ 'newListPolicyVersions' smart constructor.
data ListPolicyVersions = ListPolicyVersions'
  { -- | The policy name.
    ListPolicyVersions -> Text
policyName :: Prelude.Text
  }
  deriving (ListPolicyVersions -> ListPolicyVersions -> Bool
(ListPolicyVersions -> ListPolicyVersions -> Bool)
-> (ListPolicyVersions -> ListPolicyVersions -> Bool)
-> Eq ListPolicyVersions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPolicyVersions -> ListPolicyVersions -> Bool
$c/= :: ListPolicyVersions -> ListPolicyVersions -> Bool
== :: ListPolicyVersions -> ListPolicyVersions -> Bool
$c== :: ListPolicyVersions -> ListPolicyVersions -> Bool
Prelude.Eq, ReadPrec [ListPolicyVersions]
ReadPrec ListPolicyVersions
Int -> ReadS ListPolicyVersions
ReadS [ListPolicyVersions]
(Int -> ReadS ListPolicyVersions)
-> ReadS [ListPolicyVersions]
-> ReadPrec ListPolicyVersions
-> ReadPrec [ListPolicyVersions]
-> Read ListPolicyVersions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPolicyVersions]
$creadListPrec :: ReadPrec [ListPolicyVersions]
readPrec :: ReadPrec ListPolicyVersions
$creadPrec :: ReadPrec ListPolicyVersions
readList :: ReadS [ListPolicyVersions]
$creadList :: ReadS [ListPolicyVersions]
readsPrec :: Int -> ReadS ListPolicyVersions
$creadsPrec :: Int -> ReadS ListPolicyVersions
Prelude.Read, Int -> ListPolicyVersions -> ShowS
[ListPolicyVersions] -> ShowS
ListPolicyVersions -> String
(Int -> ListPolicyVersions -> ShowS)
-> (ListPolicyVersions -> String)
-> ([ListPolicyVersions] -> ShowS)
-> Show ListPolicyVersions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPolicyVersions] -> ShowS
$cshowList :: [ListPolicyVersions] -> ShowS
show :: ListPolicyVersions -> String
$cshow :: ListPolicyVersions -> String
showsPrec :: Int -> ListPolicyVersions -> ShowS
$cshowsPrec :: Int -> ListPolicyVersions -> ShowS
Prelude.Show, (forall x. ListPolicyVersions -> Rep ListPolicyVersions x)
-> (forall x. Rep ListPolicyVersions x -> ListPolicyVersions)
-> Generic ListPolicyVersions
forall x. Rep ListPolicyVersions x -> ListPolicyVersions
forall x. ListPolicyVersions -> Rep ListPolicyVersions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ListPolicyVersions x -> ListPolicyVersions
$cfrom :: forall x. ListPolicyVersions -> Rep ListPolicyVersions x
Prelude.Generic)

-- |
-- Create a value of 'ListPolicyVersions' 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:
--
-- 'policyName', 'listPolicyVersions_policyName' - The policy name.
newListPolicyVersions ::
  -- | 'policyName'
  Prelude.Text ->
  ListPolicyVersions
newListPolicyVersions :: Text -> ListPolicyVersions
newListPolicyVersions Text
pPolicyName_ =
  ListPolicyVersions' :: Text -> ListPolicyVersions
ListPolicyVersions' {$sel:policyName:ListPolicyVersions' :: Text
policyName = Text
pPolicyName_}

-- | The policy name.
listPolicyVersions_policyName :: Lens.Lens' ListPolicyVersions Prelude.Text
listPolicyVersions_policyName :: (Text -> f Text) -> ListPolicyVersions -> f ListPolicyVersions
listPolicyVersions_policyName = (ListPolicyVersions -> Text)
-> (ListPolicyVersions -> Text -> ListPolicyVersions)
-> Lens ListPolicyVersions ListPolicyVersions Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPolicyVersions' {Text
policyName :: Text
$sel:policyName:ListPolicyVersions' :: ListPolicyVersions -> Text
policyName} -> Text
policyName) (\s :: ListPolicyVersions
s@ListPolicyVersions' {} Text
a -> ListPolicyVersions
s {$sel:policyName:ListPolicyVersions' :: Text
policyName = Text
a} :: ListPolicyVersions)

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

instance Prelude.NFData ListPolicyVersions

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

instance Core.ToPath ListPolicyVersions where
  toPath :: ListPolicyVersions -> ByteString
toPath ListPolicyVersions' {Text
policyName :: Text
$sel:policyName:ListPolicyVersions' :: ListPolicyVersions -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/policies/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
policyName, ByteString
"/version"]

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

-- | The output from the ListPolicyVersions operation.
--
-- /See:/ 'newListPolicyVersionsResponse' smart constructor.
data ListPolicyVersionsResponse = ListPolicyVersionsResponse'
  { -- | The policy versions.
    ListPolicyVersionsResponse -> Maybe [PolicyVersion]
policyVersions :: Prelude.Maybe [PolicyVersion],
    -- | The response's http status code.
    ListPolicyVersionsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ListPolicyVersionsResponse -> ListPolicyVersionsResponse -> Bool
(ListPolicyVersionsResponse -> ListPolicyVersionsResponse -> Bool)
-> (ListPolicyVersionsResponse
    -> ListPolicyVersionsResponse -> Bool)
-> Eq ListPolicyVersionsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ListPolicyVersionsResponse -> ListPolicyVersionsResponse -> Bool
$c/= :: ListPolicyVersionsResponse -> ListPolicyVersionsResponse -> Bool
== :: ListPolicyVersionsResponse -> ListPolicyVersionsResponse -> Bool
$c== :: ListPolicyVersionsResponse -> ListPolicyVersionsResponse -> Bool
Prelude.Eq, ReadPrec [ListPolicyVersionsResponse]
ReadPrec ListPolicyVersionsResponse
Int -> ReadS ListPolicyVersionsResponse
ReadS [ListPolicyVersionsResponse]
(Int -> ReadS ListPolicyVersionsResponse)
-> ReadS [ListPolicyVersionsResponse]
-> ReadPrec ListPolicyVersionsResponse
-> ReadPrec [ListPolicyVersionsResponse]
-> Read ListPolicyVersionsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ListPolicyVersionsResponse]
$creadListPrec :: ReadPrec [ListPolicyVersionsResponse]
readPrec :: ReadPrec ListPolicyVersionsResponse
$creadPrec :: ReadPrec ListPolicyVersionsResponse
readList :: ReadS [ListPolicyVersionsResponse]
$creadList :: ReadS [ListPolicyVersionsResponse]
readsPrec :: Int -> ReadS ListPolicyVersionsResponse
$creadsPrec :: Int -> ReadS ListPolicyVersionsResponse
Prelude.Read, Int -> ListPolicyVersionsResponse -> ShowS
[ListPolicyVersionsResponse] -> ShowS
ListPolicyVersionsResponse -> String
(Int -> ListPolicyVersionsResponse -> ShowS)
-> (ListPolicyVersionsResponse -> String)
-> ([ListPolicyVersionsResponse] -> ShowS)
-> Show ListPolicyVersionsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ListPolicyVersionsResponse] -> ShowS
$cshowList :: [ListPolicyVersionsResponse] -> ShowS
show :: ListPolicyVersionsResponse -> String
$cshow :: ListPolicyVersionsResponse -> String
showsPrec :: Int -> ListPolicyVersionsResponse -> ShowS
$cshowsPrec :: Int -> ListPolicyVersionsResponse -> ShowS
Prelude.Show, (forall x.
 ListPolicyVersionsResponse -> Rep ListPolicyVersionsResponse x)
-> (forall x.
    Rep ListPolicyVersionsResponse x -> ListPolicyVersionsResponse)
-> Generic ListPolicyVersionsResponse
forall x.
Rep ListPolicyVersionsResponse x -> ListPolicyVersionsResponse
forall x.
ListPolicyVersionsResponse -> Rep ListPolicyVersionsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ListPolicyVersionsResponse x -> ListPolicyVersionsResponse
$cfrom :: forall x.
ListPolicyVersionsResponse -> Rep ListPolicyVersionsResponse x
Prelude.Generic)

-- |
-- Create a value of 'ListPolicyVersionsResponse' 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:
--
-- 'policyVersions', 'listPolicyVersionsResponse_policyVersions' - The policy versions.
--
-- 'httpStatus', 'listPolicyVersionsResponse_httpStatus' - The response's http status code.
newListPolicyVersionsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ListPolicyVersionsResponse
newListPolicyVersionsResponse :: Int -> ListPolicyVersionsResponse
newListPolicyVersionsResponse Int
pHttpStatus_ =
  ListPolicyVersionsResponse' :: Maybe [PolicyVersion] -> Int -> ListPolicyVersionsResponse
ListPolicyVersionsResponse'
    { $sel:policyVersions:ListPolicyVersionsResponse' :: Maybe [PolicyVersion]
policyVersions =
        Maybe [PolicyVersion]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ListPolicyVersionsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The policy versions.
listPolicyVersionsResponse_policyVersions :: Lens.Lens' ListPolicyVersionsResponse (Prelude.Maybe [PolicyVersion])
listPolicyVersionsResponse_policyVersions :: (Maybe [PolicyVersion] -> f (Maybe [PolicyVersion]))
-> ListPolicyVersionsResponse -> f ListPolicyVersionsResponse
listPolicyVersionsResponse_policyVersions = (ListPolicyVersionsResponse -> Maybe [PolicyVersion])
-> (ListPolicyVersionsResponse
    -> Maybe [PolicyVersion] -> ListPolicyVersionsResponse)
-> Lens
     ListPolicyVersionsResponse
     ListPolicyVersionsResponse
     (Maybe [PolicyVersion])
     (Maybe [PolicyVersion])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ListPolicyVersionsResponse' {Maybe [PolicyVersion]
policyVersions :: Maybe [PolicyVersion]
$sel:policyVersions:ListPolicyVersionsResponse' :: ListPolicyVersionsResponse -> Maybe [PolicyVersion]
policyVersions} -> Maybe [PolicyVersion]
policyVersions) (\s :: ListPolicyVersionsResponse
s@ListPolicyVersionsResponse' {} Maybe [PolicyVersion]
a -> ListPolicyVersionsResponse
s {$sel:policyVersions:ListPolicyVersionsResponse' :: Maybe [PolicyVersion]
policyVersions = Maybe [PolicyVersion]
a} :: ListPolicyVersionsResponse) ((Maybe [PolicyVersion] -> f (Maybe [PolicyVersion]))
 -> ListPolicyVersionsResponse -> f ListPolicyVersionsResponse)
-> ((Maybe [PolicyVersion] -> f (Maybe [PolicyVersion]))
    -> Maybe [PolicyVersion] -> f (Maybe [PolicyVersion]))
-> (Maybe [PolicyVersion] -> f (Maybe [PolicyVersion]))
-> ListPolicyVersionsResponse
-> f ListPolicyVersionsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PolicyVersion] [PolicyVersion] [PolicyVersion] [PolicyVersion]
-> Iso
     (Maybe [PolicyVersion])
     (Maybe [PolicyVersion])
     (Maybe [PolicyVersion])
     (Maybe [PolicyVersion])
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
  [PolicyVersion] [PolicyVersion] [PolicyVersion] [PolicyVersion]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ListPolicyVersionsResponse