{-# 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.AttachSecurityProfile
-- 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)
--
-- Associates a Device Defender security profile with a thing group or this
-- account. Each thing group or account can have up to five security
-- profiles associated with it.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions AttachSecurityProfile>
-- action.
module Amazonka.IoT.AttachSecurityProfile
  ( -- * Creating a Request
    AttachSecurityProfile (..),
    newAttachSecurityProfile,

    -- * Request Lenses
    attachSecurityProfile_securityProfileName,
    attachSecurityProfile_securityProfileTargetArn,

    -- * Destructuring the Response
    AttachSecurityProfileResponse (..),
    newAttachSecurityProfileResponse,

    -- * Response Lenses
    attachSecurityProfileResponse_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

-- | /See:/ 'newAttachSecurityProfile' smart constructor.
data AttachSecurityProfile = AttachSecurityProfile'
  { -- | The security profile that is attached.
    AttachSecurityProfile -> Text
securityProfileName :: Prelude.Text,
    -- | The ARN of the target (thing group) to which the security profile is
    -- attached.
    AttachSecurityProfile -> Text
securityProfileTargetArn :: Prelude.Text
  }
  deriving (AttachSecurityProfile -> AttachSecurityProfile -> Bool
(AttachSecurityProfile -> AttachSecurityProfile -> Bool)
-> (AttachSecurityProfile -> AttachSecurityProfile -> Bool)
-> Eq AttachSecurityProfile
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachSecurityProfile -> AttachSecurityProfile -> Bool
$c/= :: AttachSecurityProfile -> AttachSecurityProfile -> Bool
== :: AttachSecurityProfile -> AttachSecurityProfile -> Bool
$c== :: AttachSecurityProfile -> AttachSecurityProfile -> Bool
Prelude.Eq, ReadPrec [AttachSecurityProfile]
ReadPrec AttachSecurityProfile
Int -> ReadS AttachSecurityProfile
ReadS [AttachSecurityProfile]
(Int -> ReadS AttachSecurityProfile)
-> ReadS [AttachSecurityProfile]
-> ReadPrec AttachSecurityProfile
-> ReadPrec [AttachSecurityProfile]
-> Read AttachSecurityProfile
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachSecurityProfile]
$creadListPrec :: ReadPrec [AttachSecurityProfile]
readPrec :: ReadPrec AttachSecurityProfile
$creadPrec :: ReadPrec AttachSecurityProfile
readList :: ReadS [AttachSecurityProfile]
$creadList :: ReadS [AttachSecurityProfile]
readsPrec :: Int -> ReadS AttachSecurityProfile
$creadsPrec :: Int -> ReadS AttachSecurityProfile
Prelude.Read, Int -> AttachSecurityProfile -> ShowS
[AttachSecurityProfile] -> ShowS
AttachSecurityProfile -> String
(Int -> AttachSecurityProfile -> ShowS)
-> (AttachSecurityProfile -> String)
-> ([AttachSecurityProfile] -> ShowS)
-> Show AttachSecurityProfile
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachSecurityProfile] -> ShowS
$cshowList :: [AttachSecurityProfile] -> ShowS
show :: AttachSecurityProfile -> String
$cshow :: AttachSecurityProfile -> String
showsPrec :: Int -> AttachSecurityProfile -> ShowS
$cshowsPrec :: Int -> AttachSecurityProfile -> ShowS
Prelude.Show, (forall x. AttachSecurityProfile -> Rep AttachSecurityProfile x)
-> (forall x. Rep AttachSecurityProfile x -> AttachSecurityProfile)
-> Generic AttachSecurityProfile
forall x. Rep AttachSecurityProfile x -> AttachSecurityProfile
forall x. AttachSecurityProfile -> Rep AttachSecurityProfile x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachSecurityProfile x -> AttachSecurityProfile
$cfrom :: forall x. AttachSecurityProfile -> Rep AttachSecurityProfile x
Prelude.Generic)

