{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.AccessAnalyzer.Types.Trail
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.AccessAnalyzer.Types.Trail where

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

-- | Contains details about the CloudTrail trail being analyzed to generate a
-- policy.
--
-- /See:/ 'newTrail' smart constructor.
data Trail = Trail'
  { -- | Possible values are @true@ or @false@. If set to @true@, IAM Access
    -- Analyzer retrieves CloudTrail data from all regions to analyze and
    -- generate a policy.
    Trail -> Maybe Bool
allRegions :: Prelude.Maybe Prelude.Bool,
    -- | A list of regions to get CloudTrail data from and analyze to generate a
    -- policy.
    Trail -> Maybe [Text]
regions :: Prelude.Maybe [Prelude.Text],
    -- | Specifies the ARN of the trail. The format of a trail ARN is
    -- @arn:aws:cloudtrail:us-east-2:123456789012:trail\/MyTrail@.
    Trail -> Text
cloudTrailArn :: Prelude.Text
  }
  deriving (Trail -> Trail -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Trail -> Trail -> Bool
$c/= :: Trail -> Trail -> Bool
== :: Trail -> Trail -> Bool
$c== :: Trail -> Trail -> Bool
Prelude.Eq, ReadPrec [Trail]
ReadPrec Trail
Int -> ReadS Trail
ReadS [Trail]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Trail]
$creadListPrec :: ReadPrec [Trail]
readPrec :: ReadPrec Trail
$creadPrec :: ReadPrec Trail
readList :: ReadS [Trail]
$creadList :: ReadS [Trail]
readsPrec :: Int -> ReadS Trail
$creadsPrec :: Int -> ReadS Trail
Prelude.Read, Int -> Trail -> ShowS
[Trail] -> ShowS
Trail -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Trail] -> ShowS
$cshowList :: [Trail] -> ShowS
show :: Trail -> String
$cshow :: Trail -> String
showsPrec :: Int -> Trail -> ShowS
$cshowsPrec :: Int -> Trail -> ShowS
Prelude.Show, forall x. Rep Trail x -> Trail
forall x. Trail -> Rep Trail x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Trail x -> Trail
$cfrom :: forall x. Trail -> Rep Trail x
Prelude.Generic)

-- |
-- Create a value of 'Trail' 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:
--
-- 'allRegions', 'trail_allRegions' - Possible values are @true@ or @false@. If set to @true@, IAM Access
-- Analyzer retrieves CloudTrail data from all regions to analyze and
-- generate a policy.
--
-- 'regions', 'trail_regions' - A list of regions to get CloudTrail data from and analyze to generate a
-- policy.
--
-- 'cloudTrailArn', 'trail_cloudTrailArn' - Specifies the ARN of the trail. The format of a trail ARN is
-- @arn:aws:cloudtrail:us-east-2:123456789012:trail\/MyTrail@.
newTrail ::
  -- | 'cloudTrailArn'
  Prelude.Text ->
  Trail
newTrail :: Text -> Trail
newTrail Text
pCloudTrailArn_ =
  Trail'
    { $sel:allRegions:Trail' :: Maybe Bool
allRegions = forall a. Maybe a
Prelude.Nothing,
      $sel:regions:Trail' :: Maybe [Text]
regions = forall a. Maybe a
Prelude.Nothing,
      $sel:cloudTrailArn:Trail' :: Text
cloudTrailArn = Text
pCloudTrailArn_
    }

-- | Possible values are @true@ or @false@. If set to @true@, IAM Access
-- Analyzer retrieves CloudTrail data from all regions to analyze and
-- generate a policy.
trail_allRegions :: Lens.Lens' Trail (Prelude.Maybe Prelude.Bool)
trail_allRegions :: Lens' Trail (Maybe Bool)
trail_allRegions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trail' {Maybe Bool
allRegions :: Maybe Bool
$sel:allRegions:Trail' :: Trail -> Maybe Bool
allRegions} -> Maybe Bool
allRegions) (\s :: Trail
s@Trail' {} Maybe Bool
a -> Trail
s {$sel:allRegions:Trail' :: Maybe Bool
allRegions = Maybe Bool
a} :: Trail)

-- | A list of regions to get CloudTrail data from and analyze to generate a
-- policy.
trail_regions :: Lens.Lens' Trail (Prelude.Maybe [Prelude.Text])
trail_regions :: Lens' Trail (Maybe [Text])
trail_regions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trail' {Maybe [Text]
regions :: Maybe [Text]
$sel:regions:Trail' :: Trail -> Maybe [Text]
regions} -> Maybe [Text]
regions) (\s :: Trail
s@Trail' {} Maybe [Text]
a -> Trail
s {$sel:regions:Trail' :: Maybe [Text]
regions = Maybe [Text]
a} :: Trail) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the ARN of the trail. The format of a trail ARN is
-- @arn:aws:cloudtrail:us-east-2:123456789012:trail\/MyTrail@.
trail_cloudTrailArn :: Lens.Lens' Trail Prelude.Text
trail_cloudTrailArn :: Lens' Trail Text
trail_cloudTrailArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Trail' {Text
cloudTrailArn :: Text
$sel:cloudTrailArn:Trail' :: Trail -> Text
cloudTrailArn} -> Text
cloudTrailArn) (\s :: Trail
s@Trail' {} Text
a -> Trail
s {$sel:cloudTrailArn:Trail' :: Text
cloudTrailArn = Text
a} :: Trail)

instance Prelude.Hashable Trail where
  hashWithSalt :: Int -> Trail -> Int
hashWithSalt Int
_salt Trail' {Maybe Bool
Maybe [Text]
Text
cloudTrailArn :: Text
regions :: Maybe [Text]
allRegions :: Maybe Bool
$sel:cloudTrailArn:Trail' :: Trail -> Text
$sel:regions:Trail' :: Trail -> Maybe [Text]
$sel:allRegions:Trail' :: Trail -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
allRegions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
regions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
cloudTrailArn

instance Prelude.NFData Trail where
  rnf :: Trail -> ()
rnf Trail' {Maybe Bool
Maybe [Text]
Text
cloudTrailArn :: Text
regions :: Maybe [Text]
allRegions :: Maybe Bool
$sel:cloudTrailArn:Trail' :: Trail -> Text
$sel:regions:Trail' :: Trail -> Maybe [Text]
$sel:allRegions:Trail' :: Trail -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
allRegions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
regions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
cloudTrailArn

instance Data.ToJSON Trail where
  toJSON :: Trail -> Value
toJSON Trail' {Maybe Bool
Maybe [Text]
Text
cloudTrailArn :: Text
regions :: Maybe [Text]
allRegions :: Maybe Bool
$sel:cloudTrailArn:Trail' :: Trail -> Text
$sel:regions:Trail' :: Trail -> Maybe [Text]
$sel:allRegions:Trail' :: Trail -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"allRegions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
allRegions,
            (Key
"regions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
regions,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"cloudTrailArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
cloudTrailArn)
          ]
      )