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

instance Prelude.Hashable PutRolePolicy

instance Prelude.NFData PutRolePolicy

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

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

instance Core.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
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"PutRolePolicy" :: Prelude.ByteString),
        ByteString
"Version"
          ByteString -> ByteString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: (ByteString
"2010-05-08" :: Prelude.ByteString),
        ByteString
"RoleName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
roleName,
        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:/ 'newPutRolePolicyResponse' smart constructor.
data PutRolePolicyResponse = PutRolePolicyResponse'
  {
  }
  deriving (PutRolePolicyResponse -> PutRolePolicyResponse -> Bool
(PutRolePolicyResponse -> PutRolePolicyResponse -> Bool)
-> (PutRolePolicyResponse -> PutRolePolicyResponse -> Bool)
-> Eq PutRolePolicyResponse
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]
(Int -> ReadS PutRolePolicyResponse)
-> ReadS [PutRolePolicyResponse]
-> ReadPrec PutRolePolicyResponse
-> ReadPrec [PutRolePolicyResponse]
-> Read 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
(Int -> PutRolePolicyResponse -> ShowS)
-> (PutRolePolicyResponse -> String)
-> ([PutRolePolicyResponse] -> ShowS)
-> Show PutRolePolicyResponse
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. PutRolePolicyResponse -> Rep PutRolePolicyResponse x)
-> (forall x. Rep PutRolePolicyResponse x -> PutRolePolicyResponse)
-> Generic PutRolePolicyResponse
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