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

instance Prelude.Hashable DetachRolePolicy

instance Prelude.NFData DetachRolePolicy

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

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

instance Core.ToQuery DetachRolePolicy where
  toQuery :: DetachRolePolicy -> QueryString
toQuery DetachRolePolicy' {Text
policyArn :: Text
roleName :: Text
$sel:policyArn:DetachRolePolicy' :: DetachRolePolicy -> Text
$sel:roleName:DetachRolePolicy' :: DetachRolePolicy -> 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
"DetachRolePolicy" :: 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
"PolicyArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
policyArn
      ]

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