{-# 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.DeleteServiceLinkedRole
-- 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)
--
-- Submits a service-linked role deletion request and returns a
-- @DeletionTaskId@, which you can use to check the status of the deletion.
-- Before you call this operation, confirm that the role has no active
-- sessions and that any resources used by the role in the linked service
-- are deleted. If you call this operation more than once for the same
-- service-linked role and an earlier deletion task is not complete, then
-- the @DeletionTaskId@ of the earlier request is returned.
--
-- If you submit a deletion request for a service-linked role whose linked
-- service is still accessing a resource, then the deletion task fails. If
-- it fails, the GetServiceLinkedRoleDeletionStatus operation returns the
-- reason for the failure, usually including the resources that must be
-- deleted. To delete the service-linked role, you must first remove those
-- resources from the linked service and then submit the deletion request
-- again. Resources are specific to the service that is linked to the role.
-- For more information about removing resources from a service, see the
-- <http://docs.aws.amazon.com/ Amazon Web Services documentation> for your
-- service.
--
-- For more information about service-linked roles, see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role Roles terms and concepts: Amazon Web Services service-linked role>
-- in the /IAM User Guide/.
module Amazonka.IAM.DeleteServiceLinkedRole
  ( -- * Creating a Request
    DeleteServiceLinkedRole (..),
    newDeleteServiceLinkedRole,

    -- * Request Lenses
    deleteServiceLinkedRole_roleName,

    -- * Destructuring the Response
    DeleteServiceLinkedRoleResponse (..),
    newDeleteServiceLinkedRoleResponse,

    -- * Response Lenses
    deleteServiceLinkedRoleResponse_httpStatus,
    deleteServiceLinkedRoleResponse_deletionTaskId,
  )
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:/ 'newDeleteServiceLinkedRole' smart constructor.
data DeleteServiceLinkedRole = DeleteServiceLinkedRole'
  { -- | The name of the service-linked role to be deleted.
    DeleteServiceLinkedRole -> Text
roleName :: Prelude.Text
  }
  deriving (DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool
(DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool)
-> (DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool)
-> Eq DeleteServiceLinkedRole
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool
$c/= :: DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool
== :: DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool
$c== :: DeleteServiceLinkedRole -> DeleteServiceLinkedRole -> Bool
Prelude.Eq, ReadPrec [DeleteServiceLinkedRole]
ReadPrec DeleteServiceLinkedRole
Int -> ReadS DeleteServiceLinkedRole
ReadS [DeleteServiceLinkedRole]
(Int -> ReadS DeleteServiceLinkedRole)
-> ReadS [DeleteServiceLinkedRole]
-> ReadPrec DeleteServiceLinkedRole
-> ReadPrec [DeleteServiceLinkedRole]
-> Read DeleteServiceLinkedRole
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteServiceLinkedRole]
$creadListPrec :: ReadPrec [DeleteServiceLinkedRole]
readPrec :: ReadPrec DeleteServiceLinkedRole
$creadPrec :: ReadPrec DeleteServiceLinkedRole
readList :: ReadS [DeleteServiceLinkedRole]
$creadList :: ReadS [DeleteServiceLinkedRole]
readsPrec :: Int -> ReadS DeleteServiceLinkedRole
$creadsPrec :: Int -> ReadS DeleteServiceLinkedRole
Prelude.Read, Int -> DeleteServiceLinkedRole -> ShowS
[DeleteServiceLinkedRole] -> ShowS
DeleteServiceLinkedRole -> String
(Int -> DeleteServiceLinkedRole -> ShowS)
-> (DeleteServiceLinkedRole -> String)
-> ([DeleteServiceLinkedRole] -> ShowS)
-> Show DeleteServiceLinkedRole
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteServiceLinkedRole] -> ShowS
$cshowList :: [DeleteServiceLinkedRole] -> ShowS
show :: DeleteServiceLinkedRole -> String
$cshow :: DeleteServiceLinkedRole -> String
showsPrec :: Int -> DeleteServiceLinkedRole -> ShowS
$cshowsPrec :: Int -> DeleteServiceLinkedRole -> ShowS
Prelude.Show, (forall x.
 DeleteServiceLinkedRole -> Rep DeleteServiceLinkedRole x)
-> (forall x.
    Rep DeleteServiceLinkedRole x -> DeleteServiceLinkedRole)
