{-# 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-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)
--
-- 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.Lens as Lens
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
(StartLogging -> StartLogging -> Bool)
-> (StartLogging -> StartLogging -> Bool) -> Eq StartLogging
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]
(Int -> ReadS StartLogging)
-> ReadS [StartLogging]
-> ReadPrec StartLogging
-> ReadPrec [StartLogging]
-> Read 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
(Int -> StartLogging -> ShowS)
-> (StartLogging -> String)
-> ([StartLogging] -> ShowS)
-> Show StartLogging
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. StartLogging -> Rep StartLogging x)
-> (forall x. Rep StartLogging x -> StartLogging)
-> Generic StartLogging
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' :: Text -> StartLogging
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 :: (Text -> f Text) -> StartLogging -> f StartLogging
startLogging_name = (StartLogging -> Text)
-> (StartLogging -> Text -> StartLogging)
-> Lens StartLogging StartLogging Text Text
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 :: StartLogging -> Request StartLogging
request = Service -> StartLogging -> Request StartLogging
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartLogging)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse StartLogging))
-> Logger
-> Service
-> Proxy StartLogging
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse StartLogging)))
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 -> StartLoggingResponse
StartLoggingResponse'
            (Int -> StartLoggingResponse)
-> Either String Int -> Either String StartLoggingResponse
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 StartLogging

instance Prelude.NFData StartLogging

instance Core.ToHeaders StartLogging where
  toHeaders :: StartLogging -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartLogging -> 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.StartLogging" ::
                          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 StartLogging where
  toJSON :: StartLogging -> Value
toJSON StartLogging' {Text
name :: Text
$sel:name:StartLogging' :: StartLogging -> 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 StartLogging where
  toPath :: StartLogging -> ByteString
toPath = ByteString -> StartLogging -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery StartLogging where
  toQuery :: StartLogging -> QueryString
toQuery = QueryString -> StartLogging -> 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:/ 'newStartLoggingResponse' smart constructor.
data StartLoggingResponse = StartLoggingResponse'
  { -- | The response's http status code.
    StartLoggingResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (StartLoggingResponse -> StartLoggingResponse -> Bool
(StartLoggingResponse -> StartLoggingResponse -> Bool)
-> (StartLoggingResponse -> StartLoggingResponse -> Bool)
-> Eq StartLoggingResponse
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]
(Int -> ReadS StartLoggingResponse)
-> ReadS [StartLoggingResponse]
-> ReadPrec StartLoggingResponse
-> ReadPrec [StartLoggingResponse]
-> Read 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
(Int -> StartLoggingResponse -> ShowS)
-> (StartLoggingResponse -> String)
-> ([StartLoggingResponse] -> ShowS)
-> Show StartLoggingResponse
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. StartLoggingResponse -> Rep StartLoggingResponse x)
-> (forall x. Rep StartLoggingResponse x -> StartLoggingResponse)
-> Generic StartLoggingResponse
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' :: Int -> StartLoggingResponse
StartLoggingResponse' {$sel:httpStatus:StartLoggingResponse' :: Int
httpStatus = Int
pHttpStatus_}

-- | The response's http status code.
startLoggingResponse_httpStatus :: Lens.Lens' StartLoggingResponse Prelude.Int
startLoggingResponse_httpStatus :: (Int -> f Int) -> StartLoggingResponse -> f StartLoggingResponse
startLoggingResponse_httpStatus = (StartLoggingResponse -> Int)
-> (StartLoggingResponse -> Int -> StartLoggingResponse)
-> Lens StartLoggingResponse StartLoggingResponse Int Int
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