{-# 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.AttachThingPrincipal
-- 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)
--
-- Attaches the specified principal to the specified thing. A principal can
-- be X.509 certificates, IAM users, groups, and roles, Amazon Cognito
-- identities or federated identities.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions AttachThingPrincipal>
-- action.
module Amazonka.IoT.AttachThingPrincipal
  ( -- * Creating a Request
    AttachThingPrincipal (..),
    newAttachThingPrincipal,

    -- * Request Lenses
    attachThingPrincipal_thingName,
    attachThingPrincipal_principal,

    -- * Destructuring the Response
    AttachThingPrincipalResponse (..),
    newAttachThingPrincipalResponse,

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

-- |
-- Create a value of 'AttachThingPrincipal' 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', 'attachThingPrincipal_thingName' - The name of the thing.
--
-- 'principal', 'attachThingPrincipal_principal' - The principal, which can be a certificate ARN (as returned from the
-- CreateCertificate operation) or an Amazon Cognito ID.
newAttachThingPrincipal ::
  -- | 'thingName'
  Prelude.Text ->
  -- | 'principal'
  Prelude.Text ->
  AttachThingPrincipal
newAttachThingPrincipal :: Text -> Text -> AttachThingPrincipal
newAttachThingPrincipal Text
pThingName_ Text
pPrincipal_ =
  AttachThingPrincipal' :: Text -> Text -> AttachThingPrincipal
AttachThingPrincipal'
    { $sel:thingName:AttachThingPrincipal' :: Text
thingName = Text
pThingName_,
      $sel:principal:AttachThingPrincipal' :: Text
principal = Text
pPrincipal_
    }

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

-- | The principal, which can be a certificate ARN (as returned from the
-- CreateCertificate operation) or an Amazon Cognito ID.
attachThingPrincipal_principal :: Lens.Lens' AttachThingPrincipal Prelude.Text
attachThingPrincipal_principal :: (Text -> f Text) -> AttachThingPrincipal -> f AttachThingPrincipal
attachThingPrincipal_principal = (AttachThingPrincipal -> Text)
-> (AttachThingPrincipal -> Text -> AttachThingPrincipal)
-> Lens AttachThingPrincipal AttachThingPrincipal Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachThingPrincipal' {Text
principal :: Text
$sel:principal:AttachThingPrincipal' :: AttachThingPrincipal -> Text
principal} -> Text
principal) (\s :: AttachThingPrincipal
s@AttachThingPrincipal' {} Text
a -> AttachThingPrincipal
s {$sel:principal:AttachThingPrincipal' :: Text
principal = Text
a} :: AttachThingPrincipal)

instance Core.AWSRequest AttachThingPrincipal where
  type
    AWSResponse AttachThingPrincipal =
      AttachThingPrincipalResponse
  request :: AttachThingPrincipal -> Request AttachThingPrincipal
request = Service -> AttachThingPrincipal -> Request AttachThingPrincipal
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy AttachThingPrincipal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachThingPrincipal)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse AttachThingPrincipal))
-> Logger
-> Service
-> Proxy AttachThingPrincipal
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse AttachThingPrincipal)))
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 -> AttachThingPrincipalResponse
AttachThingPrincipalResponse'
            (Int -> AttachThingPrincipalResponse)
-> Either String Int -> Either String AttachThingPrincipalResponse
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 AttachThingPrincipal

instance Prelude.NFData AttachThingPrincipal

instance Core.ToHeaders AttachThingPrincipal where
  toHeaders :: AttachThingPrincipal -> ResponseHeaders
toHeaders AttachThingPrincipal' {Text
principal :: Text
thingName :: Text
$sel:principal:AttachThingPrincipal' :: AttachThingPrincipal -> Text
$sel:thingName:AttachThingPrincipal' :: AttachThingPrincipal -> 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.ToJSON AttachThingPrincipal where
  toJSON :: AttachThingPrincipal -> Value
toJSON = Value -> AttachThingPrincipal -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

instance Core.ToPath AttachThingPrincipal where
  toPath :: AttachThingPrincipal -> ByteString
toPath AttachThingPrincipal' {Text
principal :: Text
thingName :: Text
$sel:principal:AttachThingPrincipal' :: AttachThingPrincipal -> Text
$sel:thingName:AttachThingPrincipal' :: AttachThingPrincipal -> 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 AttachThingPrincipal where
  toQuery :: AttachThingPrincipal -> QueryString
toQuery = QueryString -> AttachThingPrincipal -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

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

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

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

instance Prelude.NFData AttachThingPrincipalResponse