{-# 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.Config.Types.Source
-- 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.Config.Types.Source where

import Amazonka.Config.Types.Owner
import Amazonka.Config.Types.SourceDetail
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Provides the Config rule owner (Amazon Web Services or customer), the
-- rule identifier, and the events that trigger the evaluation of your
-- Amazon Web Services resources.
--
-- /See:/ 'newSource' smart constructor.
data Source = Source'
  { -- | Provides the source and type of the event that causes Config to evaluate
    -- your Amazon Web Services resources.
    Source -> Maybe [SourceDetail]
sourceDetails :: Prelude.Maybe [SourceDetail],
    -- | Indicates whether Amazon Web Services or the customer owns and manages
    -- the Config rule.
    Source -> Owner
owner :: Owner,
    -- | For Config managed rules, a predefined identifier from a list. For
    -- example, @IAM_PASSWORD_POLICY@ is a managed rule. To reference a managed
    -- rule, see
    -- <https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_use-managed-rules.html Using Config managed rules>.
    --
    -- For custom rules, the identifier is the Amazon Resource Name (ARN) of
    -- the rule\'s Lambda function, such as
    -- @arn:aws:lambda:us-east-2:123456789012:function:custom_rule_name@.
    Source -> Text
sourceIdentifier :: Prelude.Text
  }
  deriving (Source -> Source -> Bool
(Source -> Source -> Bool)
-> (Source -> Source -> Bool) -> Eq Source
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Source -> Source -> Bool
$c/= :: Source -> Source -> Bool
== :: Source -> Source -> Bool
$c== :: Source -> Source -> Bool
Prelude.Eq, ReadPrec [Source]
ReadPrec Source
Int -> ReadS Source
ReadS [Source]
(Int -> ReadS Source)
-> ReadS [Source]
-> ReadPrec Source
-> ReadPrec [Source]
-> Read Source
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Source]
$creadListPrec :: ReadPrec [Source]
readPrec :: ReadPrec Source
$creadPrec :: ReadPrec Source
readList :: ReadS [Source]
$creadList :: ReadS [Source]
readsPrec :: Int -> ReadS Source
$creadsPrec :: Int -> ReadS Source
Prelude.Read, Int -> Source -> ShowS
[Source] -> ShowS
Source -> String
(Int -> Source -> ShowS)
-> (Source -> String) -> ([Source] -> ShowS) -> Show Source
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Source] -> ShowS
$cshowList :: [Source] -> ShowS
show :: Source -> String
$cshow :: Source -> String
showsPrec :: Int -> Source -> ShowS
$cshowsPrec :: Int -> Source -> ShowS
Prelude.Show, (forall x. Source -> Rep Source x)
-> (forall x. Rep Source x -> Source) -> Generic Source
forall x. Rep Source x -> Source
forall x. Source -> Rep Source x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Source x -> Source
$cfrom :: forall x. Source -> Rep Source x
Prelude.Generic)

-- |
-- Create a value of 'Source' 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:
--
-- 'sourceDetails', 'source_sourceDetails' - Provides the source and type of the event that causes Config to evaluate
-- your Amazon Web Services resources.
--
-- 'owner', 'source_owner' - Indicates whether Amazon Web Services or the customer owns and manages
-- the Config rule.
--
-- 'sourceIdentifier', 'source_sourceIdentifier' - For Config managed rules, a predefined identifier from a list. For
-- example, @IAM_PASSWORD_POLICY@ is a managed rule. To reference a managed
-- rule, see
-- <https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_use-managed-rules.html Using Config managed rules>.
--
-- For custom rules, the identifier is the Amazon Resource Name (ARN) of
-- the rule\'s Lambda function, such as
-- @arn:aws:lambda:us-east-2:123456789012:function:custom_rule_name@.
newSource ::
  -- | 'owner'
  Owner ->
  -- | 'sourceIdentifier'
  Prelude.Text ->
  Source
newSource :: Owner -> Text -> Source
newSource Owner
pOwner_ Text
pSourceIdentifier_ =
  Source' :: Maybe [SourceDetail] -> Owner -> Text -> Source
Source'
    { $sel:sourceDetails:Source' :: Maybe [SourceDetail]
sourceDetails = Maybe [SourceDetail]
forall a. Maybe a
Prelude.Nothing,
      $sel:owner:Source' :: Owner
owner = Owner
pOwner_,
      $sel:sourceIdentifier:Source' :: Text
sourceIdentifier = Text
pSourceIdentifier_
    }

