{-# 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.UpdateCertificate
-- 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)
--
-- Updates the status of the specified certificate. This operation is
-- idempotent.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions UpdateCertificate>
-- action.
--
-- Certificates must be in the ACTIVE state to authenticate devices that
-- use a certificate to connect to IoT.
--
-- Within a few minutes of updating a certificate from the ACTIVE state to
-- any other state, IoT disconnects all devices that used that certificate
-- to connect. Devices cannot use a certificate that is not in the ACTIVE
-- state to reconnect.
module Amazonka.IoT.UpdateCertificate
  ( -- * Creating a Request
    UpdateCertificate (..),
    newUpdateCertificate,

    -- * Request Lenses
    updateCertificate_certificateId,
    updateCertificate_newStatus,

    -- * Destructuring the Response
    UpdateCertificateResponse (..),
    newUpdateCertificateResponse,
  )
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 UpdateCertificate operation.
--
-- /See:/ 'newUpdateCertificate' smart constructor.
data UpdateCertificate = UpdateCertificate'
  { -- | The ID of the certificate. (The last part of the certificate ARN
    -- contains the certificate ID.)
    UpdateCertificate -> Text
certificateId :: Prelude.Text,
    -- | The new status.
    --
    -- __Note:__ Setting the status to PENDING_TRANSFER or PENDING_ACTIVATION
    -- will result in an exception being thrown. PENDING_TRANSFER and
    -- PENDING_ACTIVATION are statuses used internally by IoT. They are not
    -- intended for developer use.
    --
    -- __Note:__ The status value REGISTER_INACTIVE is deprecated and should
    -- not be used.
    UpdateCertificate -> CertificateStatus
newStatus' :: CertificateStatus
  }
  deriving (UpdateCertificate -> UpdateCertificate -> Bool
(UpdateCertificate -> UpdateCertificate -> Bool)
-> (UpdateCertificate -> UpdateCertificate -> Bool)
-> Eq UpdateCertificate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateCertificate -> UpdateCertificate -> Bool
$c/= :: UpdateCertificate -> UpdateCertificate -> Bool
== :: UpdateCertificate -> UpdateCertificate -> Bool
$c== :: UpdateCertificate -> UpdateCertificate -> Bool
Prelude.Eq, ReadPrec [UpdateCertificate]
ReadPrec UpdateCertificate
Int -> ReadS UpdateCertificate
ReadS [UpdateCertificate]
(Int -> ReadS UpdateCertificate)
-> ReadS [UpdateCertificate]
-> ReadPrec UpdateCertificate
-> ReadPrec [UpdateCertificate]
-> Read UpdateCertificate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateCertificate]
$creadListPrec :: ReadPrec [UpdateCertificate]
readPrec :: ReadPrec UpdateCertificate
$creadPrec :: ReadPrec UpdateCertificate
readList :: ReadS [UpdateCertificate]
$creadList :: ReadS [UpdateCertificate]
readsPrec :: Int -> ReadS UpdateCertificate
$creadsPrec :: Int -> ReadS UpdateCertificate
Prelude.Read, Int -> UpdateCertificate -> ShowS
[UpdateCertificate] -> ShowS
UpdateCertificate -> String
(Int -> UpdateCertificate -> ShowS)
-> (UpdateCertificate -> String)
-> ([UpdateCertificate] -> ShowS)
-> Show UpdateCertificate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateCertificate] -> ShowS
$cshowList :: [UpdateCertificate] -> ShowS
show :: UpdateCertificate -> String
$cshow :: UpdateCertificate -> String
showsPrec :: Int -> UpdateCertificate -> ShowS
$cshowsPrec :: Int -> UpdateCertificate -> ShowS
Prelude.Show, (forall x. UpdateCertificate -> Rep UpdateCertificate x)
-> (forall x. Rep UpdateCertificate x -> UpdateCertificate)
-> Generic UpdateCertificate
forall x. Rep UpdateCertificate x -> UpdateCertificate
forall x. UpdateCertificate -> Rep UpdateCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateCertificate x -> UpdateCertificate
$cfrom :: forall x. UpdateCertificate -> Rep UpdateCertificate x
Prelude.Generic)

