{-# 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.Backup.Types.ControlScope
-- 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.Backup.Types.ControlScope 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

-- | A framework consists of one or more controls. Each control has its own
-- control scope. The control scope can include one or more resource types,
-- a combination of a tag key and value, or a combination of one resource
-- type and one resource ID. If no scope is specified, evaluations for the
-- rule are triggered when any resource in your recording group changes in
-- configuration.
--
-- To set a control scope that includes all of a particular resource, leave
-- the @ControlScope@ empty or do not pass it when calling
-- @CreateFramework@.
--
-- /See:/ 'newControlScope' smart constructor.
data ControlScope = ControlScope'
  { -- | The ID of the only Amazon Web Services resource that you want your
    -- control scope to contain.
    ControlScope -> Maybe (NonEmpty Text)
complianceResourceIds :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | Describes whether the control scope includes one or more types of
    -- resources, such as @EFS@ or @RDS@.
    ControlScope -> Maybe [Text]
complianceResourceTypes :: Prelude.Maybe [Prelude.Text],
    -- | The tag key-value pair applied to those Amazon Web Services resources
    -- that you want to trigger an evaluation for a rule. A maximum of one
    -- key-value pair can be provided. The tag value is optional, but it cannot
    -- be an empty string. The structure to assign a tag is:
    -- @[{\"Key\":\"string\",\"Value\":\"string\"}]@.
    ControlScope -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (ControlScope -> ControlScope -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ControlScope -> ControlScope -> Bool
$c/= :: ControlScope -> ControlScope -> Bool
== :: ControlScope -> ControlScope -> Bool
$c== :: ControlScope -> ControlScope -> Bool
Prelude.Eq, ReadPrec [ControlScope]
ReadPrec ControlScope
Int -> ReadS ControlScope
ReadS [ControlScope]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ControlScope]
$creadListPrec :: ReadPrec [ControlScope]
readPrec :: ReadPrec ControlScope
$creadPrec :: ReadPrec ControlScope
readList :: ReadS [ControlScope]
$creadList :: ReadS [ControlScope]
readsPrec :: Int -> ReadS ControlScope
$creadsPrec :: Int -> ReadS ControlScope
Prelude.Read, Int -> ControlScope -> ShowS
[ControlScope] -> ShowS
ControlScope -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ControlScope] -> ShowS
$cshowList :: [ControlScope] -> ShowS
show :: ControlScope -> String
$cshow :: ControlScope -> String
showsPrec :: Int -> ControlScope -> ShowS
$cshowsPrec :: Int -> ControlScope -> ShowS
Prelude.Show, forall x. Rep ControlScope x -> ControlScope
forall x. ControlScope -> Rep ControlScope x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ControlScope x -> ControlScope
$cfrom :: forall x. ControlScope -> Rep ControlScope x
Prelude.Generic)

-- |
-- Create a value of 'ControlScope' 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:
--
-- 'complianceResourceIds', 'controlScope_complianceResourceIds' - The ID of the only Amazon Web Services resource that you want your
-- control scope to contain.
--
-- 'complianceResourceTypes', 'controlScope_complianceResourceTypes' - Describes whether the control scope includes one or more types of
-- resources, such as @EFS@ or @RDS@.
--
-- 'tags', 'controlScope_tags' - The tag key-value pair applied to those Amazon Web Services resources
-- that you want to trigger an evaluation for a rule. A maximum of one
-- key-value pair can be provided. The tag value is optional, but it cannot
-- be an empty string. The structure to assign a tag is:
-- @[{\"Key\":\"string\",\"Value\":\"string\"}]@.
newControlScope ::
  ControlScope
newControlScope :: ControlScope
newControlScope =
  ControlScope'
    { $sel:complianceResourceIds:ControlScope' :: Maybe (NonEmpty Text)
complianceResourceIds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:complianceResourceTypes:ControlScope' :: Maybe [Text]
complianceResourceTypes = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:ControlScope' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the only Amazon Web Services resource that you want your
-- control scope to contain.
controlScope_complianceResourceIds :: Lens.Lens' ControlScope (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
controlScope_complianceResourceIds :: Lens' ControlScope (Maybe (NonEmpty Text))
controlScope_complianceResourceIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ControlScope' {Maybe (NonEmpty Text)
complianceResourceIds :: Maybe (NonEmpty Text)
$sel:complianceResourceIds:ControlScope' :: ControlScope -> Maybe (NonEmpty Text)
complianceResourceIds} -> Maybe (NonEmpty Text)
complianceResourceIds) (\s :: ControlScope
s@ControlScope' {} Maybe (NonEmpty Text)
a -> ControlScope
s {$sel:complianceResourceIds:ControlScope' :: Maybe (NonEmpty Text)
complianceResourceIds = Maybe (NonEmpty Text)
a} :: ControlScope) 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

-- | Describes whether the control scope includes one or more types of
-- resources, such as @EFS@ or @RDS@.
controlScope_complianceResourceTypes :: Lens.Lens' ControlScope (Prelude.Maybe [Prelude.Text])
controlScope_complianceResourceTypes :: Lens' ControlScope (Maybe [Text])
controlScope_complianceResourceTypes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ControlScope' {Maybe [Text]
complianceResourceTypes :: Maybe [Text]
$sel:complianceResourceTypes:ControlScope' :: ControlScope -> Maybe [Text]
complianceResourceTypes} -> Maybe [Text]
complianceResourceTypes) (\s :: ControlScope
s@ControlScope' {} Maybe [Text]
a -> ControlScope
s {$sel:complianceResourceTypes:ControlScope' :: Maybe [Text]
complianceResourceTypes = Maybe [Text]
a} :: ControlScope) 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

-- | The tag key-value pair applied to those Amazon Web Services resources
-- that you want to trigger an evaluation for a rule. A maximum of one
-- key-value pair can be provided. The tag value is optional, but it cannot
-- be an empty string. The structure to assign a tag is:
-- @[{\"Key\":\"string\",\"Value\":\"string\"}]@.
controlScope_tags :: Lens.Lens' ControlScope (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
controlScope_tags :: Lens' ControlScope (Maybe (HashMap Text Text))
controlScope_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ControlScope' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:ControlScope' :: ControlScope -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: ControlScope
s@ControlScope' {} Maybe (HashMap Text Text)
a -> ControlScope
s {$sel:tags:ControlScope' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: ControlScope) 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

instance Data.FromJSON ControlScope where
  parseJSON :: Value -> Parser ControlScope
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ControlScope"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe [Text] -> Maybe (HashMap Text Text) -> ControlScope
ControlScope'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ComplianceResourceIds")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ComplianceResourceTypes"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Tags" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable ControlScope where
  hashWithSalt :: Int -> ControlScope -> Int
hashWithSalt Int
_salt ControlScope' {Maybe [Text]
Maybe (NonEmpty Text)
Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
complianceResourceTypes :: Maybe [Text]
complianceResourceIds :: Maybe (NonEmpty Text)
$sel:tags:ControlScope' :: ControlScope -> Maybe (HashMap Text Text)
$sel:complianceResourceTypes:ControlScope' :: ControlScope -> Maybe [Text]
$sel:complianceResourceIds:ControlScope' :: ControlScope -> Maybe (NonEmpty Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
complianceResourceIds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
complianceResourceTypes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags

instance Prelude.NFData ControlScope where
  rnf :: ControlScope -> ()
rnf ControlScope' {Maybe [Text]
Maybe (NonEmpty Text)
Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
complianceResourceTypes :: Maybe [Text]
complianceResourceIds :: Maybe (NonEmpty Text)
$sel:tags:ControlScope' :: ControlScope -> Maybe (HashMap Text Text)
$sel:complianceResourceTypes:ControlScope' :: ControlScope -> Maybe [Text]
$sel:complianceResourceIds:ControlScope' :: ControlScope -> Maybe (NonEmpty Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
complianceResourceIds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
complianceResourceTypes
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags

instance Data.ToJSON ControlScope where
  toJSON :: ControlScope -> Value
toJSON ControlScope' {Maybe [Text]
Maybe (NonEmpty Text)
Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
complianceResourceTypes :: Maybe [Text]
complianceResourceIds :: Maybe (NonEmpty Text)
$sel:tags:ControlScope' :: ControlScope -> Maybe (HashMap Text Text)
$sel:complianceResourceTypes:ControlScope' :: ControlScope -> Maybe [Text]
$sel:complianceResourceIds:ControlScope' :: ControlScope -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ComplianceResourceIds" 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 (NonEmpty Text)
complianceResourceIds,
            (Key
"ComplianceResourceTypes" 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]
complianceResourceTypes,
            (Key
"Tags" 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 (HashMap Text Text)
tags
          ]
      )