{-# 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.DetachThingPrincipal
-- 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)
--
-- Detaches the specified principal from the specified thing. A principal
-- can be X.509 certificates, IAM users, groups, and roles, Amazon Cognito
-- identities or federated identities.
--
-- This call is asynchronous. It might take several seconds for the
-- detachment to propagate.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions DetachThingPrincipal>
-- action.
module Amazonka.IoT.DetachThingPrincipal
  ( -- * Creating a Request
    DetachThingPrincipal (..),
    newDetachThingPrincipal,

    -- * Request Lenses
    detachThingPrincipal_thingName,
    detachThingPrincipal_principal,

    -- * Destructuring the Response
    DetachThingPrincipalResponse (..),
    newDetachThingPrincipalResponse,

    -- * Response Lenses
    detachThingPrincipalResponse_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 DetachThingPrincipal operation.
--
-- /See:/ 'newDetachThingPrincipal' smart constructor.
data DetachThingPrincipal = DetachThingPrincipal'
  { -- | The name of the thing.
    DetachThingPrincipal -> Text
thingName :: Prelude.Text,
    -- | If the principal is a certificate, this value must be ARN of the
    -- certificate. If the principal is an Amazon Cognito identity, this value
    -- must be the ID of the Amazon Cognito identity.
    DetachThingPrincipal -> Text
principal :: Prelude.Text
  }
  deriving (DetachThingPrincipal -> DetachThingPrincipal -> Bool
(DetachThingPrincipal -> DetachThingPrincipal -> Bool)
-> (DetachThingPrincipal -> DetachThingPrincipal -> Bool)
-> Eq DetachThingPrincipal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachThingPrincipal -> DetachThingPrincipal -> Bool
$c/= :: DetachThingPrincipal -> DetachThingPrincipal -> Bool
== :: DetachThingPrincipal -> DetachThingPrincipal -> Bool
$c== :: DetachThingPrincipal -> DetachThingPrincipal -> Bool
Prelude.Eq, ReadPrec [DetachThingPrincipal]
ReadPrec DetachThingPrincipal
Int -> ReadS DetachThingPrincipal
ReadS [DetachThingPrincipal]
(Int -> ReadS DetachThingPrincipal)
-> ReadS [DetachThingPrincipal]
-> ReadPrec DetachThingPrincipal
-> ReadPrec [DetachThingPrincipal]
-> Read DetachThingPrincipal
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachThingPrincipal]
$creadListPrec :: ReadPrec [DetachThingPrincipal]
readPrec :: ReadPrec DetachThingPrincipal
$creadPrec :: ReadPrec DetachThingPrincipal
readList :: ReadS [DetachThingPrincipal]
$creadList :: ReadS [DetachThingPrincipal]
readsPrec :: Int -> ReadS DetachThingPrincipal
$creadsPrec :: Int -> ReadS DetachThingPrincipal
Prelude.Read, Int -> DetachThingPrincipal -> ShowS
[DetachThingPrincipal] -> ShowS
DetachThingPrincipal -> String
(Int -> DetachThingPrincipal -> ShowS)
-> (DetachThingPrincipal -> String)
-> ([DetachThingPrincipal] -> ShowS)
-> Show DetachThingPrincipal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachThingPrincipal] -> ShowS
$cshowList :: [DetachThingPrincipal] -> ShowS
show :: DetachThingPrincipal -> String
$cshow :: DetachThingPrincipal -> String
showsPrec :: Int -> DetachThingPrincipal -> ShowS
$cshowsPrec :: Int -> DetachThingPrincipal -> ShowS
Prelude.Show, (forall x. DetachThingPrincipal -> Rep DetachThingPrincipal x)
-> (forall x. Rep DetachThingPrincipal x -> DetachThingPrincipal)
-> Generic DetachThingPrincipal
forall x. Rep DetachThingPrincipal x -> DetachThingPrincipal
forall x. DetachThingPrincipal -> Rep DetachThingPrincipal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetachThingPrincipal x -> DetachThingPrincipal
$cfrom :: forall x. DetachThingPrincipal -> Rep DetachThingPrincipal x
Prelude.Generic)

-- |
-- Create a value of 'DetachThingPrincipal' 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:
--
-- 'thingName', 'detachThingPrincipal_thingName' - The name of the thing.
--
-- 'principal', 'detachThingPrincipal_principal' - If the principal is a certificate, this value must be ARN of the
-- certificate. If the principal is an Amazon Cognito identity, this value
-- must be the ID of the Amazon Cognito identity.
newDetachThingPrincipal ::
  -- | 'thingName'
  Prelude.Text ->
  -- | 'principal'
  Prelude.Text ->
  DetachThingPrincipal
