{-# 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.SSM.Types.PatchFilter
-- 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.SSM.Types.PatchFilter where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSM.Types.PatchFilterKey

-- | Defines which patches should be included in a patch baseline.
--
-- A patch filter consists of a key and a set of values. The filter key is
-- a patch property. For example, the available filter keys for @WINDOWS@
-- are @PATCH_SET@, @PRODUCT@, @PRODUCT_FAMILY@, @CLASSIFICATION@, and
-- @MSRC_SEVERITY@.
--
-- The filter values define a matching criterion for the patch property
-- indicated by the key. For example, if the filter key is @PRODUCT@ and
-- the filter values are @[\"Office 2013\", \"Office 2016\"]@, then the
-- filter accepts all patches where product name is either \"Office 2013\"
-- or \"Office 2016\". The filter values can be exact values for the patch
-- property given as a key, or a wildcard (*), which matches all values.
--
-- You can view lists of valid values for the patch properties by running
-- the @DescribePatchProperties@ command. For information about which patch
-- properties can be used with each major operating system, see
-- DescribePatchProperties.
--
-- /See:/ 'newPatchFilter' smart constructor.
data PatchFilter = PatchFilter'
  { -- | The key for the filter.
    --
    -- Run the DescribePatchProperties command to view lists of valid keys for
    -- each operating system type.
    PatchFilter -> PatchFilterKey
key :: PatchFilterKey,
    -- | The value for the filter key.
    --
    -- Run the DescribePatchProperties command to view lists of valid values
    -- for each key based on operating system type.
    PatchFilter -> NonEmpty Text
values :: Prelude.NonEmpty Prelude.Text
  }
  deriving (PatchFilter -> PatchFilter -> Bool
(PatchFilter -> PatchFilter -> Bool)
-> (PatchFilter -> PatchFilter -> Bool) -> Eq PatchFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PatchFilter -> PatchFilter -> Bool
$c/= :: PatchFilter -> PatchFilter -> Bool
== :: PatchFilter -> PatchFilter -> Bool
$c== :: PatchFilter -> PatchFilter -> Bool
Prelude.Eq, ReadPrec [PatchFilter]
ReadPrec PatchFilter
Int -> ReadS PatchFilter
ReadS [PatchFilter]
(Int -> ReadS PatchFilter)
-> ReadS [PatchFilter]
-> ReadPrec PatchFilter
-> ReadPrec [PatchFilter]
-> Read PatchFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PatchFilter]
$creadListPrec :: ReadPrec [PatchFilter]
readPrec :: ReadPrec PatchFilter
$creadPrec :: ReadPrec PatchFilter
readList :: ReadS [PatchFilter]
$creadList :: ReadS [PatchFilter]
readsPrec :: Int -> ReadS PatchFilter
$creadsPrec :: Int -> ReadS PatchFilter
Prelude.Read, Int -> PatchFilter -> ShowS
[PatchFilter] -> ShowS
PatchFilter -> String
(Int -> PatchFilter -> ShowS)
-> (PatchFilter -> String)
-> ([PatchFilter] -> ShowS)
-> Show PatchFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PatchFilter] -> ShowS
$cshowList :: [PatchFilter] -> ShowS
show :: PatchFilter -> String
$cshow :: PatchFilter -> String
showsPrec :: Int -> PatchFilter -> ShowS
$cshowsPrec :: Int -> PatchFilter -> ShowS
Prelude.Show, (forall x. PatchFilter -> Rep PatchFilter x)
-> (forall x. Rep PatchFilter x -> PatchFilter)
-> Generic PatchFilter
forall x. Rep PatchFilter x -> PatchFilter
forall x. PatchFilter -> Rep PatchFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PatchFilter x -> PatchFilter
$cfrom :: forall x. PatchFilter -> Rep PatchFilter x
Prelude.Generic)

-- |
-- Create a value of 'PatchFilter' 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:
--
-- 'key', 'patchFilter_key' - The key for the filter.
--
-- Run the DescribePatchProperties command to view lists of valid keys for
-- each operating system type.
--
-- 'values', 'patchFilter_values' - The value for the filter key.
--
-- Run the DescribePatchProperties command to view lists of valid values
-- for each key based on operating system type.
newPatchFilter ::
  -- | 'key'
  PatchFilterKey ->
  -- | 'values'
  Prelude.NonEmpty Prelude.Text ->
  PatchFilter
