{-# 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.AccessPreview
-- 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)
module Amazonka.AccessAnalyzer.Types.AccessPreview where

import Amazonka.AccessAnalyzer.Types.AccessPreviewStatus
import Amazonka.AccessAnalyzer.Types.AccessPreviewStatusReason
import Amazonka.AccessAnalyzer.Types.Configuration
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about an access preview.
--
-- /See:/ 'newAccessPreview' smart constructor.
data AccessPreview = AccessPreview'
  { -- | Provides more details about the current status of the access preview.
    --
    -- For example, if the creation of the access preview fails, a @Failed@
    -- status is returned. This failure can be due to an internal issue with
    -- the analysis or due to an invalid resource configuration.
    AccessPreview -> Maybe AccessPreviewStatusReason
statusReason :: Prelude.Maybe AccessPreviewStatusReason,
    -- | The ARN of the analyzer used to generate the access preview.
    AccessPreview -> Text
analyzerArn :: Prelude.Text,
    -- | A map of resource ARNs for the proposed resource configuration.
    AccessPreview -> HashMap Text Configuration
configurations :: Prelude.HashMap Prelude.Text Configuration,
    -- | The time at which the access preview was created.
    AccessPreview -> POSIX
createdAt :: Core.POSIX,
    -- | The unique ID for the access preview.
    AccessPreview -> Text
id :: Prelude.Text,
    -- | The status of the access preview.
    --
    -- -   @Creating@ - The access preview creation is in progress.
    --
    -- -   @Completed@ - The access preview is complete. You can preview
    --     findings for external access to the resource.
    --
    -- -   @Failed@ - The access preview creation has failed.
    AccessPreview -> AccessPreviewStatus
status :: AccessPreviewStatus
  }
  deriving (AccessPreview -> AccessPreview -> Bool
(AccessPreview -> AccessPreview -> Bool)
-> (AccessPreview -> AccessPreview -> Bool) -> Eq AccessPreview
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessPreview -> AccessPreview -> Bool
$c/= :: AccessPreview -> AccessPreview -> Bool
== :: AccessPreview -> AccessPreview -> Bool
$c== :: AccessPreview -> AccessPreview -> Bool
Prelude.Eq, ReadPrec [AccessPreview]
ReadPrec AccessPreview
Int -> ReadS AccessPreview
ReadS [AccessPreview]
(Int -> ReadS AccessPreview)
-> ReadS [AccessPreview]
-> ReadPrec AccessPreview
-> ReadPrec [AccessPreview]
-> Read AccessPreview
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AccessPreview]
$creadListPrec :: ReadPrec [AccessPreview]
readPrec :: ReadPrec AccessPreview
$creadPrec :: ReadPrec AccessPreview
readList :: ReadS [AccessPreview]
$creadList :: ReadS [AccessPreview]
readsPrec :: Int -> ReadS AccessPreview
$creadsPrec :: Int -> ReadS AccessPreview
Prelude.Read, Int -> AccessPreview -> ShowS
[AccessPreview] -> ShowS
AccessPreview -> String
(Int -> AccessPreview -> ShowS)
-> (AccessPreview -> String)
-> ([AccessPreview] -> ShowS)
-> Show AccessPreview
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessPreview] -> ShowS
$cshowList :: [AccessPreview] -> ShowS
show :: AccessPreview -> String
$cshow :: AccessPreview -> String
showsPrec :: Int -> AccessPreview -> ShowS
$cshowsPrec :: Int -> AccessPreview -> ShowS
Prelude.Show, (forall x. AccessPreview -> Rep AccessPreview x)
-> (forall x. Rep AccessPreview x -> AccessPreview)
-> Generic AccessPreview
forall x. Rep AccessPreview x -> AccessPreview
forall x. AccessPreview -> Rep AccessPreview x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessPreview x -> AccessPreview
$cfrom :: forall x. AccessPreview -> Rep AccessPreview x
Prelude.Generic)