-- |
-- Create a value of 'AttachSecurityProfile' 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:
--
-- 'securityProfileName', 'attachSecurityProfile_securityProfileName' - The security profile that is attached.
--
-- 'securityProfileTargetArn', 'attachSecurityProfile_securityProfileTargetArn' - The ARN of the target (thing group) to which the security profile is
-- attached.
newAttachSecurityProfile ::
  -- | 'securityProfileName'
  Prelude.Text ->
  -- | 'securityProfileTargetArn'
  Prelude.Text ->
  AttachSecurityProfile
newAttachSecurityProfile :: Text -> Text -> AttachSecurityProfile
newAttachSecurityProfile
  Text
pSecurityProfileName_
  Text
pSecurityProfileTargetArn_ =
    AttachSecurityProfile' :: Text -> Text -> AttachSecurityProfile
AttachSecurityProfile'
      { $sel:securityProfileName:AttachSecurityProfile' :: Text
securityProfileName =
          Text
pSecurityProfileName_,
        $sel:securityProfileTargetArn:AttachSecurityProfile' :: Text
securityProfileTargetArn =
          Text
pSecurityProfileTargetArn_
      }

-- | The security profile that is attached.
attachSecurityProfile_securityProfileName :: Lens.Lens' AttachSecurityProfile Prelude.Text
attachSecurityProfile_securityProfileName :: (Text -> f Text)
-> AttachSecurityProfile -> f AttachSecurityProfile
attachSecurityProfile_securityProfileName = (AttachSecurityProfile -> Text)
-> (AttachSecurityProfile -> Text -> AttachSecurityProfile)
-> Lens AttachSecurityProfile AttachSecurityProfile Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachSecurityProfile' {Text
securityProfileName :: Text
$sel:securityProfileName:AttachSecurityProfile' :: AttachSecurityProfile -> Text
securityProfileName} -> Text
securityProfileName) (\s :: AttachSecurityProfile
s@AttachSecurityProfile' {} Text
a -> AttachSecurityProfile
s {$sel:securityProfileName:AttachSecurityProfile' :: Text
securityProfileName = Text
a} :: AttachSecurityProfile)

-- | The ARN of the target (thing group) to which the security profile is
-- attached.
attachSecurityProfile_securityProfileTargetArn :: Lens.Lens' AttachSecurityProfile Prelude.Text
attachSecurityProfile_securityProfileTargetArn :: (Text -> f Text)
-> AttachSecurityProfile -> f AttachSecurityProfile
attachSecurityProfile_securityProfileTargetArn = (AttachSecurityProfile -> Text)
-> (AttachSecurityProfile -> Text -> AttachSecurityProfile)
-> Lens AttachSecurityProfile AttachSecurityProfile Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachSecurityProfile' {Text
securityProfileTargetArn :: Text
$sel:securityProfileTargetArn:AttachSecurityProfile' :: AttachSecurityProfile -> Text
securityProfileTargetArn} -> Text
securityProfileTargetArn) (\s :: AttachSecurityProfile
s@AttachSecurityProfile' {} Text
a -> AttachSecurityProfile
s {$sel:securityProfileTargetArn:AttachSecurityProfile' :: Text
securityProfileTargetArn = Text
a} :: AttachSecurityProfile)

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

instance Prelude.NFData AttachSecurityProfile

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

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

instance Core.ToPath AttachSecurityProfile where
  toPath :: AttachSecurityProfile -> ByteString
toPath AttachSecurityProfile' {Text
securityProfileTargetArn :: Text
securityProfileName :: Text
$sel:securityProfileTargetArn:AttachSecurityProfile' :: AttachSecurityProfile -> Text
$sel:securityProfileName:AttachSecurityProfile' :: AttachSecurityProfile -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/security-profiles/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
securityProfileName,
        ByteString
"/targets"
      ]

instance Core.ToQuery AttachSecurityProfile where
  toQuery :: AttachSecurityProfile -> QueryString
toQuery AttachSecurityProfile' {Text
securityProfileTargetArn :: Text
securityProfileName :: Text
$sel:securityProfileTargetArn:AttachSecurityProfile' :: AttachSecurityProfile -> Text
$sel:securityProfileName:AttachSecurityProfile' :: AttachSecurityProfile -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"securityProfileTargetArn"
          ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
securityProfileTargetArn
      ]

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

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

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

instance Prelude.NFData AttachSecurityProfileResponse