{-# 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.TransferCertificate
-- 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)
--
-- Transfers the specified certificate to the specified Amazon Web Services
-- account.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions TransferCertificate>
-- action.
--
-- You can cancel the transfer until it is acknowledged by the recipient.
--
-- No notification is sent to the transfer destination\'s account. It is up
-- to the caller to notify the transfer target.
--
-- The certificate being transferred must not be in the ACTIVE state. You
-- can use the UpdateCertificate action to deactivate it.
--
-- The certificate must not have any policies attached to it. You can use
-- the DetachPolicy action to detach them.
module Amazonka.IoT.TransferCertificate
  ( -- * Creating a Request
    TransferCertificate (..),
    newTransferCertificate,

    -- * Request Lenses
    transferCertificate_transferMessage,
    transferCertificate_certificateId,
    transferCertificate_targetAwsAccount,

    -- * Destructuring the Response
    TransferCertificateResponse (..),
    newTransferCertificateResponse,

    -- * Response Lenses
    transferCertificateResponse_transferredCertificateArn,
    transferCertificateResponse_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 TransferCertificate operation.
--
-- /See:/ 'newTransferCertificate' smart constructor.
data TransferCertificate = TransferCertificate'
  { -- | The transfer message.
    TransferCertificate -> Maybe Text
transferMessage :: Prelude.Maybe Prelude.Text,
    -- | The ID of the certificate. (The last part of the certificate ARN
    -- contains the certificate ID.)
    TransferCertificate -> Text
certificateId :: Prelude.Text,
    -- | The Amazon Web Services account.
    TransferCertificate -> Text
targetAwsAccount :: Prelude.Text
  }
  deriving (TransferCertificate -> TransferCertificate -> Bool
(TransferCertificate -> TransferCertificate -> Bool)
-> (TransferCertificate -> TransferCertificate -> Bool)
-> Eq TransferCertificate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransferCertificate -> TransferCertificate -> Bool
$c/= :: TransferCertificate -> TransferCertificate -> Bool
== :: TransferCertificate -> TransferCertificate -> Bool
$c== :: TransferCertificate -> TransferCertificate -> Bool
Prelude.Eq, ReadPrec [TransferCertificate]
ReadPrec TransferCertificate
Int -> ReadS TransferCertificate
ReadS [TransferCertificate]
(Int -> ReadS TransferCertificate)
-> ReadS [TransferCertificate]
-> ReadPrec TransferCertificate
-> ReadPrec [TransferCertificate]
-> Read TransferCertificate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TransferCertificate]
$creadListPrec :: ReadPrec [TransferCertificate]
readPrec :: ReadPrec TransferCertificate
$creadPrec :: ReadPrec TransferCertificate
readList :: ReadS [TransferCertificate]
$creadList :: ReadS [TransferCertificate]
readsPrec :: Int -> ReadS TransferCertificate
$creadsPrec :: Int -> ReadS TransferCertificate
Prelude.Read, Int -> TransferCertificate -> ShowS
[TransferCertificate] -> ShowS
TransferCertificate -> String
(Int -> TransferCertificate -> ShowS)
-> (TransferCertificate -> String)
-> ([TransferCertificate] -> ShowS)
-> Show TransferCertificate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransferCertificate] -> ShowS
$cshowList :: [TransferCertificate] -> ShowS
show :: TransferCertificate -> String
$cshow :: TransferCertificate -> String
showsPrec :: Int -> TransferCertificate -> ShowS
$cshowsPrec :: Int -> TransferCertificate -> ShowS
Prelude.Show, (forall x. TransferCertificate -> Rep TransferCertificate x)
-> (forall x. Rep TransferCertificate x -> TransferCertificate)
-> Generic TransferCertificate
forall x. Rep TransferCertificate x -> TransferCertificate
forall x. TransferCertificate -> Rep TransferCertificate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TransferCertificate x -> TransferCertificate
$cfrom :: forall x. TransferCertificate -> Rep TransferCertificate x
Prelude.Generic)

-- |
-- Create a value of 'TransferCertificate' 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:
--
-- 'transferMessage', 'transferCertificate_transferMessage' - The transfer message.
--
-- 'certificateId', 'transferCertificate_certificateId' - The ID of the certificate. (The last part of the certificate ARN
-- contains the certificate ID.)
--
-- 'targetAwsAccount', 'transferCertificate_targetAwsAccount' - The Amazon Web Services account.
newTransferCertificate ::
  -- | 'certificateId'
  Prelude.Text ->
  -- | 'targetAwsAccount'
  Prelude.Text ->
  TransferCertificate
newTransferCertificate :: Text -> Text -> TransferCertificate
newTransferCertificate
  Text
pCertificateId_
  Text
pTargetAwsAccount_ =
    TransferCertificate' :: Maybe Text -> Text -> Text -> TransferCertificate
TransferCertificate'
      { $sel:transferMessage:TransferCertificate' :: Maybe Text
transferMessage =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:certificateId:TransferCertificate' :: Text
certificateId = Text
pCertificateId_,
        $sel:targetAwsAccount:TransferCertificate' :: Text
targetAwsAccount = Text
pTargetAwsAccount_
      }