-> Generic DeleteServiceLinkedRole
forall x. Rep DeleteServiceLinkedRole x -> DeleteServiceLinkedRole
forall x. DeleteServiceLinkedRole -> Rep DeleteServiceLinkedRole x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteServiceLinkedRole x -> DeleteServiceLinkedRole
$cfrom :: forall x. DeleteServiceLinkedRole -> Rep DeleteServiceLinkedRole x
Prelude.Generic)

-- |
-- Create a value of 'DeleteServiceLinkedRole' 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', 'deleteServiceLinkedRole_roleName' - The name of the service-linked role to be deleted.
newDeleteServiceLinkedRole ::
  -- | 'roleName'
  Prelude.Text ->
  DeleteServiceLinkedRole
newDeleteServiceLinkedRole :: Text -> DeleteServiceLinkedRole
newDeleteServiceLinkedRole Text
pRoleName_ =
  DeleteServiceLinkedRole' :: Text -> DeleteServiceLinkedRole
DeleteServiceLinkedRole' {$sel:roleName:DeleteServiceLinkedRole' :: Text
roleName = Text
pRoleName_}

-- | The name of the service-linked role to be deleted.
deleteServiceLinkedRole_roleName :: Lens.Lens' DeleteServiceLinkedRole Prelude.Text
deleteServiceLinkedRole_roleName :: (Text -> f Text)
-> DeleteServiceLinkedRole -> f DeleteServiceLinkedRole
deleteServiceLinkedRole_roleName = (DeleteServiceLinkedRole -> Text)
-> (DeleteServiceLinkedRole -> Text -> DeleteServiceLinkedRole)
-> Lens DeleteServiceLinkedRole DeleteServiceLinkedRole Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteServiceLinkedRole' {Text
roleName :: Text
$sel:roleName:DeleteServiceLinkedRole' :: DeleteServiceLinkedRole -> Text
roleName} -> Text
roleName) (\s :: DeleteServiceLinkedRole
s@DeleteServiceLinkedRole' {} Text
a -> DeleteServiceLinkedRole
s {$sel:roleName:DeleteServiceLinkedRole' :: Text
roleName = Text
a} :: DeleteServiceLinkedRole)

instance Core.AWSRequest DeleteServiceLinkedRole where
  type
    AWSResponse DeleteServiceLinkedRole =
      DeleteServiceLinkedRoleResponse
  request :: DeleteServiceLinkedRole -> Request DeleteServiceLinkedRole
request = Service
-> DeleteServiceLinkedRole -> Request DeleteServiceLinkedRole
forall a. ToRequest a => Service -> a -> Request a
Request.postQuery Service
defaultService
  response :: Logger
-> Service
-> Proxy DeleteServiceLinkedRole
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteServiceLinkedRole)))
response =
    Text
-> (Int
    -> ResponseHeaders
    -> [Node]
    -> Either String (AWSResponse DeleteServiceLinkedRole))
-> Logger
-> Service
-> Proxy DeleteServiceLinkedRole
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DeleteServiceLinkedRole)))
forall (m :: * -> *) a.
MonadResource m =>
Text
-> (Int
    -> ResponseHeaders -> [Node] -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveXMLWrapper
      Text
"DeleteServiceLinkedRoleResult"
      ( \Int
s ResponseHeaders
h [Node]
x ->
          Int -> Text -> DeleteServiceLinkedRoleResponse
DeleteServiceLinkedRoleResponse'
            (Int -> Text -> DeleteServiceLinkedRoleResponse)
-> Either String Int
-> Either String (Text -> DeleteServiceLinkedRoleResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> DeleteServiceLinkedRoleResponse)
-> Either String Text
-> Either String DeleteServiceLinkedRoleResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"DeletionTaskId")
      )

instance Prelude.Hashable DeleteServiceLinkedRole

instance Prelude.NFData DeleteServiceLinkedRole

instance Core.ToHeaders DeleteServiceLinkedRole where
  toHeaders :: DeleteServiceLinkedRole -> ResponseHeaders
toHeaders = ResponseHeaders -> DeleteServiceLinkedRole -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

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

instance Core.ToQuery DeleteServiceLinkedRole where
  toQuery :: DeleteServiceLinkedRole -> QueryString
toQuery DeleteServiceLinkedRole' {Text
roleName :: Text
$sel:roleName:DeleteServiceLinkedRole' :: DeleteServiceLinkedRole -> 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
"DeleteServiceLinkedRole" :: 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
      ]

