{-# 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.StartLogging
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts the recording of Amazon Web Services API calls and log file
-- delivery for a trail. For a trail that is enabled in all regions, this
-- operation must be called from the region in which the trail was created.
-- This operation cannot be called on the shadow trails (replicated trails
-- in other regions) of a trail that is enabled in all regions.
module Amazonka.CloudTrail.StartLogging
  ( -- * Creating a Request
    StartLogging (..),
    newStartLogging,

    -- * Request Lenses
    startLogging_name,

    -- * Destructuring the Response
    StartLoggingResponse (..),
    newStartLoggingResponse,

    -- * Response Lenses
    startLoggingResponse_httpStatus,
  )
where

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

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

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

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

instance Core.AWSRequest StartLogging where
  type AWSResponse StartLogging = StartLoggingResponse
  request :: (Service -> Service) -> StartLogging -> Request StartLogging
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy StartLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartLogging)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> StartLoggingResponse
StartLoggingResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

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

instance Prelude.NFData StartLogging where
  rnf :: StartLogging -> ()
rnf StartLogging' {Text
name :: Text
$sel:name:StartLogging' :: StartLogging -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
name

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

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

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

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

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

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

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

instance Prelude.NFData StartLoggingResponse where
  rnf :: StartLoggingResponse -> ()
rnf StartLoggingResponse' {Int
httpStatus :: Int
$sel:httpStatus:StartLoggingResponse' :: StartLoggingResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus