{-# 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.SetDefaultPolicyVersion
-- 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)
--
-- Sets the specified version of the specified policy as the policy\'s
-- default (operative) version. This action affects all certificates to
-- which the policy is attached. To list the principals the policy is
-- attached to, use the ListPrincipalPolicies action.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions SetDefaultPolicyVersion>
-- action.
module Amazonka.IoT.SetDefaultPolicyVersion
  ( -- * Creating a Request
    SetDefaultPolicyVersion (..),
    newSetDefaultPolicyVersion,

    -- * Request Lenses
    setDefaultPolicyVersion_policyName,
    setDefaultPolicyVersion_policyVersionId,

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

-- |
-- Create a value of 'SetDefaultPolicyVersion' 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', 'setDefaultPolicyVersion_policyName' - The policy name.
--
-- 'policyVersionId', 'setDefaultPolicyVersion_policyVersionId' - The policy version ID.
newSetDefaultPolicyVersion ::
  -- | 'policyName'
  Prelude.Text ->
  -- | 'policyVersionId'
  Prelude.Text ->
  SetDefaultPolicyVersion
newSetDefaultPolicyVersion :: Text -> Text -> SetDefaultPolicyVersion
newSetDefaultPolicyVersion
  Text
pPolicyName_
  Text
pPolicyVersionId_ =
    SetDefaultPolicyVersion' :: Text -> Text -> SetDefaultPolicyVersion
SetDefaultPolicyVersion'
      { $sel:policyName:SetDefaultPolicyVersion' :: Text
policyName = Text
pPolicyName_,
        $sel:policyVersionId:SetDefaultPolicyVersion' :: Text
policyVersionId = Text
pPolicyVersionId_
      }

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

-- | The policy version ID.
setDefaultPolicyVersion_policyVersionId :: Lens.Lens' SetDefaultPolicyVersion Prelude.Text
setDefaultPolicyVersion_policyVersionId :: (Text -> f Text)
-> SetDefaultPolicyVersion -> f SetDefaultPolicyVersion
setDefaultPolicyVersion_policyVersionId = (SetDefaultPolicyVersion -> Text)
-> (SetDefaultPolicyVersion -> Text -> SetDefaultPolicyVersion)
-> Lens SetDefaultPolicyVersion SetDefaultPolicyVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDefaultPolicyVersion' {Text
policyVersionId :: Text
$sel:policyVersionId:SetDefaultPolicyVersion' :: SetDefaultPolicyVersion -> Text
policyVersionId} -> Text
policyVersionId) (\s :: SetDefaultPolicyVersion
s@SetDefaultPolicyVersion' {} Text
a -> SetDefaultPolicyVersion
s {$sel:policyVersionId:SetDefaultPolicyVersion' :: Text
policyVersionId = Text
a} :: SetDefaultPolicyVersion)

instance Core.AWSRequest SetDefaultPolicyVersion where
  type
    AWSResponse SetDefaultPolicyVersion =
      SetDefaultPolicyVersionResponse
  request :: SetDefaultPolicyVersion -> Request SetDefaultPolicyVersion
request = Service
-> SetDefaultPolicyVersion -> Request SetDefaultPolicyVersion
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SetDefaultPolicyVersion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SetDefaultPolicyVersion)))
response =
    AWSResponse SetDefaultPolicyVersion
-> Logger
-> Service
-> Proxy SetDefaultPolicyVersion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SetDefaultPolicyVersion)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse SetDefaultPolicyVersion
SetDefaultPolicyVersionResponse
SetDefaultPolicyVersionResponse'

instance Prelude.Hashable SetDefaultPolicyVersion

instance Prelude.NFData SetDefaultPolicyVersion

instance Core.ToHeaders SetDefaultPolicyVersion where
  toHeaders :: SetDefaultPolicyVersion -> [Header]
toHeaders = [Header] -> SetDefaultPolicyVersion -> [Header]
forall a b. a -> b -> a
Prelude.const [Header]
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON SetDefaultPolicyVersion where
  toJSON :: SetDefaultPolicyVersion -> Value
toJSON = Value -> SetDefaultPolicyVersion -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath SetDefaultPolicyVersion where
  toPath :: SetDefaultPolicyVersion -> ByteString
toPath SetDefaultPolicyVersion' {Text
policyVersionId :: Text
policyName :: Text
$sel:policyVersionId:SetDefaultPolicyVersion' :: SetDefaultPolicyVersion -> Text
$sel:policyName:SetDefaultPolicyVersion' :: SetDefaultPolicyVersion -> 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/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
policyVersionId
      ]

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

