{-# 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.DetachRolePolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Removes the specified managed policy from the specified role.
--
-- A role can also have inline policies embedded with it. To delete an
-- inline policy, use DeleteRolePolicy. 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/.
module Amazonka.IAM.DetachRolePolicy
  ( -- * Creating a Request
    DetachRolePolicy (..),
    newDetachRolePolicy,

    -- * Request Lenses
    detachRolePolicy_roleName,
    detachRolePolicy_policyArn,

    -- * Destructuring the Response
    DetachRolePolicyResponse (..),
    newDetachRolePolicyResponse,
  )
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:/ 'newDetachRolePolicy' smart constructor.
data DetachRolePolicy = DetachRolePolicy'
  { -- | The name (friendly name, not ARN) of the IAM role to detach the policy
    -- from.
    --
    -- 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: _+=,.\@-
    DetachRolePolicy -> Text
roleName :: Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the IAM policy you want to detach.
    --
    -- 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/.
    DetachRolePolicy -> Text
policyArn :: Prelude.Text
  }
  deriving (DetachRolePolicy -> DetachRolePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetachRolePolicy -> DetachRolePolicy -> Bool
$c/= :: DetachRolePolicy -> DetachRolePolicy -> Bool
== :: DetachRolePolicy -> DetachRolePolicy -> Bool
$c== :: DetachRolePolicy -> DetachRolePolicy -> Bool
Prelude.Eq, ReadPrec [DetachRolePolicy]
ReadPrec DetachRolePolicy
Int -> ReadS DetachRolePolicy
ReadS [DetachRolePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetachRolePolicy]
$creadListPrec :: ReadPrec [DetachRolePolicy]
readPrec :: ReadPrec DetachRolePolicy
$creadPrec :: ReadPrec DetachRolePolicy
readList :: ReadS [DetachRolePolicy]
$creadList :: ReadS [DetachRolePolicy]
readsPrec :: Int -> ReadS DetachRolePolicy
$creadsPrec :: Int -> ReadS DetachRolePolicy
Prelude.Read, Int -> DetachRolePolicy -> ShowS
[DetachRolePolicy] -> ShowS
DetachRolePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetachRolePolicy] -> ShowS
$cshowList :: [DetachRolePolicy] -> ShowS
show :: DetachRolePolicy -> String
$cshow :: DetachRolePolicy -> String
showsPrec :: Int -> DetachRolePolicy -> ShowS
$cshowsPrec :: Int -> DetachRolePolicy -> ShowS
Prelude.Show, forall x. Rep DetachRolePolicy x -> DetachRolePolicy
forall x. DetachRolePolicy -> Rep DetachRolePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetachRolePolicy x -> DetachRolePolicy
$cfrom :: forall x. DetachRolePolicy -> Rep DetachRolePolicy x
Prelude.Generic)

-- |
-- Create a value of 'DetachRolePolicy' 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', 'detachRolePolicy_roleName' - The name (friendly name, not ARN) of the IAM role to detach the policy
-- from.
--
-- 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', 'detachRolePolicy_policyArn' - The Amazon Resource Name (ARN) of the IAM policy you want to detach.
--
-- 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/.
newDetachRolePolicy ::
  -- | 'roleName'
  Prelude.Text ->
  -- | 'policyArn'
  Prelude.Text ->
  DetachRolePolicy
newDetachRolePolicy :: Text -> Text -> DetachRolePolicy
newDetachRolePolicy Text
pRoleName_ Text
pPolicyArn_ =
  DetachRolePolicy'
    { $sel:roleName:DetachRolePolicy' :: Text
roleName = Text
pRoleName_,
      $sel:policyArn:DetachRolePolicy' :: Text
policyArn = Text
pPolicyArn_
    }

-- | The name (friendly name, not ARN) of the IAM role to detach the policy
-- from.
--
-- 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: _+=,.\@-
detachRolePolicy_roleName :: Lens.Lens' DetachRolePolicy Prelude.Text
detachRolePolicy_roleName :: Lens' DetachRolePolicy Text
detachRolePolicy_roleName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachRolePolicy' {Text
roleName :: Text
$sel:roleName:DetachRolePolicy' :: DetachRolePolicy -> Text
roleName} -> Text
roleName) (\s :: DetachRolePolicy
s@DetachRolePolicy' {} Text
a -> DetachRolePolicy
s {$sel:roleName:DetachRolePolicy' :: Text
roleName = Text
a} :: DetachRolePolicy)

-- | The Amazon Resource Name (ARN) of the IAM policy you want to detach.
--
-- 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/.
detachRolePolicy_policyArn :: Lens.Lens' DetachRolePolicy Prelude.Text
detachRolePolicy_policyArn :: Lens' DetachRolePolicy Text
detachRolePolicy_policyArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetachRolePolicy' {Text
policyArn :: Text
$sel:policyArn:DetachRolePolicy' :: DetachRolePolicy -> Text
policyArn} -> Text
policyArn) (\s :: DetachRolePolicy
s@DetachRolePolicy' {} Text
a -> DetachRolePolicy
s {$sel:policyArn:DetachRolePolicy' :: Text
policyArn = Text
a} :: DetachRolePolicy)

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

instance Prelude.Hashable DetachRolePolicy where
  hashWithSalt :: Int -> DetachRolePolicy -> Int
hashWithSalt Int
_salt DetachRolePolicy' {Text
policyArn :: Text
roleName :: Text
$sel:policyArn:DetachRolePolicy' :: DetachRolePolicy -> Text
$sel:roleName:DetachRolePolicy' :: DetachRolePolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
roleName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policyArn

instance Prelude.NFData DetachRolePolicy where
  rnf :: DetachRolePolicy -> ()
rnf DetachRolePolicy' {Text
policyArn :: Text
roleName :: Text
$sel:policyArn:DetachRolePolicy' :: DetachRolePolicy -> Text
$sel:roleName:DetachRolePolicy' :: DetachRolePolicy -> 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
policyArn

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

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

instance Data.ToQuery DetachRolePolicy where
  toQuery :: DetachRolePolicy -> QueryString
toQuery DetachRolePolicy' {Text
policyArn :: Text
roleName :: Text
$sel:policyArn:DetachRolePolicy' :: DetachRolePolicy -> Text
$sel:roleName:DetachRolePolicy' :: DetachRolePolicy -> Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Action"
          forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: (ByteString
"DetachRolePolicy" :: 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
"PolicyArn" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
policyArn
      ]

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

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

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