-- | The transfer message.
transferCertificate_transferMessage :: Lens.Lens' TransferCertificate (Prelude.Maybe Prelude.Text)
transferCertificate_transferMessage :: (Maybe Text -> f (Maybe Text))
-> TransferCertificate -> f TransferCertificate
transferCertificate_transferMessage = (TransferCertificate -> Maybe Text)
-> (TransferCertificate -> Maybe Text -> TransferCertificate)
-> Lens
     TransferCertificate TransferCertificate (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificate' {Maybe Text
transferMessage :: Maybe Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
transferMessage} -> Maybe Text
transferMessage) (\s :: TransferCertificate
s@TransferCertificate' {} Maybe Text
a -> TransferCertificate
s {$sel:transferMessage:TransferCertificate' :: Maybe Text
transferMessage = Maybe Text
a} :: TransferCertificate)

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

-- | The Amazon Web Services account.
transferCertificate_targetAwsAccount :: Lens.Lens' TransferCertificate Prelude.Text
transferCertificate_targetAwsAccount :: (Text -> f Text) -> TransferCertificate -> f TransferCertificate
transferCertificate_targetAwsAccount = (TransferCertificate -> Text)
-> (TransferCertificate -> Text -> TransferCertificate)
-> Lens TransferCertificate TransferCertificate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificate' {Text
targetAwsAccount :: Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
targetAwsAccount} -> Text
targetAwsAccount) (\s :: TransferCertificate
s@TransferCertificate' {} Text
a -> TransferCertificate
s {$sel:targetAwsAccount:TransferCertificate' :: Text
targetAwsAccount = Text
a} :: TransferCertificate)

instance Core.AWSRequest TransferCertificate where
  type
    AWSResponse TransferCertificate =
      TransferCertificateResponse
  request :: TransferCertificate -> Request TransferCertificate
request = Service -> TransferCertificate -> Request TransferCertificate
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy TransferCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TransferCertificate)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse TransferCertificate))
-> Logger
-> Service
-> Proxy TransferCertificate
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse TransferCertificate)))
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 -> TransferCertificateResponse
TransferCertificateResponse'
            (Maybe Text -> Int -> TransferCertificateResponse)
-> Either String (Maybe Text)
-> Either String (Int -> TransferCertificateResponse)
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
"transferredCertificateArn")
            Either String (Int -> TransferCertificateResponse)
-> Either String Int -> Either String TransferCertificateResponse
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 TransferCertificate

instance Prelude.NFData TransferCertificate

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

instance Core.ToJSON TransferCertificate where
  toJSON :: TransferCertificate -> Value
toJSON TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"transferMessage" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
transferMessage
          ]
      )

instance Core.ToPath TransferCertificate where
  toPath :: TransferCertificate -> ByteString
toPath TransferCertificate' {Maybe Text
Text
targetAwsAccount :: Text
certificateId :: Text
transferMessage :: Maybe Text
$sel:targetAwsAccount:TransferCertificate' :: TransferCertificate -> Text
$sel:certificateId:TransferCertificate' :: TransferCertificate -> Text
$sel:transferMessage:TransferCertificate' :: TransferCertificate -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/transfer-certificate/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
certificateId]

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

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

-- |
-- Create a value of 'TransferCertificateResponse' 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:
--
-- 'transferredCertificateArn', 'transferCertificateResponse_transferredCertificateArn' - The ARN of the certificate.
--
-- 'httpStatus', 'transferCertificateResponse_httpStatus' - The response's http status code.
newTransferCertificateResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  TransferCertificateResponse
newTransferCertificateResponse :: Int -> TransferCertificateResponse
newTransferCertificateResponse Int
pHttpStatus_ =
  TransferCertificateResponse' :: Maybe Text -> Int -> TransferCertificateResponse
TransferCertificateResponse'
    { $sel:transferredCertificateArn:TransferCertificateResponse' :: Maybe Text
transferredCertificateArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:TransferCertificateResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the certificate.
transferCertificateResponse_transferredCertificateArn :: Lens.Lens' TransferCertificateResponse (Prelude.Maybe Prelude.Text)
transferCertificateResponse_transferredCertificateArn :: (Maybe Text -> f (Maybe Text))
-> TransferCertificateResponse -> f TransferCertificateResponse
transferCertificateResponse_transferredCertificateArn = (TransferCertificateResponse -> Maybe Text)
-> (TransferCertificateResponse
    -> Maybe Text -> TransferCertificateResponse)
-> Lens
     TransferCertificateResponse
     TransferCertificateResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransferCertificateResponse' {Maybe Text
transferredCertificateArn :: Maybe Text
$sel:transferredCertificateArn:TransferCertificateResponse' :: TransferCertificateResponse -> Maybe Text
transferredCertificateArn} -> Maybe Text
transferredCertificateArn) (\s :: TransferCertificateResponse
s@TransferCertificateResponse' {} Maybe Text
a -> TransferCertificateResponse
s {$sel:transferredCertificateArn:TransferCertificateResponse' :: Maybe Text
transferredCertificateArn = Maybe Text
a} :: TransferCertificateResponse)

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

instance Prelude.NFData TransferCertificateResponse