{-# 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-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 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 Amazonka.IAM.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:/ '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
(AttachUserPolicy -> AttachUserPolicy -> Bool)
-> (AttachUserPolicy -> AttachUserPolicy -> Bool)
-> Eq AttachUserPolicy
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]
(Int -> ReadS AttachUserPolicy)
-> ReadS [AttachUserPolicy]
-> ReadPrec AttachUserPolicy
-> ReadPrec [AttachUserPolicy]
-> Read 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
(Int -> AttachUserPolicy -> ShowS)
-> (AttachUserPolicy -> String)
-> ([AttachUserPolicy] -> ShowS)
-> Show AttachUserPolicy
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. AttachUserPolicy -> Rep AttachUserPolicy x)
-> (forall x. Rep AttachUserPolicy x -> AttachUserPolicy)
-> Generic AttachUserPolicy
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' :: Text -> Text -> AttachUserPolicy
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 :: (Text -> f Text) -> AttachUserPolicy -> f AttachUserPolicy
attachUserPolicy_userName = (AttachUserPolicy -> Text)
-> (AttachUserPolicy -> Text -> AttachUserPolicy)
-> Lens AttachUserPolicy AttachUserPolicy Text Text
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 :: (Text -> f Text) -> AttachUserPolicy -> f AttachUserPolicy
attachUserPolicy_policyArn = (AttachUserPolicy -> Text)
-> (AttachUserPolicy -> Text -> AttachUserPolicy)
-> Lens AttachUserPolicy AttachUserPolicy Text Text
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 :: AttachUserPolicy -> Request AttachUserPolicy
request = Service -> AttachUserPolicy -> Request AttachUserPolicy
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy AttachUserPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachUserPolicy)))
response =
    AWSResponse AttachUserPolicy
-> Logger
-> Service
-> Proxy AttachUserPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse AttachUserPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse AttachUserPolicy
AttachUserPolicyResponse
AttachUserPolicyResponse'

instance Prelude.Hashable AttachUserPolicy

instance Prelude.NFData AttachUserPolicy

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

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

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

-- | /See:/ 'newAttachUserPolicyResponse' smart constructor.
data AttachUserPolicyResponse = AttachUserPolicyResponse'
  {
  }
  deriving (AttachUserPolicyResponse -> AttachUserPolicyResponse -> Bool
(AttachUserPolicyResponse -> AttachUserPolicyResponse -> Bool)
-> (AttachUserPolicyResponse -> AttachUserPolicyResponse -> Bool)
-> Eq AttachUserPolicyResponse
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]
(Int -> ReadS AttachUserPolicyResponse)
-> ReadS [AttachUserPolicyResponse]
-> ReadPrec AttachUserPolicyResponse
-> ReadPrec [AttachUserPolicyResponse]
-> Read 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
(Int -> AttachUserPolicyResponse -> ShowS)
-> (AttachUserPolicyResponse -> String)
-> ([AttachUserPolicyResponse] -> ShowS)
-> Show AttachUserPolicyResponse
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.
 AttachUserPolicyResponse -> Rep AttachUserPolicyResponse x)
-> (forall x.
    Rep AttachUserPolicyResponse x -> AttachUserPolicyResponse)
-> Generic AttachUserPolicyResponse
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