{-# 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.PutUserPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Adds or updates an inline policy document that is embedded in the
-- specified IAM user.
--
-- An IAM user can also have a managed policy attached to it. To attach a
-- managed policy to a user, use AttachUserPolicy. To create a new managed
-- policy, use CreatePolicy. For 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/.
--
-- For information about the maximum number of inline policies that you can
-- embed in a user, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-quotas.html IAM and STS quotas>
-- in the /IAM User Guide/.
--
-- Because policy documents can be large, you should use POST rather than
-- GET when calling @PutUserPolicy@. For general information about using
-- the Query API with IAM, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/IAM_UsingQueryAPI.html Making query requests>
-- in the /IAM User Guide/.
module Amazonka.IAM.PutUserPolicy
  ( -- * Creating a Request
    PutUserPolicy (..),
    newPutUserPolicy,

    -- * Request Lenses
    putUserPolicy_userName,
    putUserPolicy_policyName,
    putUserPolicy_policyDocument,

    -- * Destructuring the Response
    PutUserPolicyResponse (..),
    newPutUserPolicyResponse,
  )
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:/ 'newPutUserPolicy' smart constructor.
data PutUserPolicy = PutUserPolicy'
  { -- | The name of the user to associate the policy with.
    --
    -- 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: _+=,.\@-
    PutUserPolicy -> Text
userName :: Prelude.Text,
    -- | The name of the policy document.
    --
    -- 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: _+=,.\@-
    PutUserPolicy -> Text
policyName :: Prelude.Text,
    -- | The policy document.
    --
    -- You must provide policies in JSON format in IAM. However, for
    -- CloudFormation templates formatted in YAML, you can provide the policy
    -- in JSON or YAML format. CloudFormation always converts a YAML policy to
    -- JSON format before submitting it to IAM.
    --
    -- The <http://wikipedia.org/wiki/regex regex pattern> used to validate
    -- this parameter is a string of characters consisting of the following:
    --
    -- -   Any printable ASCII character ranging from the space character
    --     (@\\u0020@) through the end of the ASCII character range
    --
    -- -   The printable characters in the Basic Latin and Latin-1 Supplement
    --     character set (through @\\u00FF@)
    --
    -- -   The special characters tab (@\\u0009@), line feed (@\\u000A@), and
    --     carriage return (@\\u000D@)
    PutUserPolicy -> Text
policyDocument :: Prelude.Text
  }
  deriving (PutUserPolicy -> PutUserPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutUserPolicy -> PutUserPolicy -> Bool
$c/= :: PutUserPolicy -> PutUserPolicy -> Bool
== :: PutUserPolicy -> PutUserPolicy -> Bool
$c== :: PutUserPolicy -> PutUserPolicy -> Bool
Prelude.Eq, ReadPrec [PutUserPolicy]
ReadPrec PutUserPolicy
Int -> ReadS PutUserPolicy
ReadS [PutUserPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutUserPolicy]
$creadListPrec :: ReadPrec [PutUserPolicy]
readPrec :: ReadPrec PutUserPolicy
$creadPrec :: ReadPrec PutUserPolicy
readList :: ReadS [PutUserPolicy]
$creadList :: ReadS [PutUserPolicy]
readsPrec :: Int -> ReadS PutUserPolicy
$creadsPrec :: Int -> ReadS PutUserPolicy
Prelude.Read, Int -> PutUserPolicy -> ShowS
[PutUserPolicy] -> ShowS
PutUserPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutUserPolicy] -> ShowS
$cshowList :: [PutUserPolicy] -> ShowS
show :: PutUserPolicy -> String
$cshow :: PutUserPolicy -> String
showsPrec :: Int -> PutUserPolicy -> ShowS
$cshowsPrec :: Int -> PutUserPolicy -> ShowS
Prelude.Show, forall x. Rep PutUserPolicy x -> PutUserPolicy
forall x. PutUserPolicy -> Rep PutUserPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutUserPolicy x -> PutUserPolicy
$cfrom :: forall x. PutUserPolicy -> Rep PutUserPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutUserPolicy' 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', 'putUserPolicy_userName' - The name of the user to associate the policy with.
--
-- 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: _+=,.\@-
--
-- 'policyName', 'putUserPolicy_policyName' - The name of the policy document.
--
-- 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: _+=,.\@-
--
-- 'policyDocument', 'putUserPolicy_policyDocument' - The policy document.
--
-- You must provide policies in JSON format in IAM. However, for
-- CloudFormation templates formatted in YAML, you can provide the policy
-- in JSON or YAML format. CloudFormation always converts a YAML policy to
-- JSON format before submitting it to IAM.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> used to validate
-- this parameter is a string of characters consisting of the following:
--
-- -   Any printable ASCII character ranging from the space character
--     (@\\u0020@) through the end of the ASCII character range
--
-- -   The printable characters in the Basic Latin and Latin-1 Supplement
--     character set (through @\\u00FF@)
--
-- -   The special characters tab (@\\u0009@), line feed (@\\u000A@), and
--     carriage return (@\\u000D@)
newPutUserPolicy ::
  -- | 'userName'
  Prelude.Text ->
  -- | 'policyName'
  Prelude.Text ->
  -- | 'policyDocument'
  Prelude.Text ->
  PutUserPolicy
newPutUserPolicy :: Text -> Text -> Text -> PutUserPolicy
newPutUserPolicy
  Text
pUserName_
  Text
pPolicyName_
  Text
pPolicyDocument_ =
    PutUserPolicy'
      { $sel:userName:PutUserPolicy' :: Text
userName = Text
pUserName_,
        $sel:policyName:PutUserPolicy' :: Text
policyName = Text
pPolicyName_,
        $sel:policyDocument:PutUserPolicy' :: Text
policyDocument = Text
pPolicyDocument_
      }

-- | The name of the user to associate the policy with.
--
-- 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: _+=,.\@-
putUserPolicy_userName :: Lens.Lens' PutUserPolicy Prelude.Text
putUserPolicy_userName :: Lens' PutUserPolicy Text
putUserPolicy_userName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutUserPolicy' {Text
userName :: Text
$sel:userName:PutUserPolicy' :: PutUserPolicy -> Text
userName} -> Text
userName) (\s :: PutUserPolicy
s@PutUserPolicy' {} Text
a -> PutUserPolicy
s {$sel:userName:PutUserPolicy' :: Text
userName = Text
a} :: PutUserPolicy)

