{-# 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.PutRolePolicy
-- 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 role.
--
-- When you embed an inline policy in a role, the inline policy is used as
-- part of the role\'s access (permissions) policy. The role\'s trust
-- policy is created at the same time as the role, using CreateRole. You
-- can update a role\'s trust policy using UpdateAssumeRolePolicy. For more
-- information about IAM roles, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/roles-toplevel.html Using roles to delegate permissions and federate identities>.
--
-- A role can also have a managed policy attached to it. To attach a
-- managed policy to a role, use AttachRolePolicy. 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 with a role, 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 @PutRolePolicy@. 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.PutRolePolicy
  ( -- * Creating a Request
    PutRolePolicy (..),
    newPutRolePolicy,

    -- * Request Lenses
    putRolePolicy_roleName,
    putRolePolicy_policyName,
    putRolePolicy_policyDocument,

    -- * Destructuring the Response
    PutRolePolicyResponse (..),
    newPutRolePolicyResponse,
  )
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:/ 'newPutRolePolicy' smart constructor.
data PutRolePolicy = PutRolePolicy'
  { -- | The name of the role 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: _+=,.\@-
    PutRolePolicy -> Text
roleName :: 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: _+=,.\@-
    PutRolePolicy -> 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@)
    PutRolePolicy -> Text
policyDocument :: Prelude.Text
  }
  deriving (PutRolePolicy -> PutRolePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRolePolicy -> PutRolePolicy -> Bool
$c/= :: PutRolePolicy -> PutRolePolicy -> Bool
== :: PutRolePolicy -> PutRolePolicy -> Bool
$c== :: PutRolePolicy -> PutRolePolicy -> Bool
Prelude.Eq, ReadPrec [PutRolePolicy]
ReadPrec PutRolePolicy
Int -> ReadS PutRolePolicy
ReadS [PutRolePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRolePolicy]
$creadListPrec :: ReadPrec [PutRolePolicy]
readPrec :: ReadPrec PutRolePolicy
$creadPrec :: ReadPrec PutRolePolicy
readList :: ReadS [PutRolePolicy]
$creadList :: ReadS [PutRolePolicy]
readsPrec :: Int -> ReadS PutRolePolicy
$creadsPrec :: Int -> ReadS PutRolePolicy
Prelude.Read, Int -> PutRolePolicy -> ShowS
[PutRolePolicy] -> ShowS
PutRolePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRolePolicy] -> ShowS
$cshowList :: [PutRolePolicy] -> ShowS
show :: PutRolePolicy -> String
$cshow :: PutRolePolicy -> String
showsPrec :: Int -> PutRolePolicy -> ShowS
$cshowsPrec :: Int -> PutRolePolicy -> ShowS
Prelude.Show, forall x. Rep PutRolePolicy x -> PutRolePolicy
forall x. PutRolePolicy -> Rep PutRolePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRolePolicy x -> PutRolePolicy
$cfrom :: forall x. PutRolePolicy -> Rep PutRolePolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutRolePolicy' 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:
--
-- 'roleName', 'putRolePolicy_roleName' - The name of the role 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', 'putRolePolicy_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', 'putRolePolicy_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@)
newPutRolePolicy ::
  -- | 'roleName'
  Prelude.Text ->
  -- | 'policyName'
  Prelude.Text ->
  -- | 'policyDocument'
  Prelude.Text ->
  PutRolePolicy
newPutRolePolicy :: Text -> Text -> Text -> PutRolePolicy
newPutRolePolicy
  Text
pRoleName_
  Text
pPolicyName_
  Text
pPolicyDocument_ =
    PutRolePolicy'
      { $sel:roleName:PutRolePolicy' :: Text
roleName = Text
pRoleName_,
        $sel:policyName:PutRolePolicy' :: Text
policyName = Text
pPolicyName_,
        $sel:policyDocument:PutRolePolicy' :: Text
policyDocument = Text
pPolicyDocument_
      }

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

-- | 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: _+=,.\@-
putRolePolicy_policyName :: Lens.Lens' PutRolePolicy Prelude.Text
putRolePolicy_policyName :: Lens' PutRolePolicy Text
putRolePolicy_policyName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRolePolicy' {Text
policyName :: Text
$sel:policyName:PutRolePolicy' :: PutRolePolicy -> Text
policyName} -> Text
policyName) (\s :: PutRolePolicy
s@PutRolePolicy' {} Text
a -> PutRolePolicy
s {$sel:policyName:PutRolePolicy' :: Text
policyName = Text
a} :: PutRolePolicy)