-- | Provides the source and type of the event that causes Config to evaluate
-- your Amazon Web Services resources.
source_sourceDetails :: Lens.Lens' Source (Prelude.Maybe [SourceDetail])
source_sourceDetails :: (Maybe [SourceDetail] -> f (Maybe [SourceDetail]))
-> Source -> f Source
source_sourceDetails = (Source -> Maybe [SourceDetail])
-> (Source -> Maybe [SourceDetail] -> Source)
-> Lens Source Source (Maybe [SourceDetail]) (Maybe [SourceDetail])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Source' {Maybe [SourceDetail]
sourceDetails :: Maybe [SourceDetail]
$sel:sourceDetails:Source' :: Source -> Maybe [SourceDetail]
sourceDetails} -> Maybe [SourceDetail]
sourceDetails) (\s :: Source
s@Source' {} Maybe [SourceDetail]
a -> Source
s {$sel:sourceDetails:Source' :: Maybe [SourceDetail]
sourceDetails = Maybe [SourceDetail]
a} :: Source) ((Maybe [SourceDetail] -> f (Maybe [SourceDetail]))
 -> Source -> f Source)
-> ((Maybe [SourceDetail] -> f (Maybe [SourceDetail]))
    -> Maybe [SourceDetail] -> f (Maybe [SourceDetail]))
-> (Maybe [SourceDetail] -> f (Maybe [SourceDetail]))
-> Source
-> f Source
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [SourceDetail] [SourceDetail] [SourceDetail] [SourceDetail]
-> Iso
     (Maybe [SourceDetail])
     (Maybe [SourceDetail])
     (Maybe [SourceDetail])
     (Maybe [SourceDetail])
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 AnIso [SourceDetail] [SourceDetail] [SourceDetail] [SourceDetail]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Indicates whether Amazon Web Services or the customer owns and manages
-- the Config rule.
source_owner :: Lens.Lens' Source Owner
source_owner :: (Owner -> f Owner) -> Source -> f Source
source_owner = (Source -> Owner)
-> (Source -> Owner -> Source) -> Lens Source Source Owner Owner
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Source' {Owner
owner :: Owner
$sel:owner:Source' :: Source -> Owner
owner} -> Owner
owner) (\s :: Source
s@Source' {} Owner
a -> Source
s {$sel:owner:Source' :: Owner
owner = Owner
a} :: Source)

-- | For Config managed rules, a predefined identifier from a list. For
-- example, @IAM_PASSWORD_POLICY@ is a managed rule. To reference a managed
-- rule, see
-- <https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_use-managed-rules.html Using Config managed rules>.
--
-- For custom rules, the identifier is the Amazon Resource Name (ARN) of
-- the rule\'s Lambda function, such as
-- @arn:aws:lambda:us-east-2:123456789012:function:custom_rule_name@.
source_sourceIdentifier :: Lens.Lens' Source Prelude.Text
source_sourceIdentifier :: (Text -> f Text) -> Source -> f Source
source_sourceIdentifier = (Source -> Text)
-> (Source -> Text -> Source) -> Lens Source Source Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Source' {Text
sourceIdentifier :: Text
$sel:sourceIdentifier:Source' :: Source -> Text
sourceIdentifier} -> Text
sourceIdentifier) (\s :: Source
s@Source' {} Text
a -> Source
s {$sel:sourceIdentifier:Source' :: Text
sourceIdentifier = Text
a} :: Source)

instance Core.FromJSON Source where
  parseJSON :: Value -> Parser Source
parseJSON =
    String -> (Object -> Parser Source) -> Value -> Parser Source
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Source"
      ( \Object
x ->
          Maybe [SourceDetail] -> Owner -> Text -> Source
Source'
            (Maybe [SourceDetail] -> Owner -> Text -> Source)
-> Parser (Maybe [SourceDetail])
-> Parser (Owner -> Text -> Source)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [SourceDetail]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"SourceDetails" Parser (Maybe (Maybe [SourceDetail]))
-> Maybe [SourceDetail] -> Parser (Maybe [SourceDetail])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [SourceDetail]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Owner -> Text -> Source)
-> Parser Owner -> Parser (Text -> Source)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Owner
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Owner")
            Parser (Text -> Source) -> Parser Text -> Parser Source
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
"SourceIdentifier")
      )

instance Prelude.Hashable Source

instance Prelude.NFData Source

instance Core.ToJSON Source where
  toJSON :: Source -> Value
toJSON Source' {Maybe [SourceDetail]
Text
Owner
sourceIdentifier :: Text
owner :: Owner
sourceDetails :: Maybe [SourceDetail]
$sel:sourceIdentifier:Source' :: Source -> Text
$sel:owner:Source' :: Source -> Owner
$sel:sourceDetails:Source' :: Source -> Maybe [SourceDetail]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"SourceDetails" Text -> [SourceDetail] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([SourceDetail] -> Pair) -> Maybe [SourceDetail] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [SourceDetail]
sourceDetails,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Owner" Text -> Owner -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Owner
owner),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"SourceIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
sourceIdentifier)
          ]
      )