-- |
-- Create a value of 'AccessPreview' 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:
--
-- 'statusReason', 'accessPreview_statusReason' - Provides more details about the current status of the access preview.
--
-- For example, if the creation of the access preview fails, a @Failed@
-- status is returned. This failure can be due to an internal issue with
-- the analysis or due to an invalid resource configuration.
--
-- 'analyzerArn', 'accessPreview_analyzerArn' - The ARN of the analyzer used to generate the access preview.
--
-- 'configurations', 'accessPreview_configurations' - A map of resource ARNs for the proposed resource configuration.
--
-- 'createdAt', 'accessPreview_createdAt' - The time at which the access preview was created.
--
-- 'id', 'accessPreview_id' - The unique ID for the access preview.
--
-- 'status', 'accessPreview_status' - The status of the access preview.
--
-- -   @Creating@ - The access preview creation is in progress.
--
-- -   @Completed@ - The access preview is complete. You can preview
--     findings for external access to the resource.
--
-- -   @Failed@ - The access preview creation has failed.
newAccessPreview ::
  -- | 'analyzerArn'
  Prelude.Text ->
  -- | 'createdAt'
  Prelude.UTCTime ->
  -- | 'id'
  Prelude.Text ->
  -- | 'status'
  AccessPreviewStatus ->
  AccessPreview
newAccessPreview :: Text -> UTCTime -> Text -> AccessPreviewStatus -> AccessPreview
newAccessPreview
  Text
pAnalyzerArn_
  UTCTime
pCreatedAt_
  Text
pId_
  AccessPreviewStatus
pStatus_ =
    AccessPreview' :: Maybe AccessPreviewStatusReason
-> Text
-> HashMap Text Configuration
-> POSIX
-> Text
-> AccessPreviewStatus
-> AccessPreview
AccessPreview'
      { $sel:statusReason:AccessPreview' :: Maybe AccessPreviewStatusReason
statusReason = Maybe AccessPreviewStatusReason
forall a. Maybe a
Prelude.Nothing,
        $sel:analyzerArn:AccessPreview' :: Text
analyzerArn = Text
pAnalyzerArn_,
        $sel:configurations:AccessPreview' :: HashMap Text Configuration
configurations = HashMap Text Configuration
forall a. Monoid a => a
Prelude.mempty,
        $sel:createdAt:AccessPreview' :: POSIX
createdAt = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pCreatedAt_,
        $sel:id:AccessPreview' :: Text
id = Text
pId_,
        $sel:status:AccessPreview' :: AccessPreviewStatus
status = AccessPreviewStatus
pStatus_
      }

-- | Provides more details about the current status of the access preview.
--
-- For example, if the creation of the access preview fails, a @Failed@
-- status is returned. This failure can be due to an internal issue with
-- the analysis or due to an invalid resource configuration.
accessPreview_statusReason :: Lens.Lens' AccessPreview (Prelude.Maybe AccessPreviewStatusReason)
accessPreview_statusReason :: (Maybe AccessPreviewStatusReason
 -> f (Maybe AccessPreviewStatusReason))
-> AccessPreview -> f AccessPreview
accessPreview_statusReason = (AccessPreview -> Maybe AccessPreviewStatusReason)
-> (AccessPreview
    -> Maybe AccessPreviewStatusReason -> AccessPreview)
-> Lens
     AccessPreview
     AccessPreview
     (Maybe AccessPreviewStatusReason)
     (Maybe AccessPreviewStatusReason)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessPreview' {Maybe AccessPreviewStatusReason
statusReason :: Maybe AccessPreviewStatusReason
$sel:statusReason:AccessPreview' :: AccessPreview -> Maybe AccessPreviewStatusReason
statusReason} -> Maybe AccessPreviewStatusReason
statusReason) (\s :: AccessPreview
s@AccessPreview' {} Maybe AccessPreviewStatusReason
a -> AccessPreview
s {$sel:statusReason:AccessPreview' :: Maybe AccessPreviewStatusReason
statusReason = Maybe AccessPreviewStatusReason
a} :: AccessPreview)

