{-# 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.CloudTrail.StopLogging
-- 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)
--
-- Suspends the recording of Amazon Web Services API calls and log file
-- delivery for the specified trail. Under most circumstances, there is no
-- need to use this action. You can update a trail without stopping it
-- first. This action is the only way to stop recording. For a trail
-- enabled in all regions, this operation must be called from the region in
-- which the trail was created, or an @InvalidHomeRegionException@ will
-- occur. This operation cannot be called on the shadow trails (replicated
-- trails in other regions) of a trail enabled in all regions.
module Amazonka.CloudTrail.StopLogging
  ( -- * Creating a Request
    StopLogging (..),
    newStopLogging,

    -- * Request Lenses
    stopLogging_name,

    -- * Destructuring the Response
    StopLoggingResponse (..),
    newStopLoggingResponse,

    -- * Response Lenses
    stopLoggingResponse_httpStatus,
  )
where

import Amazonka.CloudTrail.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Passes the request to CloudTrail to stop logging Amazon Web Services API
-- calls for the specified account.
--
-- /See:/ 'newStopLogging' smart constructor.
data StopLogging = StopLogging'
  { -- | Specifies the name or the CloudTrail ARN of the trail for which
    -- CloudTrail will stop logging Amazon Web Services API calls. The
    -- following is the format of a trail ARN.
    --
    -- @arn:aws:cloudtrail:us-east-2:123456789012:trail\/MyTrail@
    StopLogging -> Text
name :: Prelude.Text
  }
  deriving (StopLogging -> StopLogging -> Bool
(StopLogging -> StopLogging -> Bool)
-> (StopLogging -> StopLogging -> Bool) -> Eq StopLogging
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopLogging -> StopLogging -> Bool
$c/= :: StopLogging -> StopLogging -> Bool
== :: StopLogging -> StopLogging -> Bool
$c== :: StopLogging -> StopLogging -> Bool
Prelude.Eq, ReadPrec [StopLogging]
ReadPrec StopLogging
Int -> ReadS StopLogging
ReadS [StopLogging]
(Int -> ReadS StopLogging)
-> ReadS [StopLogging]
-> ReadPrec StopLogging
-> ReadPrec [StopLogging]
-> Read StopLogging
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopLogging]
$creadListPrec :: ReadPrec [StopLogging]
readPrec :: ReadPrec StopLogging
$creadPrec :: ReadPrec StopLogging
readList :: ReadS [StopLogging]
$creadList :: ReadS [StopLogging]
readsPrec :: Int -> ReadS StopLogging
$creadsPrec :: Int -> ReadS StopLogging
Prelude.Read, Int -> StopLogging -> ShowS
[StopLogging] -> ShowS
StopLogging -> String
(Int -> StopLogging -> ShowS)
-> (StopLogging -> String)
-> ([StopLogging] -> ShowS)
-> Show StopLogging
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopLogging] -> ShowS
$cshowList :: [StopLogging] -> ShowS
show :: StopLogging -> String
$cshow :: StopLogging -> String
showsPrec :: Int -> StopLogging -> ShowS
$cshowsPrec :: Int -> StopLogging -> ShowS
Prelude.Show, (forall x. StopLogging -> Rep StopLogging x)
-> (forall x. Rep StopLogging x -> StopLogging)
-> Generic StopLogging
forall x. Rep StopLogging x -> StopLogging
forall x. StopLogging -> Rep StopLogging x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopLogging x -> StopLogging
$cfrom :: forall x. StopLogging -> Rep StopLogging x
Prelude.Generic)

-- |
-- Create a value of 'StopLogging' 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:
--
-- 'name', 'stopLogging_name' - Specifies the name or the CloudTrail ARN of the trail for which
-- CloudTrail will stop logging Amazon Web Services API calls. The
-- following is the format of a trail ARN.
--
-- @arn:aws:cloudtrail:us-east-2:123456789012:trail\/MyTrail@
newStopLogging ::
  -- | 'name'
  Prelude.Text ->
  StopLogging
newStopLogging :: Text -> StopLogging
newStopLogging Text
pName_ = StopLogging' :: Text -> StopLogging
StopLogging' {$sel:name:StopLogging' :: Text
name = Text
pName_}

-- | Specifies the name or the CloudTrail ARN of the trail for which
-- CloudTrail will stop logging Amazon Web Services API calls. The
-- following is the format of a trail ARN.
--
-- @arn:aws:cloudtrail:us-east-2:123456789012:trail\/MyTrail@
stopLogging_name :: Lens.Lens' StopLogging Prelude.Text
stopLogging_name :: (Text -> f Text) -> StopLogging -> f StopLogging
stopLogging_name = (StopLogging -> Text)
-> (StopLogging -> Text -> StopLogging)
-> Lens StopLogging StopLogging Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StopLogging' {Text
name :: Text
$sel:name:StopLogging' :: StopLogging -> Text
name} -> Text
name) (\s :: StopLogging
s@StopLogging' {} Text
a -> StopLogging
s {$sel:name:StopLogging' :: Text
name = Text
a} :: StopLogging)