-- |
-- Create a value of 'UpdateCertificate' 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:
--
-- 'certificateId', 'updateCertificate_certificateId' - The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
--
-- 'newStatus'', 'updateCertificate_newStatus' - The new status.
--
-- __Note:__ Setting the status to PENDING_TRANSFER or PENDING_ACTIVATION
-- will result in an exception being thrown. PENDING_TRANSFER and
-- PENDING_ACTIVATION are statuses used internally by IoT. They are not
-- intended for developer use.
--
-- __Note:__ The status value REGISTER_INACTIVE is deprecated and should
-- not be used.
newUpdateCertificate ::
  -- | 'certificateId'
  Prelude.Text ->
  -- | 'newStatus''
  CertificateStatus ->
  UpdateCertificate
newUpdateCertificate :: Text -> CertificateStatus -> UpdateCertificate
newUpdateCertificate Text
pCertificateId_ CertificateStatus
pNewStatus_ =
  UpdateCertificate' :: Text -> CertificateStatus -> UpdateCertificate
UpdateCertificate'
    { $sel:certificateId:UpdateCertificate' :: Text
certificateId = Text
pCertificateId_,
      $sel:newStatus':UpdateCertificate' :: CertificateStatus
newStatus' = CertificateStatus
pNewStatus_
    }

-- | The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
updateCertificate_certificateId :: Lens.Lens' UpdateCertificate Prelude.Text
updateCertificate_certificateId :: (Text -> f Text) -> UpdateCertificate -> f UpdateCertificate
updateCertificate_certificateId = (UpdateCertificate -> Text)
-> (UpdateCertificate -> Text -> UpdateCertificate)
-> Lens UpdateCertificate UpdateCertificate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCertificate' {Text
certificateId :: Text
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
certificateId} -> Text
certificateId) (\s :: UpdateCertificate
s@UpdateCertificate' {} Text
a -> UpdateCertificate
s {$sel:certificateId:UpdateCertificate' :: Text
certificateId = Text
a} :: UpdateCertificate)

-- | The new status.
--
-- __Note:__ Setting the status to PENDING_TRANSFER or PENDING_ACTIVATION
-- will result in an exception being thrown. PENDING_TRANSFER and
-- PENDING_ACTIVATION are statuses used internally by IoT. They are not
-- intended for developer use.
--
-- __Note:__ The status value REGISTER_INACTIVE is deprecated and should
-- not be used.
updateCertificate_newStatus :: Lens.Lens' UpdateCertificate CertificateStatus
updateCertificate_newStatus :: (CertificateStatus -> f CertificateStatus)
-> UpdateCertificate -> f UpdateCertificate
updateCertificate_newStatus = (UpdateCertificate -> CertificateStatus)
-> (UpdateCertificate -> CertificateStatus -> UpdateCertificate)
-> Lens
     UpdateCertificate
     UpdateCertificate
     CertificateStatus
     CertificateStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateCertificate' {CertificateStatus
newStatus' :: CertificateStatus
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
newStatus'} -> CertificateStatus
newStatus') (\s :: UpdateCertificate
s@UpdateCertificate' {} CertificateStatus
a -> UpdateCertificate
s {$sel:newStatus':UpdateCertificate' :: CertificateStatus
newStatus' = CertificateStatus
a} :: UpdateCertificate)

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

instance Prelude.Hashable UpdateCertificate

instance Prelude.NFData UpdateCertificate

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

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

instance Core.ToPath UpdateCertificate where
  toPath :: UpdateCertificate -> ByteString
toPath UpdateCertificate' {Text
CertificateStatus
newStatus' :: CertificateStatus
certificateId :: Text
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/certificates/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
certificateId]

instance Core.ToQuery UpdateCertificate where
  toQuery :: UpdateCertificate -> QueryString
toQuery UpdateCertificate' {Text
CertificateStatus
newStatus' :: CertificateStatus
certificateId :: Text
$sel:newStatus':UpdateCertificate' :: UpdateCertificate -> CertificateStatus
$sel:certificateId:UpdateCertificate' :: UpdateCertificate -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"newStatus" ByteString -> CertificateStatus -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: CertificateStatus
newStatus']

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

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

instance Prelude.NFData UpdateCertificateResponse