{-# 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.IAM.AttachUserPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Attaches the specified managed policy to the specified user.
--
-- You use this operation to attach a /managed/ policy to a user. To embed
-- an inline policy in a user, use PutUserPolicy.
--
-- As a best practice, you can validate your IAM policies. To learn more,
-- see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_policy-validator.html Validating IAM policies>
-- in the /IAM User Guide/.
--
-- For more information about policies, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/policies-managed-vs-inline.html Managed policies and inline policies>
-- in the /IAM User Guide/.
module Amazonka.IAM.AttachUserPolicy
  ( -- * Creating a Request
    AttachUserPolicy (..),
    newAttachUserPolicy,

    -- * Request Lenses
    attachUserPolicy_userName,
    attachUserPolicy_policyArn,

    -- * Destructuring the Response
    AttachUserPolicyResponse (..),
    newAttachUserPolicyResponse,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IAM.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newAttachUserPolicy' smart constructor.
data AttachUserPolicy = AttachUserPolicy'
  { -- | The name (friendly name, not ARN) of the IAM user to attach the policy
    -- to.
    --
    -- This parameter allows (through its
    -- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
    -- consisting of upper and lowercase alphanumeric characters with no
    -- spaces. You can also include any of the following characters: _+=,.\@-
    AttachUserPolicy -> Text
userName :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the IAM policy you want to attach.
    --
    -- For more information about ARNs, see
    -- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html Amazon Resource Names (ARNs)>
    -- in the /Amazon Web Services General Reference/.
    AttachUserPolicy -> Text
policyArn :: Prelude.Text
  }
  deriving (AttachUserPolicy -> AttachUserPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachUserPolicy -> AttachUserPolicy -> Bool
$c/= :: AttachUserPolicy -> AttachUserPolicy -> Bool
== :: AttachUserPolicy -> AttachUserPolicy -> Bool
$c== :: AttachUserPolicy -> AttachUserPolicy -> Bool
Prelude.Eq, ReadPrec [AttachUserPolicy]
ReadPrec AttachUserPolicy
Int -> ReadS AttachUserPolicy
ReadS [AttachUserPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachUserPolicy]
$creadListPrec :: ReadPrec [AttachUserPolicy]
readPrec :: ReadPrec AttachUserPolicy
$creadPrec :: ReadPrec AttachUserPolicy
readList :: ReadS [AttachUserPolicy]
$creadList :: ReadS [AttachUserPolicy]
readsPrec :: Int -> ReadS AttachUserPolicy
$creadsPrec :: Int -> ReadS AttachUserPolicy
Prelude.Read, Int -> AttachUserPolicy -> ShowS
[AttachUserPolicy] -> ShowS
AttachUserPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachUserPolicy] -> ShowS
$cshowList :: [AttachUserPolicy] -> ShowS
show :: AttachUserPolicy -> String
$cshow :: AttachUserPolicy -> String
showsPrec :: Int -> AttachUserPolicy -> ShowS
$cshowsPrec :: Int -> AttachUserPolicy -> ShowS
Prelude.Show, forall x. Rep AttachUserPolicy x -> AttachUserPolicy
forall x. AttachUserPolicy -> Rep AttachUserPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachUserPolicy x -> AttachUserPolicy
$cfrom :: forall x. AttachUserPolicy -> Rep AttachUserPolicy x
Prelude.Generic)

-- |
-- Create a value of 'AttachUserPolicy' 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:
--
-- 'userName', 'attachUserPolicy_userName' - The name (friendly name, not ARN) of the IAM user to attach the policy
-- to.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
--
-- 'policyArn', 'attachUserPolicy_policyArn' - The Amazon Resource Name (ARN) of the IAM policy you want to attach.
--
-- For more information about ARNs, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html Amazon Resource Names (ARNs)>
-- in the /Amazon Web Services General Reference/.
newAttachUserPolicy ::
  -- | 'userName'
  Prelude.Text ->
  -- | 'policyArn'
  Prelude.Text ->
  AttachUserPolicy
newAttachUserPolicy :: Text -> Text -> AttachUserPolicy
newAttachUserPolicy Text
pUserName_ Text
pPolicyArn_ =
  AttachUserPolicy'
    { $sel:userName:AttachUserPolicy' :: Text
userName = Text
pUserName_,
      $sel:policyArn:AttachUserPolicy' :: Text
policyArn = Text
pPolicyArn_
    }

-- | The name (friendly name, not ARN) of the IAM user to attach the policy
-- to.
--
-- This parameter allows (through its
-- <http://wikipedia.org/wiki/regex regex pattern>) a string of characters
-- consisting of upper and lowercase alphanumeric characters with no
-- spaces. You can also include any of the following characters: _+=,.\@-
attachUserPolicy_userName :: Lens.Lens' AttachUserPolicy Prelude.Text
attachUserPolicy_userName :: Lens' AttachUserPolicy Text
attachUserPolicy_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachUserPolicy' {Text
userName :: Text
$sel:userName:AttachUserPolicy' :: AttachUserPolicy -> Text
userName} -> Text
userName) (\s :: AttachUserPolicy
s@AttachUserPolicy' {} Text
a -> AttachUserPolicy
s {$sel:userName:AttachUserPolicy' :: Text
userName = Text
a} :: AttachUserPolicy)

-- | The Amazon Resource Name (ARN) of the IAM policy you want to attach.
--
-- For more information about ARNs, see
-- <https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html Amazon Resource Names (ARNs)>
-- in the /Amazon Web Services General Reference/.
attachUserPolicy_policyArn :: Lens.Lens' AttachUserPolicy Prelude.Text
attachUserPolicy_policyArn :: Lens' AttachUserPolicy Text
attachUserPolicy_policyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachUserPolicy' {Text
policyArn :: Text
$sel:policyArn:AttachUserPolicy' :: AttachUserPolicy -> Text
policyArn} -> Text
policyArn) (\s :: AttachUserPolicy
s@AttachUserPolicy' {} Text
a -> AttachUserPolicy
s {$sel:policyArn:AttachUserPolicy' :: Text
policyArn = Text
a} :: AttachUserPolicy)