-- | The ARN of the analyzer used to generate the access preview.
accessPreview_analyzerArn :: Lens.Lens' AccessPreview Prelude.Text
accessPreview_analyzerArn :: (Text -> f Text) -> AccessPreview -> f AccessPreview
accessPreview_analyzerArn = (AccessPreview -> Text)
-> (AccessPreview -> Text -> AccessPreview)
-> Lens AccessPreview AccessPreview Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessPreview' {Text
analyzerArn :: Text
$sel:analyzerArn:AccessPreview' :: AccessPreview -> Text
analyzerArn} -> Text
analyzerArn) (\s :: AccessPreview
s@AccessPreview' {} Text
a -> AccessPreview
s {$sel:analyzerArn:AccessPreview' :: Text
analyzerArn = Text
a} :: AccessPreview)

-- | A map of resource ARNs for the proposed resource configuration.
accessPreview_configurations :: Lens.Lens' AccessPreview (Prelude.HashMap Prelude.Text Configuration)
accessPreview_configurations :: (HashMap Text Configuration -> f (HashMap Text Configuration))
-> AccessPreview -> f AccessPreview
accessPreview_configurations = (AccessPreview -> HashMap Text Configuration)
-> (AccessPreview -> HashMap Text Configuration -> AccessPreview)
-> Lens
     AccessPreview
     AccessPreview
     (HashMap Text Configuration)
     (HashMap Text Configuration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessPreview' {HashMap Text Configuration
configurations :: HashMap Text Configuration
$sel:configurations:AccessPreview' :: AccessPreview -> HashMap Text Configuration
configurations} -> HashMap Text Configuration
configurations) (\s :: AccessPreview
s@AccessPreview' {} HashMap Text Configuration
a -> AccessPreview
s {$sel:configurations:AccessPreview' :: HashMap Text Configuration
configurations = HashMap Text Configuration
a} :: AccessPreview) ((HashMap Text Configuration -> f (HashMap Text Configuration))
 -> AccessPreview -> f AccessPreview)
-> ((HashMap Text Configuration -> f (HashMap Text Configuration))
    -> HashMap Text Configuration -> f (HashMap Text Configuration))
-> (HashMap Text Configuration -> f (HashMap Text Configuration))
-> AccessPreview
-> f AccessPreview
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Configuration -> f (HashMap Text Configuration))
-> HashMap Text Configuration -> f (HashMap Text Configuration)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The time at which the access preview was created.
accessPreview_createdAt :: Lens.Lens' AccessPreview Prelude.UTCTime
accessPreview_createdAt :: (UTCTime -> f UTCTime) -> AccessPreview -> f AccessPreview
accessPreview_createdAt = (AccessPreview -> POSIX)
-> (AccessPreview -> POSIX -> AccessPreview)
-> Lens AccessPreview AccessPreview POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessPreview' {POSIX
createdAt :: POSIX
$sel:createdAt:AccessPreview' :: AccessPreview -> POSIX
createdAt} -> POSIX
createdAt) (\s :: AccessPreview
s@AccessPreview' {} POSIX
a -> AccessPreview
s {$sel:createdAt:AccessPreview' :: POSIX
createdAt = POSIX
a} :: AccessPreview) ((POSIX -> f POSIX) -> AccessPreview -> f AccessPreview)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> AccessPreview
-> f AccessPreview
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The unique ID for the access preview.
accessPreview_id :: Lens.Lens' AccessPreview Prelude.Text
accessPreview_id :: (Text -> f Text) -> AccessPreview -> f AccessPreview
accessPreview_id = (AccessPreview -> Text)
-> (AccessPreview -> Text -> AccessPreview)
-> Lens AccessPreview AccessPreview Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessPreview' {Text
id :: Text
$sel:id:AccessPreview' :: AccessPreview -> Text
id} -> Text
id) (\s :: AccessPreview
s@AccessPreview' {} Text
a -> AccessPreview
s {$sel:id:AccessPreview' :: Text
id = Text
a} :: AccessPreview)