-- | /See:/ 'newDeleteServiceLinkedRoleResponse' smart constructor.
data DeleteServiceLinkedRoleResponse = DeleteServiceLinkedRoleResponse'
  { -- | The response's http status code.
    DeleteServiceLinkedRoleResponse -> Int
httpStatus :: Prelude.Int,
    -- | The deletion task identifier that you can use to check the status of the
    -- deletion. This identifier is returned in the format
    -- @task\/aws-service-role\/\<service-principal-name>\/\<role-name>\/\<task-uuid>@.
    DeleteServiceLinkedRoleResponse -> Text
deletionTaskId :: Prelude.Text
  }
  deriving (DeleteServiceLinkedRoleResponse
-> DeleteServiceLinkedRoleResponse -> Bool
(DeleteServiceLinkedRoleResponse
 -> DeleteServiceLinkedRoleResponse -> Bool)
-> (DeleteServiceLinkedRoleResponse
    -> DeleteServiceLinkedRoleResponse -> Bool)
-> Eq DeleteServiceLinkedRoleResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteServiceLinkedRoleResponse
-> DeleteServiceLinkedRoleResponse -> Bool
$c/= :: DeleteServiceLinkedRoleResponse
-> DeleteServiceLinkedRoleResponse -> Bool
== :: DeleteServiceLinkedRoleResponse
-> DeleteServiceLinkedRoleResponse -> Bool
$c== :: DeleteServiceLinkedRoleResponse
-> DeleteServiceLinkedRoleResponse -> Bool
Prelude.Eq, ReadPrec [DeleteServiceLinkedRoleResponse]
ReadPrec DeleteServiceLinkedRoleResponse
Int -> ReadS DeleteServiceLinkedRoleResponse
ReadS [DeleteServiceLinkedRoleResponse]
(Int -> ReadS DeleteServiceLinkedRoleResponse)
-> ReadS [DeleteServiceLinkedRoleResponse]
-> ReadPrec DeleteServiceLinkedRoleResponse
-> ReadPrec [DeleteServiceLinkedRoleResponse]
-> Read DeleteServiceLinkedRoleResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteServiceLinkedRoleResponse]
$creadListPrec :: ReadPrec [DeleteServiceLinkedRoleResponse]
readPrec :: ReadPrec DeleteServiceLinkedRoleResponse
$creadPrec :: ReadPrec DeleteServiceLinkedRoleResponse
readList :: ReadS [DeleteServiceLinkedRoleResponse]
$creadList :: ReadS [DeleteServiceLinkedRoleResponse]
readsPrec :: Int -> ReadS DeleteServiceLinkedRoleResponse
$creadsPrec :: Int -> ReadS DeleteServiceLinkedRoleResponse
Prelude.Read, Int -> DeleteServiceLinkedRoleResponse -> ShowS
[DeleteServiceLinkedRoleResponse] -> ShowS
DeleteServiceLinkedRoleResponse -> String
(Int -> DeleteServiceLinkedRoleResponse -> ShowS)
-> (DeleteServiceLinkedRoleResponse -> String)
-> ([DeleteServiceLinkedRoleResponse] -> ShowS)
-> Show DeleteServiceLinkedRoleResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteServiceLinkedRoleResponse] -> ShowS
$cshowList :: [DeleteServiceLinkedRoleResponse] -> ShowS
show :: DeleteServiceLinkedRoleResponse -> String
$cshow :: DeleteServiceLinkedRoleResponse -> String
showsPrec :: Int -> DeleteServiceLinkedRoleResponse -> ShowS
$cshowsPrec :: Int -> DeleteServiceLinkedRoleResponse -> ShowS
Prelude.Show, (forall x.
 DeleteServiceLinkedRoleResponse
 -> Rep DeleteServiceLinkedRoleResponse x)
-> (forall x.
    Rep DeleteServiceLinkedRoleResponse x
    -> DeleteServiceLinkedRoleResponse)
-> Generic DeleteServiceLinkedRoleResponse
forall x.
Rep DeleteServiceLinkedRoleResponse x
-> DeleteServiceLinkedRoleResponse
forall x.
DeleteServiceLinkedRoleResponse
-> Rep DeleteServiceLinkedRoleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DeleteServiceLinkedRoleResponse x
-> DeleteServiceLinkedRoleResponse
$cfrom :: forall x.
DeleteServiceLinkedRoleResponse
-> Rep DeleteServiceLinkedRoleResponse x
Prelude.Generic)