newDetachThingPrincipal :: Text -> Text -> DetachThingPrincipal
newDetachThingPrincipal Text
pThingName_ Text
pPrincipal_ =
  DetachThingPrincipal' :: Text -> Text -> DetachThingPrincipal
DetachThingPrincipal'
    { $sel:thingName:DetachThingPrincipal' :: Text
thingName = Text
pThingName_,
      $sel:principal:DetachThingPrincipal' :: Text
principal = Text
pPrincipal_
    }

-- | The name of the thing.
detachThingPrincipal_thingName :: Lens.Lens' DetachThingPrincipal Prelude.Text
detachThingPrincipal_thingName :: (Text -> f Text) -> DetachThingPrincipal -> f DetachThingPrincipal
detachThingPrincipal_thingName = (DetachThingPrincipal -> Text)
-> (DetachThingPrincipal -> Text -> DetachThingPrincipal)
-> Lens DetachThingPrincipal DetachThingPrincipal Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachThingPrincipal' {Text
thingName :: Text
$sel:thingName:DetachThingPrincipal' :: DetachThingPrincipal -> Text
thingName} -> Text
thingName) (\s :: DetachThingPrincipal
s@DetachThingPrincipal' {} Text
a -> DetachThingPrincipal
s {$sel:thingName:DetachThingPrincipal' :: Text
thingName = Text
a} :: DetachThingPrincipal)

-- | If the principal is a certificate, this value must be ARN of the
-- certificate. If the principal is an Amazon Cognito identity, this value
-- must be the ID of the Amazon Cognito identity.
detachThingPrincipal_principal :: Lens.Lens' DetachThingPrincipal Prelude.Text
detachThingPrincipal_principal :: (Text -> f Text) -> DetachThingPrincipal -> f DetachThingPrincipal
detachThingPrincipal_principal = (DetachThingPrincipal -> Text)
-> (DetachThingPrincipal -> Text -> DetachThingPrincipal)
-> Lens DetachThingPrincipal DetachThingPrincipal Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachThingPrincipal' {Text
principal :: Text
$sel:principal:DetachThingPrincipal' :: DetachThingPrincipal -> Text
principal} -> Text
principal) (\s :: DetachThingPrincipal
s@DetachThingPrincipal' {} Text
a -> DetachThingPrincipal
s {$sel:principal:DetachThingPrincipal' :: Text
principal = Text
a} :: DetachThingPrincipal)

instance Core.AWSRequest DetachThingPrincipal where
  type
    AWSResponse DetachThingPrincipal =
      DetachThingPrincipalResponse
  request :: DetachThingPrincipal -> Request DetachThingPrincipal
request = Service -> DetachThingPrincipal -> Request DetachThingPrincipal
forall a. ToRequest a => Service -> a -> Request a
Request.delete Service
defaultService
  response :: Logger
-> Service
-> Proxy DetachThingPrincipal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DetachThingPrincipal)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse DetachThingPrincipal))
-> Logger
-> Service
-> Proxy DetachThingPrincipal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DetachThingPrincipal)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> DetachThingPrincipalResponse
DetachThingPrincipalResponse'
            (Int -> DetachThingPrincipalResponse)
-> Either String Int -> Either String DetachThingPrincipalResponse
forall (f :: * -> *) a b. Functor 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 DetachThingPrincipal

instance Prelude.NFData DetachThingPrincipal

instance Core.ToHeaders DetachThingPrincipal where
  toHeaders :: DetachThingPrincipal -> ResponseHeaders
toHeaders DetachThingPrincipal' {Text
principal :: Text
thingName :: Text
$sel:principal:DetachThingPrincipal' :: DetachThingPrincipal -> Text
$sel:thingName:DetachThingPrincipal' :: DetachThingPrincipal -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amzn-principal" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
principal]

instance Core.ToPath DetachThingPrincipal where
  toPath :: DetachThingPrincipal -> ByteString
toPath DetachThingPrincipal' {Text
principal :: Text
thingName :: Text
$sel:principal:DetachThingPrincipal' :: DetachThingPrincipal -> Text
$sel:thingName:DetachThingPrincipal' :: DetachThingPrincipal -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/things/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
thingName, ByteString
"/principals"]

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

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

-- |
-- Create a value of 'DetachThingPrincipalResponse' 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:
--
-- 'httpStatus', 'detachThingPrincipalResponse_httpStatus' - The response's http status code.
newDetachThingPrincipalResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DetachThingPrincipalResponse
newDetachThingPrincipalResponse :: Int -> DetachThingPrincipalResponse
newDetachThingPrincipalResponse Int
pHttpStatus_ =
  DetachThingPrincipalResponse' :: Int -> DetachThingPrincipalResponse
DetachThingPrincipalResponse'
    { $sel:httpStatus:DetachThingPrincipalResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData DetachThingPrincipalResponse