-- | The status of the access preview.
--
-- -   @Creating@ - The access preview creation is in progress.
--
-- -   @Completed@ - The access preview is complete. You can preview
--     findings for external access to the resource.
--
-- -   @Failed@ - The access preview creation has failed.
accessPreview_status :: Lens.Lens' AccessPreview AccessPreviewStatus
accessPreview_status :: (AccessPreviewStatus -> f AccessPreviewStatus)
-> AccessPreview -> f AccessPreview
accessPreview_status = (AccessPreview -> AccessPreviewStatus)
-> (AccessPreview -> AccessPreviewStatus -> AccessPreview)
-> Lens
     AccessPreview AccessPreview AccessPreviewStatus AccessPreviewStatus
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessPreview' {AccessPreviewStatus
status :: AccessPreviewStatus
$sel:status:AccessPreview' :: AccessPreview -> AccessPreviewStatus
status} -> AccessPreviewStatus
status) (\s :: AccessPreview
s@AccessPreview' {} AccessPreviewStatus
a -> AccessPreview
s {$sel:status:AccessPreview' :: AccessPreviewStatus
status = AccessPreviewStatus
a} :: AccessPreview)

instance Core.FromJSON AccessPreview where
  parseJSON :: Value -> Parser AccessPreview
parseJSON =
    String
-> (Object -> Parser AccessPreview)
-> Value
-> Parser AccessPreview
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessPreview"
      ( \Object
x ->
          Maybe AccessPreviewStatusReason
-> Text
-> HashMap Text Configuration
-> POSIX
-> Text
-> AccessPreviewStatus
-> AccessPreview
AccessPreview'
            (Maybe AccessPreviewStatusReason
 -> Text
 -> HashMap Text Configuration
 -> POSIX
 -> Text
 -> AccessPreviewStatus
 -> AccessPreview)
-> Parser (Maybe AccessPreviewStatusReason)
-> Parser
     (Text
      -> HashMap Text Configuration
      -> POSIX
      -> Text
      -> AccessPreviewStatus
      -> AccessPreview)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe AccessPreviewStatusReason)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"statusReason")
            Parser
  (Text
   -> HashMap Text Configuration
   -> POSIX
   -> Text
   -> AccessPreviewStatus
   -> AccessPreview)
-> Parser Text
-> Parser
     (HashMap Text Configuration
      -> POSIX -> Text -> AccessPreviewStatus -> AccessPreview)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"analyzerArn")
            Parser
  (HashMap Text Configuration
   -> POSIX -> Text -> AccessPreviewStatus -> AccessPreview)
-> Parser (HashMap Text Configuration)
-> Parser (POSIX -> Text -> AccessPreviewStatus -> AccessPreview)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (HashMap Text Configuration))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"configurations" Parser (Maybe (HashMap Text Configuration))
-> HashMap Text Configuration
-> Parser (HashMap Text Configuration)
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= HashMap Text Configuration
forall a. Monoid a => a
Prelude.mempty)
            Parser (POSIX -> Text -> AccessPreviewStatus -> AccessPreview)
-> Parser POSIX
-> Parser (Text -> AccessPreviewStatus -> AccessPreview)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"createdAt")
            Parser (Text -> AccessPreviewStatus -> AccessPreview)
-> Parser Text -> Parser (AccessPreviewStatus -> AccessPreview)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"id")
            Parser (AccessPreviewStatus -> AccessPreview)
-> Parser AccessPreviewStatus -> Parser AccessPreview
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AccessPreviewStatus
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"status")
      )

instance Prelude.Hashable AccessPreview

instance Prelude.NFData AccessPreview