{-# 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.PatchRule
-- 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.PatchRule where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSM.Types.PatchComplianceLevel
import Amazonka.SSM.Types.PatchFilterGroup

-- | Defines an approval rule for a patch baseline.
--
-- /See:/ 'newPatchRule' smart constructor.
data PatchRule = PatchRule'
  { -- | The number of days after the release date of each patch matched by the
    -- rule that the patch is marked as approved in the patch baseline. For
    -- example, a value of @7@ means that patches are approved seven days after
    -- they are released. Not supported on Debian Server or Ubuntu Server.
    PatchRule -> Maybe Natural
approveAfterDays :: Prelude.Maybe Prelude.Natural,
    -- | The cutoff date for auto approval of released patches. Any patches
    -- released on or before this date are installed automatically. Not
    -- supported on Debian Server or Ubuntu Server.
    --
    -- Enter dates in the format @YYYY-MM-DD@. For example, @2021-12-31@.
    PatchRule -> Maybe Text
approveUntilDate :: Prelude.Maybe Prelude.Text,
    -- | For instances identified by the approval rule filters, enables a patch
    -- baseline to apply non-security updates available in the specified
    -- repository. The default value is @false@. Applies to Linux instances
    -- only.
    PatchRule -> Maybe Bool
enableNonSecurity :: Prelude.Maybe Prelude.Bool,
    -- | A compliance severity level for all approved patches in a patch
    -- baseline.
    PatchRule -> Maybe PatchComplianceLevel
complianceLevel :: Prelude.Maybe PatchComplianceLevel,
    -- | The patch filter group that defines the criteria for the rule.
    PatchRule -> PatchFilterGroup
patchFilterGroup :: PatchFilterGroup
  }
  deriving (PatchRule -> PatchRule -> Bool
(PatchRule -> PatchRule -> Bool)
-> (PatchRule -> PatchRule -> Bool) -> Eq PatchRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PatchRule -> PatchRule -> Bool
$c/= :: PatchRule -> PatchRule -> Bool
== :: PatchRule -> PatchRule -> Bool
$c== :: PatchRule -> PatchRule -> Bool
Prelude.Eq, ReadPrec [PatchRule]
ReadPrec PatchRule
Int -> ReadS PatchRule
ReadS [PatchRule]
(Int -> ReadS PatchRule)
-> ReadS [PatchRule]
-> ReadPrec PatchRule
-> ReadPrec [PatchRule]
-> Read PatchRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PatchRule]
$creadListPrec :: ReadPrec [PatchRule]
readPrec :: ReadPrec PatchRule
$creadPrec :: ReadPrec PatchRule
readList :: ReadS [PatchRule]
$creadList :: ReadS [PatchRule]
readsPrec :: Int -> ReadS PatchRule
$creadsPrec :: Int -> ReadS PatchRule
Prelude.Read, Int -> PatchRule -> ShowS
[PatchRule] -> ShowS
PatchRule -> String
(Int -> PatchRule -> ShowS)
-> (PatchRule -> String)
-> ([PatchRule] -> ShowS)
-> Show PatchRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PatchRule] -> ShowS
$cshowList :: [PatchRule] -> ShowS
show :: PatchRule -> String
$cshow :: PatchRule -> String
showsPrec :: Int -> PatchRule -> ShowS
$cshowsPrec :: Int -> PatchRule -> ShowS
Prelude.Show, (forall x. PatchRule -> Rep PatchRule x)
-> (forall x. Rep PatchRule x -> PatchRule) -> Generic PatchRule
forall x. Rep PatchRule x -> PatchRule
forall x. PatchRule -> Rep PatchRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PatchRule x -> PatchRule
$cfrom :: forall x. PatchRule -> Rep PatchRule x
Prelude.Generic)

-- |
-- Create a value of 'PatchRule' 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:
--
-- 'approveAfterDays', 'patchRule_approveAfterDays' - The number of days after the release date of each patch matched by the
-- rule that the patch is marked as approved in the patch baseline. For
-- example, a value of @7@ means that patches are approved seven days after
-- they are released. Not supported on Debian Server or Ubuntu Server.
--
-- 'approveUntilDate', 'patchRule_approveUntilDate' - The cutoff date for auto approval of released patches. Any patches
-- released on or before this date are installed automatically. Not
-- supported on Debian Server or Ubuntu Server.
--
-- Enter dates in the format @YYYY-MM-DD@. For example, @2021-12-31@.
--
-- 'enableNonSecurity', 'patchRule_enableNonSecurity' - For instances identified by the approval rule filters, enables a patch
-- baseline to apply non-security updates available in the specified
-- repository. The default value is @false@. Applies to Linux instances
-- only.
--
-- 'complianceLevel', 'patchRule_complianceLevel' - A compliance severity level for all approved patches in a patch
-- baseline.
--
-- 'patchFilterGroup', 'patchRule_patchFilterGroup' - The patch filter group that defines the criteria for the rule.
newPatchRule ::
  -- | 'patchFilterGroup'
  PatchFilterGroup ->
  PatchRule