instance Core.AWSRequest AttachUserPolicy where
  type
    AWSResponse AttachUserPolicy =
      AttachUserPolicyResponse
  request :: (Service -> Service)
-> AttachUserPolicy -> Request AttachUserPolicy
request Service -> Service
overrides =
    forall a. ToRequest a => Service -> a -> Request a
Request.postQuery (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy AttachUserPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachUserPolicy)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AttachUserPolicyResponse
AttachUserPolicyResponse'

instance Prelude.Hashable AttachUserPolicy where
  hashWithSalt :: Int -> AttachUserPolicy -> Int
hashWithSalt Int
_salt AttachUserPolicy' {Text
policyArn :: Text
userName :: Text
$sel:policyArn:AttachUserPolicy' :: AttachUserPolicy -> Text
$sel:userName:AttachUserPolicy' :: AttachUserPolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
userName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policyArn

instance Prelude.NFData AttachUserPolicy where
  rnf :: AttachUserPolicy -> ()
rnf AttachUserPolicy' {Text
policyArn :: Text
userName :: Text
$sel:policyArn:AttachUserPolicy' :: AttachUserPolicy -> Text
$sel:userName:AttachUserPolicy' :: AttachUserPolicy -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
userName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
policyArn

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

instance Data.ToPath AttachUserPolicy where
  toPath :: AttachUserPolicy -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Data.ToQuery AttachUserPolicy where
  toQuery :: AttachUserPolicy -> QueryString
toQuery AttachUserPolicy' {Text
policyArn :: Text
userName :: Text
$sel:policyArn:AttachUserPolicy' :: AttachUserPolicy -> Text
$sel:userName:AttachUserPolicy' :: AttachUserPolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"AttachUserPolicy" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"UserName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
userName,
        ByteString
"PolicyArn" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
policyArn
      ]

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

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

instance Prelude.NFData AttachUserPolicyResponse where
  rnf :: AttachUserPolicyResponse -> ()
rnf AttachUserPolicyResponse
_ = ()