-- | /See:/ 'newSetDefaultPolicyVersionResponse' smart constructor.
data SetDefaultPolicyVersionResponse = SetDefaultPolicyVersionResponse'
  {
  }
  deriving (SetDefaultPolicyVersionResponse
-> SetDefaultPolicyVersionResponse -> Bool
(SetDefaultPolicyVersionResponse
 -> SetDefaultPolicyVersionResponse -> Bool)
-> (SetDefaultPolicyVersionResponse
    -> SetDefaultPolicyVersionResponse -> Bool)
-> Eq SetDefaultPolicyVersionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetDefaultPolicyVersionResponse
-> SetDefaultPolicyVersionResponse -> Bool
$c/= :: SetDefaultPolicyVersionResponse
-> SetDefaultPolicyVersionResponse -> Bool
== :: SetDefaultPolicyVersionResponse
-> SetDefaultPolicyVersionResponse -> Bool
$c== :: SetDefaultPolicyVersionResponse
-> SetDefaultPolicyVersionResponse -> Bool
Prelude.Eq, ReadPrec [SetDefaultPolicyVersionResponse]
ReadPrec SetDefaultPolicyVersionResponse
Int -> ReadS SetDefaultPolicyVersionResponse
ReadS [SetDefaultPolicyVersionResponse]
(Int -> ReadS SetDefaultPolicyVersionResponse)
-> ReadS [SetDefaultPolicyVersionResponse]
-> ReadPrec SetDefaultPolicyVersionResponse
-> ReadPrec [SetDefaultPolicyVersionResponse]
-> Read SetDefaultPolicyVersionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetDefaultPolicyVersionResponse]
$creadListPrec :: ReadPrec [SetDefaultPolicyVersionResponse]
readPrec :: ReadPrec SetDefaultPolicyVersionResponse
$creadPrec :: ReadPrec SetDefaultPolicyVersionResponse
readList :: ReadS [SetDefaultPolicyVersionResponse]
$creadList :: ReadS [SetDefaultPolicyVersionResponse]
readsPrec :: Int -> ReadS SetDefaultPolicyVersionResponse
$creadsPrec :: Int -> ReadS SetDefaultPolicyVersionResponse
Prelude.Read, Int -> SetDefaultPolicyVersionResponse -> ShowS
[SetDefaultPolicyVersionResponse] -> ShowS
SetDefaultPolicyVersionResponse -> String
(Int -> SetDefaultPolicyVersionResponse -> ShowS)
-> (SetDefaultPolicyVersionResponse -> String)
-> ([SetDefaultPolicyVersionResponse] -> ShowS)
-> Show SetDefaultPolicyVersionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetDefaultPolicyVersionResponse] -> ShowS
$cshowList :: [SetDefaultPolicyVersionResponse] -> ShowS
show :: SetDefaultPolicyVersionResponse -> String
$cshow :: SetDefaultPolicyVersionResponse -> String
showsPrec :: Int -> SetDefaultPolicyVersionResponse -> ShowS
$cshowsPrec :: Int -> SetDefaultPolicyVersionResponse -> ShowS
Prelude.Show, (forall x.
 SetDefaultPolicyVersionResponse
 -> Rep SetDefaultPolicyVersionResponse x)
-> (forall x.
    Rep SetDefaultPolicyVersionResponse x
    -> SetDefaultPolicyVersionResponse)
-> Generic SetDefaultPolicyVersionResponse
forall x.
Rep SetDefaultPolicyVersionResponse x
-> SetDefaultPolicyVersionResponse
forall x.
SetDefaultPolicyVersionResponse
-> Rep SetDefaultPolicyVersionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep SetDefaultPolicyVersionResponse x
-> SetDefaultPolicyVersionResponse
$cfrom :: forall x.
SetDefaultPolicyVersionResponse
-> Rep SetDefaultPolicyVersionResponse x
Prelude.Generic)

-- |
-- Create a value of 'SetDefaultPolicyVersionResponse' 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.
newSetDefaultPolicyVersionResponse ::
  SetDefaultPolicyVersionResponse
newSetDefaultPolicyVersionResponse :: SetDefaultPolicyVersionResponse
newSetDefaultPolicyVersionResponse =
  SetDefaultPolicyVersionResponse
SetDefaultPolicyVersionResponse'

instance
  Prelude.NFData
    SetDefaultPolicyVersionResponse