newPatchRule :: PatchFilterGroup -> PatchRule
newPatchRule PatchFilterGroup
pPatchFilterGroup_ =
  PatchRule' :: Maybe Natural
-> Maybe Text
-> Maybe Bool
-> Maybe PatchComplianceLevel
-> PatchFilterGroup
-> PatchRule
PatchRule'
    { $sel:approveAfterDays:PatchRule' :: Maybe Natural
approveAfterDays = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:approveUntilDate:PatchRule' :: Maybe Text
approveUntilDate = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:enableNonSecurity:PatchRule' :: Maybe Bool
enableNonSecurity = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:complianceLevel:PatchRule' :: Maybe PatchComplianceLevel
complianceLevel = Maybe PatchComplianceLevel
forall a. Maybe a
Prelude.Nothing,
      $sel:patchFilterGroup:PatchRule' :: PatchFilterGroup
patchFilterGroup = PatchFilterGroup
pPatchFilterGroup_
    }

-- | The number of days after the release date of each patch matched by the
-- rule that the patch is marked as approved in the patch baseline. For
-- example, a value of @7@ means that patches are approved seven days after
-- they are released. Not supported on Debian Server or Ubuntu Server.
patchRule_approveAfterDays :: Lens.Lens' PatchRule (Prelude.Maybe Prelude.Natural)
patchRule_approveAfterDays :: (Maybe Natural -> f (Maybe Natural)) -> PatchRule -> f PatchRule
patchRule_approveAfterDays = (PatchRule -> Maybe Natural)
-> (PatchRule -> Maybe Natural -> PatchRule)
-> Lens PatchRule PatchRule (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchRule' {Maybe Natural
approveAfterDays :: Maybe Natural
$sel:approveAfterDays:PatchRule' :: PatchRule -> Maybe Natural
approveAfterDays} -> Maybe Natural
approveAfterDays) (\s :: PatchRule
s@PatchRule' {} Maybe Natural
a -> PatchRule
s {$sel:approveAfterDays:PatchRule' :: Maybe Natural
approveAfterDays = Maybe Natural
a} :: PatchRule)

-- | The cutoff date for auto approval of released patches. Any patches
-- released on or before this date are installed automatically. Not
-- supported on Debian Server or Ubuntu Server.
--
-- Enter dates in the format @YYYY-MM-DD@. For example, @2021-12-31@.
patchRule_approveUntilDate :: Lens.Lens' PatchRule (Prelude.Maybe Prelude.Text)
patchRule_approveUntilDate :: (Maybe Text -> f (Maybe Text)) -> PatchRule -> f PatchRule
patchRule_approveUntilDate = (PatchRule -> Maybe Text)
-> (PatchRule -> Maybe Text -> PatchRule)
-> Lens PatchRule PatchRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchRule' {Maybe Text
approveUntilDate :: Maybe Text
$sel:approveUntilDate:PatchRule' :: PatchRule -> Maybe Text
approveUntilDate} -> Maybe Text
approveUntilDate) (\s :: PatchRule
s@PatchRule' {} Maybe Text
a -> PatchRule
s {$sel:approveUntilDate:PatchRule' :: Maybe Text
approveUntilDate = Maybe Text
a} :: PatchRule)

-- | For instances identified by the approval rule filters, enables a patch
-- baseline to apply non-security updates available in the specified
-- repository. The default value is @false@. Applies to Linux instances
-- only.
patchRule_enableNonSecurity :: Lens.Lens' PatchRule (Prelude.Maybe Prelude.Bool)
patchRule_enableNonSecurity :: (Maybe Bool -> f (Maybe Bool)) -> PatchRule -> f PatchRule
patchRule_enableNonSecurity = (PatchRule -> Maybe Bool)
-> (PatchRule -> Maybe Bool -> PatchRule)
-> Lens PatchRule PatchRule (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchRule' {Maybe Bool
enableNonSecurity :: Maybe Bool
$sel:enableNonSecurity:PatchRule' :: PatchRule -> Maybe Bool
enableNonSecurity} -> Maybe Bool
enableNonSecurity) (\s :: PatchRule
s@PatchRule' {} Maybe Bool
a -> PatchRule
s {$sel:enableNonSecurity:PatchRule' :: Maybe Bool
enableNonSecurity = Maybe Bool
a} :: PatchRule)

-- | A compliance severity level for all approved patches in a patch
-- baseline.
patchRule_complianceLevel :: Lens.Lens' PatchRule (Prelude.Maybe PatchComplianceLevel)
patchRule_complianceLevel :: (Maybe PatchComplianceLevel -> f (Maybe PatchComplianceLevel))
-> PatchRule -> f PatchRule
patchRule_complianceLevel = (PatchRule -> Maybe PatchComplianceLevel)
-> (PatchRule -> Maybe PatchComplianceLevel -> PatchRule)
-> Lens
     PatchRule
     PatchRule
     (Maybe PatchComplianceLevel)
     (Maybe PatchComplianceLevel)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchRule' {Maybe PatchComplianceLevel