instance Core.AWSRequest StopLogging where
  type AWSResponse StopLogging = StopLoggingResponse
  request :: StopLogging -> Request StopLogging
request = Service -> StopLogging -> Request StopLogging
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StopLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopLogging)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse StopLogging))
-> Logger
-> Service
-> Proxy StopLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StopLogging)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> StopLoggingResponse
StopLoggingResponse'
            (Int -> StopLoggingResponse)
-> Either String Int -> Either String StopLoggingResponse
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))
      )

instance Prelude.Hashable StopLogging

instance Prelude.NFData StopLogging

instance Core.ToHeaders StopLogging where
  toHeaders :: StopLogging -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StopLogging -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"com.amazonaws.cloudtrail.v20131101.CloudTrail_20131101.StopLogging" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON StopLogging where
  toJSON :: StopLogging -> Value
toJSON StopLogging' {Text
name :: Text
$sel:name:StopLogging' :: StopLogging -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name)]
      )

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

instance Core.ToQuery StopLogging where
  toQuery :: StopLogging -> QueryString
toQuery = QueryString -> StopLogging -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | Returns the objects or data listed below if successful. Otherwise,
-- returns an error.
--
-- /See:/ 'newStopLoggingResponse' smart constructor.
data StopLoggingResponse = StopLoggingResponse'
  { -- | The response's http status code.
    StopLoggingResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StopLoggingResponse -> StopLoggingResponse -> Bool
(StopLoggingResponse -> StopLoggingResponse -> Bool)
-> (StopLoggingResponse -> StopLoggingResponse -> Bool)
-> Eq StopLoggingResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StopLoggingResponse -> StopLoggingResponse -> Bool
$c/= :: StopLoggingResponse -> StopLoggingResponse -> Bool
== :: StopLoggingResponse -> StopLoggingResponse -> Bool
$c== :: StopLoggingResponse -> StopLoggingResponse -> Bool
Prelude.Eq, ReadPrec [StopLoggingResponse]
ReadPrec StopLoggingResponse
Int -> ReadS StopLoggingResponse
ReadS [StopLoggingResponse]
(Int -> ReadS StopLoggingResponse)
-> ReadS [StopLoggingResponse]
-> ReadPrec StopLoggingResponse
-> ReadPrec [StopLoggingResponse]
-> Read StopLoggingResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StopLoggingResponse]
$creadListPrec :: ReadPrec [StopLoggingResponse]
readPrec :: ReadPrec StopLoggingResponse
$creadPrec :: ReadPrec StopLoggingResponse
readList :: ReadS [StopLoggingResponse]
$creadList :: ReadS [StopLoggingResponse]
readsPrec :: Int -> ReadS StopLoggingResponse
$creadsPrec :: Int -> ReadS StopLoggingResponse
Prelude.Read, Int -> StopLoggingResponse -> ShowS
[StopLoggingResponse] -> ShowS
StopLoggingResponse -> String
(Int -> StopLoggingResponse -> ShowS)
-> (StopLoggingResponse -> String)
-> ([StopLoggingResponse] -> ShowS)
-> Show StopLoggingResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StopLoggingResponse] -> ShowS
$cshowList :: [StopLoggingResponse] -> ShowS
show :: StopLoggingResponse -> String
$cshow :: StopLoggingResponse -> String
showsPrec :: Int -> StopLoggingResponse -> ShowS
$cshowsPrec :: Int -> StopLoggingResponse -> ShowS
Prelude.Show, (forall x. StopLoggingResponse -> Rep StopLoggingResponse x)
-> (forall x. Rep StopLoggingResponse x -> StopLoggingResponse)
-> Generic StopLoggingResponse
forall x. Rep StopLoggingResponse x -> StopLoggingResponse
forall x. StopLoggingResponse -> Rep StopLoggingResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StopLoggingResponse x -> StopLoggingResponse
$cfrom :: forall x. StopLoggingResponse -> Rep StopLoggingResponse x
Prelude.Generic)

-- |
-- Create a value of 'StopLoggingResponse' 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', 'stopLoggingResponse_httpStatus' - The response's http status code.
newStopLoggingResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StopLoggingResponse
newStopLoggingResponse :: Int -> StopLoggingResponse
newStopLoggingResponse Int
pHttpStatus_ =
  StopLoggingResponse' :: Int -> StopLoggingResponse
StopLoggingResponse' {$sel:httpStatus:StopLoggingResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData StopLoggingResponse