newPatchFilter :: PatchFilterKey -> NonEmpty Text -> PatchFilter
newPatchFilter PatchFilterKey
pKey_ NonEmpty Text
pValues_ =
  PatchFilter' :: PatchFilterKey -> NonEmpty Text -> PatchFilter
PatchFilter'
    { $sel:key:PatchFilter' :: PatchFilterKey
key = PatchFilterKey
pKey_,
      $sel:values:PatchFilter' :: NonEmpty Text
values = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pValues_
    }

-- | The key for the filter.
--
-- Run the DescribePatchProperties command to view lists of valid keys for
-- each operating system type.
patchFilter_key :: Lens.Lens' PatchFilter PatchFilterKey
patchFilter_key :: (PatchFilterKey -> f PatchFilterKey)
-> PatchFilter -> f PatchFilter
patchFilter_key = (PatchFilter -> PatchFilterKey)
-> (PatchFilter -> PatchFilterKey -> PatchFilter)
-> Lens PatchFilter PatchFilter PatchFilterKey PatchFilterKey
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchFilter' {PatchFilterKey
key :: PatchFilterKey
$sel:key:PatchFilter' :: PatchFilter -> PatchFilterKey
key} -> PatchFilterKey
key) (\s :: PatchFilter
s@PatchFilter' {} PatchFilterKey
a -> PatchFilter
s {$sel:key:PatchFilter' :: PatchFilterKey
key = PatchFilterKey
a} :: PatchFilter)

-- | The value for the filter key.
--
-- Run the DescribePatchProperties command to view lists of valid values
-- for each key based on operating system type.
patchFilter_values :: Lens.Lens' PatchFilter (Prelude.NonEmpty Prelude.Text)
patchFilter_values :: (NonEmpty Text -> f (NonEmpty Text))
-> PatchFilter -> f PatchFilter
patchFilter_values = (PatchFilter -> NonEmpty Text)
-> (PatchFilter -> NonEmpty Text -> PatchFilter)
-> Lens PatchFilter PatchFilter (NonEmpty Text) (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchFilter' {NonEmpty Text
values :: NonEmpty Text
$sel:values:PatchFilter' :: PatchFilter -> NonEmpty Text
values} -> NonEmpty Text
values) (\s :: PatchFilter
s@PatchFilter' {} NonEmpty Text
a -> PatchFilter
s {$sel:values:PatchFilter' :: NonEmpty Text
values = NonEmpty Text
a} :: PatchFilter) ((NonEmpty Text -> f (NonEmpty Text))
 -> PatchFilter -> f PatchFilter)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> PatchFilter
-> f PatchFilter
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON PatchFilter where
  parseJSON :: Value -> Parser PatchFilter
parseJSON =
    String
-> (Object -> Parser PatchFilter) -> Value -> Parser PatchFilter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PatchFilter"
      ( \Object
x ->
          PatchFilterKey -> NonEmpty Text -> PatchFilter
PatchFilter'
            (PatchFilterKey -> NonEmpty Text -> PatchFilter)
-> Parser PatchFilterKey -> Parser (NonEmpty Text -> PatchFilter)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser PatchFilterKey
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Key") Parser (NonEmpty Text -> PatchFilter)
-> Parser (NonEmpty Text) -> Parser PatchFilter
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Values")
      )

instance Prelude.Hashable PatchFilter

instance Prelude.NFData PatchFilter

instance Core.ToJSON PatchFilter where
  toJSON :: PatchFilter -> Value
toJSON PatchFilter' {NonEmpty Text
PatchFilterKey
values :: NonEmpty Text
key :: PatchFilterKey
$sel:values:PatchFilter' :: PatchFilter -> NonEmpty Text
$sel:key:PatchFilter' :: PatchFilter -> PatchFilterKey
..} =
    [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
"Key" Text -> PatchFilterKey -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PatchFilterKey
key),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Values" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
values)
          ]
      )