complianceLevel :: Maybe PatchComplianceLevel
$sel:complianceLevel:PatchRule' :: PatchRule -> Maybe PatchComplianceLevel
complianceLevel} -> Maybe PatchComplianceLevel
complianceLevel) (\s :: PatchRule
s@PatchRule' {} Maybe PatchComplianceLevel
a -> PatchRule
s {$sel:complianceLevel:PatchRule' :: Maybe PatchComplianceLevel
complianceLevel = Maybe PatchComplianceLevel
a} :: PatchRule)

-- | The patch filter group that defines the criteria for the rule.
patchRule_patchFilterGroup :: Lens.Lens' PatchRule PatchFilterGroup
patchRule_patchFilterGroup :: (PatchFilterGroup -> f PatchFilterGroup)
-> PatchRule -> f PatchRule
patchRule_patchFilterGroup = (PatchRule -> PatchFilterGroup)
-> (PatchRule -> PatchFilterGroup -> PatchRule)
-> Lens PatchRule PatchRule PatchFilterGroup PatchFilterGroup
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchRule' {PatchFilterGroup
patchFilterGroup :: PatchFilterGroup
$sel:patchFilterGroup:PatchRule' :: PatchRule -> PatchFilterGroup
patchFilterGroup} -> PatchFilterGroup
patchFilterGroup) (\s :: PatchRule
s@PatchRule' {} PatchFilterGroup
a -> PatchRule
s {$sel:patchFilterGroup:PatchRule' :: PatchFilterGroup
patchFilterGroup = PatchFilterGroup
a} :: PatchRule)

instance Core.FromJSON PatchRule where
  parseJSON :: Value -> Parser PatchRule
parseJSON =
    String -> (Object -> Parser PatchRule) -> Value -> Parser PatchRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PatchRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe Text
-> Maybe Bool
-> Maybe PatchComplianceLevel
-> PatchFilterGroup
-> PatchRule
PatchRule'
            (Maybe Natural
 -> Maybe Text
 -> Maybe Bool
 -> Maybe PatchComplianceLevel
 -> PatchFilterGroup
 -> PatchRule)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Text
      -> Maybe Bool
      -> Maybe PatchComplianceLevel
      -> PatchFilterGroup
      -> PatchRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ApproveAfterDays")
            Parser
  (Maybe Text
   -> Maybe Bool
   -> Maybe PatchComplianceLevel
   -> PatchFilterGroup
   -> PatchRule)
-> Parser (Maybe Text)
-> Parser
     (Maybe Bool
      -> Maybe PatchComplianceLevel -> PatchFilterGroup -> PatchRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ApproveUntilDate")
            Parser
  (Maybe Bool
   -> Maybe PatchComplianceLevel -> PatchFilterGroup -> PatchRule)
-> Parser (Maybe Bool)
-> Parser
     (Maybe PatchComplianceLevel -> PatchFilterGroup -> PatchRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"EnableNonSecurity")
            Parser
  (Maybe PatchComplianceLevel -> PatchFilterGroup -> PatchRule)
-> Parser (Maybe PatchComplianceLevel)
-> Parser (PatchFilterGroup -> PatchRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe PatchComplianceLevel)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ComplianceLevel")
            Parser (PatchFilterGroup -> PatchRule)
-> Parser PatchFilterGroup -> Parser PatchRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PatchFilterGroup
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"PatchFilterGroup")
      )

instance Prelude.Hashable PatchRule

instance Prelude.NFData PatchRule

instance Core.ToJSON PatchRule where
  toJSON :: PatchRule -> Value
toJSON PatchRule' {Maybe Bool
Maybe Natural
Maybe Text
Maybe PatchComplianceLevel
PatchFilterGroup
patchFilterGroup :: PatchFilterGroup
complianceLevel :: Maybe PatchComplianceLevel
enableNonSecurity :: Maybe Bool
approveUntilDate :: Maybe Text
approveAfterDays :: Maybe Natural
$sel:patchFilterGroup:PatchRule' :: PatchRule -> PatchFilterGroup
$sel:complianceLevel:PatchRule' :: PatchRule -> Maybe PatchComplianceLevel
$sel:enableNonSecurity:PatchRule' :: PatchRule -> Maybe Bool
$sel:approveUntilDate:PatchRule' :: PatchRule -> Maybe Text
$sel:approveAfterDays:PatchRule' :: PatchRule -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ApproveAfterDays" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
approveAfterDays,
            (Text
"ApproveUntilDate" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
approveUntilDate,
            (Text
"EnableNonSecurity" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enableNonSecurity,
            (Text
"ComplianceLevel" Text -> PatchComplianceLevel -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (PatchComplianceLevel -> Pair)
-> Maybe PatchComplianceLevel -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PatchComplianceLevel
complianceLevel,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"PatchFilterGroup" Text -> PatchFilterGroup -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PatchFilterGroup
patchFilterGroup)
          ]
      )