-- | The name of the policy document.
--
-- 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: _+=,.\@-
putUserPolicy_policyName :: Lens.Lens' PutUserPolicy Prelude.Text
putUserPolicy_policyName :: Lens' PutUserPolicy Text
putUserPolicy_policyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutUserPolicy' {Text
policyName :: Text
$sel:policyName:PutUserPolicy' :: PutUserPolicy -> Text
policyName} -> Text
policyName) (\s :: PutUserPolicy
s@PutUserPolicy' {} Text
a -> PutUserPolicy
s {$sel:policyName:PutUserPolicy' :: Text
policyName = Text
a} :: PutUserPolicy)

-- | The policy document.
--
-- You must provide policies in JSON format in IAM. However, for
-- CloudFormation templates formatted in YAML, you can provide the policy
-- in JSON or YAML format. CloudFormation always converts a YAML policy to
-- JSON format before submitting it to IAM.
--
-- The <http://wikipedia.org/wiki/regex regex pattern> used to validate
-- this parameter is a string of characters consisting of the following:
--
-- -   Any printable ASCII character ranging from the space character
--     (@\\u0020@) through the end of the ASCII character range
--
-- -   The printable characters in the Basic Latin and Latin-1 Supplement
--     character set (through @\\u00FF@)
--
-- -   The special characters tab (@\\u0009@), line feed (@\\u000A@), and
--     carriage return (@\\u000D@)
putUserPolicy_policyDocument :: Lens.Lens' PutUserPolicy Prelude.Text
putUserPolicy_policyDocument :: Lens' PutUserPolicy Text
putUserPolicy_policyDocument = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutUserPolicy' {Text
policyDocument :: Text
$sel:policyDocument:PutUserPolicy' :: PutUserPolicy -> Text
policyDocument} -> Text
policyDocument) (\s :: PutUserPolicy
s@PutUserPolicy' {} Text
a -> PutUserPolicy
s {$sel:policyDocument:PutUserPolicy' :: Text
policyDocument = Text
a} :: PutUserPolicy)

instance Core.AWSRequest PutUserPolicy where
  type
    AWSResponse PutUserPolicy =
      PutUserPolicyResponse
  request :: (Service -> Service) -> PutUserPolicy -> Request PutUserPolicy
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 PutUserPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutUserPolicy)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull PutUserPolicyResponse
PutUserPolicyResponse'

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

instance Prelude.NFData PutUserPolicy where
  rnf :: PutUserPolicy -> ()
rnf PutUserPolicy' {Text
policyDocument :: Text
policyName :: Text
userName :: Text
$sel:policyDocument:PutUserPolicy' :: PutUserPolicy -> Text
$sel:policyName:PutUserPolicy' :: PutUserPolicy -> Text
$sel:userName:PutUserPolicy' :: PutUserPolicy -> 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
policyName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
policyDocument

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

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

instance Data.ToQuery PutUserPolicy where
  toQuery :: PutUserPolicy -> QueryString
toQuery PutUserPolicy' {Text
policyDocument :: Text
policyName :: Text
userName :: Text
$sel:policyDocument:PutUserPolicy' :: PutUserPolicy -> Text
$sel:policyName:PutUserPolicy' :: PutUserPolicy -> Text
$sel:userName:PutUserPolicy' :: PutUserPolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"PutUserPolicy" :: 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
"PolicyName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
policyName,
        ByteString
"PolicyDocument" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
policyDocument
      ]

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

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

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