-- |
-- Create a value of 'DeleteServiceLinkedRoleResponse' 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:
--
-- 'httpStatus', 'deleteServiceLinkedRoleResponse_httpStatus' - The response's http status code.
--
-- 'deletionTaskId', 'deleteServiceLinkedRoleResponse_deletionTaskId' - The deletion task identifier that you can use to check the status of the
-- deletion. This identifier is returned in the format
-- @task\/aws-service-role\/\<service-principal-name>\/\<role-name>\/\<task-uuid>@.
newDeleteServiceLinkedRoleResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'deletionTaskId'
  Prelude.Text ->
  DeleteServiceLinkedRoleResponse
newDeleteServiceLinkedRoleResponse :: Int -> Text -> DeleteServiceLinkedRoleResponse
newDeleteServiceLinkedRoleResponse
  Int
pHttpStatus_
  Text
pDeletionTaskId_ =
    DeleteServiceLinkedRoleResponse' :: Int -> Text -> DeleteServiceLinkedRoleResponse
DeleteServiceLinkedRoleResponse'
      { $sel:httpStatus:DeleteServiceLinkedRoleResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:deletionTaskId:DeleteServiceLinkedRoleResponse' :: Text
deletionTaskId = Text
pDeletionTaskId_
      }

-- | The response's http status code.
deleteServiceLinkedRoleResponse_httpStatus :: Lens.Lens' DeleteServiceLinkedRoleResponse Prelude.Int
deleteServiceLinkedRoleResponse_httpStatus :: (Int -> f Int)
-> DeleteServiceLinkedRoleResponse
-> f DeleteServiceLinkedRoleResponse
deleteServiceLinkedRoleResponse_httpStatus = (DeleteServiceLinkedRoleResponse -> Int)
-> (DeleteServiceLinkedRoleResponse
    -> Int -> DeleteServiceLinkedRoleResponse)
-> Lens
     DeleteServiceLinkedRoleResponse
     DeleteServiceLinkedRoleResponse
     Int
     Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteServiceLinkedRoleResponse' {Int
httpStatus :: Int
$sel:httpStatus:DeleteServiceLinkedRoleResponse' :: DeleteServiceLinkedRoleResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DeleteServiceLinkedRoleResponse
s@DeleteServiceLinkedRoleResponse' {} Int
a -> DeleteServiceLinkedRoleResponse
s {$sel:httpStatus:DeleteServiceLinkedRoleResponse' :: Int
httpStatus = Int
a} :: DeleteServiceLinkedRoleResponse)

-- | The deletion task identifier that you can use to check the status of the
-- deletion. This identifier is returned in the format
-- @task\/aws-service-role\/\<service-principal-name>\/\<role-name>\/\<task-uuid>@.
deleteServiceLinkedRoleResponse_deletionTaskId :: Lens.Lens' DeleteServiceLinkedRoleResponse Prelude.Text
deleteServiceLinkedRoleResponse_deletionTaskId :: (Text -> f Text)
-> DeleteServiceLinkedRoleResponse
-> f DeleteServiceLinkedRoleResponse
deleteServiceLinkedRoleResponse_deletionTaskId = (DeleteServiceLinkedRoleResponse -> Text)
-> (DeleteServiceLinkedRoleResponse
    -> Text -> DeleteServiceLinkedRoleResponse)
-> Lens
     DeleteServiceLinkedRoleResponse
     DeleteServiceLinkedRoleResponse
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DeleteServiceLinkedRoleResponse' {Text
deletionTaskId :: Text
$sel:deletionTaskId:DeleteServiceLinkedRoleResponse' :: DeleteServiceLinkedRoleResponse -> Text
deletionTaskId} -> Text
deletionTaskId) (\s :: DeleteServiceLinkedRoleResponse
s@DeleteServiceLinkedRoleResponse' {} Text
a -> DeleteServiceLinkedRoleResponse
s {$sel:deletionTaskId:DeleteServiceLinkedRoleResponse' :: Text
deletionTaskId = Text
a} :: DeleteServiceLinkedRoleResponse)

instance
  Prelude.NFData
    DeleteServiceLinkedRoleResponse