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

instance Prelude.Hashable PutUserPolicy

instance Prelude.NFData PutUserPolicy

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

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

instance Core.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
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"PutUserPolicy" :: 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
"PolicyName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
policyName,
        ByteString
"PolicyDocument" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
policyDocument
      ]

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