-- | 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@)
putRolePolicy_policyDocument :: Lens.Lens' PutRolePolicy Prelude.Text
putRolePolicy_policyDocument :: Lens' PutRolePolicy Text
putRolePolicy_policyDocument = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRolePolicy' {Text
policyDocument :: Text
$sel:policyDocument:PutRolePolicy' :: PutRolePolicy -> Text
policyDocument} -> Text
policyDocument) (\s :: PutRolePolicy
s@PutRolePolicy' {} Text
a -> PutRolePolicy
s {$sel:policyDocument:PutRolePolicy' :: Text
policyDocument = Text
a} :: PutRolePolicy)

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

instance Prelude.Hashable PutRolePolicy where
  hashWithSalt :: Int -> PutRolePolicy -> Int
hashWithSalt Int
_salt PutRolePolicy' {Text
policyDocument :: Text
policyName :: Text
roleName :: Text
$sel:policyDocument:PutRolePolicy' :: PutRolePolicy -> Text
$sel:policyName:PutRolePolicy' :: PutRolePolicy -> Text
$sel:roleName:PutRolePolicy' :: PutRolePolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleName
      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 PutRolePolicy where
  rnf :: PutRolePolicy -> ()
rnf PutRolePolicy' {Text
policyDocument :: Text
policyName :: Text
roleName :: Text
$sel:policyDocument:PutRolePolicy' :: PutRolePolicy -> Text
$sel:policyName:PutRolePolicy' :: PutRolePolicy -> Text
$sel:roleName:PutRolePolicy' :: PutRolePolicy -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
roleName
      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 PutRolePolicy where
  toHeaders :: PutRolePolicy -> [Header]
toHeaders = forall a b. a -> b -> a
Prelude.const forall a. Monoid a => a
Prelude.mempty

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

instance Data.ToQuery PutRolePolicy where
  toQuery :: PutRolePolicy -> QueryString
toQuery PutRolePolicy' {Text
policyDocument :: Text
policyName :: Text
roleName :: Text
$sel:policyDocument:PutRolePolicy' :: PutRolePolicy -> Text
$sel:policyName:PutRolePolicy' :: PutRolePolicy -> Text
$sel:roleName:PutRolePolicy' :: PutRolePolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"PutRolePolicy" :: Prelude.ByteString),
        ByteString
"Version"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"RoleName" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
roleName,
        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:/ 'newPutRolePolicyResponse' smart constructor.
data PutRolePolicyResponse = PutRolePolicyResponse'
  {
  }
  deriving (PutRolePolicyResponse -> PutRolePolicyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRolePolicyResponse -> PutRolePolicyResponse -> Bool
$c/= :: PutRolePolicyResponse -> PutRolePolicyResponse -> Bool
== :: PutRolePolicyResponse -> PutRolePolicyResponse -> Bool
$c== :: PutRolePolicyResponse -> PutRolePolicyResponse -> Bool
Prelude.Eq, ReadPrec [PutRolePolicyResponse]
ReadPrec PutRolePolicyResponse
Int -> ReadS PutRolePolicyResponse
ReadS [PutRolePolicyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutRolePolicyResponse]
$creadListPrec :: ReadPrec [PutRolePolicyResponse]
readPrec :: ReadPrec PutRolePolicyResponse
$creadPrec :: ReadPrec PutRolePolicyResponse
readList :: ReadS [PutRolePolicyResponse]
$creadList :: ReadS [PutRolePolicyResponse]
readsPrec :: Int -> ReadS PutRolePolicyResponse
$creadsPrec :: Int -> ReadS PutRolePolicyResponse
Prelude.Read, Int -> PutRolePolicyResponse -> ShowS
[PutRolePolicyResponse] -> ShowS
PutRolePolicyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRolePolicyResponse] -> ShowS
$cshowList :: [PutRolePolicyResponse] -> ShowS
show :: PutRolePolicyResponse -> String
$cshow :: PutRolePolicyResponse -> String
showsPrec :: Int -> PutRolePolicyResponse -> ShowS
$cshowsPrec :: Int -> PutRolePolicyResponse -> ShowS
Prelude.Show, forall x. Rep PutRolePolicyResponse x -> PutRolePolicyResponse
forall x. PutRolePolicyResponse -> Rep PutRolePolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRolePolicyResponse x -> PutRolePolicyResponse
$cfrom :: forall x. PutRolePolicyResponse -> Rep PutRolePolicyResponse x
Prelude.Generic)

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

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