{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SSM.Types.PatchRule 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
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,
    -- | A compliance severity level for all approved patches in a patch
    -- baseline.
    PatchRule -> Maybe PatchComplianceLevel
complianceLevel :: Prelude.Maybe PatchComplianceLevel,
    -- | For managed nodes 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 managed nodes
    -- only.
    PatchRule -> Maybe Bool
enableNonSecurity :: Prelude.Maybe Prelude.Bool,
    -- | The patch filter group that defines the criteria for the rule.
    PatchRule -> PatchFilterGroup
patchFilterGroup :: PatchFilterGroup
  }
  deriving (PatchRule -> PatchRule -> Bool
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]
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
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. 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@.
--
-- 'complianceLevel', 'patchRule_complianceLevel' - A compliance severity level for all approved patches in a patch
-- baseline.
--
-- 'enableNonSecurity', 'patchRule_enableNonSecurity' - For managed nodes 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 managed nodes
-- only.
--
-- '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'
    { $sel:approveAfterDays:PatchRule' :: Maybe Natural
approveAfterDays = forall a. Maybe a
Prelude.Nothing,
      $sel:approveUntilDate:PatchRule' :: Maybe Text
approveUntilDate = forall a. Maybe a
Prelude.Nothing,
      $sel:complianceLevel:PatchRule' :: Maybe PatchComplianceLevel
complianceLevel = forall a. Maybe a
Prelude.Nothing,
      $sel:enableNonSecurity:PatchRule' :: Maybe Bool
enableNonSecurity = 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 :: Lens' PatchRule (Maybe Natural)
patchRule_approveAfterDays = 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 :: Lens' PatchRule (Maybe Text)
patchRule_approveUntilDate = 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)

-- | A compliance severity level for all approved patches in a patch
-- baseline.
patchRule_complianceLevel :: Lens.Lens' PatchRule (Prelude.Maybe PatchComplianceLevel)
patchRule_complianceLevel :: Lens' PatchRule (Maybe PatchComplianceLevel)
patchRule_complianceLevel = 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)

-- | For managed nodes 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 managed nodes
-- only.
patchRule_enableNonSecurity :: Lens.Lens' PatchRule (Prelude.Maybe Prelude.Bool)
patchRule_enableNonSecurity :: Lens' PatchRule (Maybe Bool)
patchRule_enableNonSecurity = 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)

-- | The patch filter group that defines the criteria for the rule.
patchRule_patchFilterGroup :: Lens.Lens' PatchRule PatchFilterGroup
patchRule_patchFilterGroup :: Lens' PatchRule PatchFilterGroup
patchRule_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 Data.FromJSON PatchRule where
  parseJSON :: Value -> Parser PatchRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PatchRule"
      ( \Object
x ->
          Maybe Natural
-> Maybe Text
-> Maybe PatchComplianceLevel
-> Maybe Bool
-> PatchFilterGroup
-> PatchRule
PatchRule'
            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
"ApproveAfterDays")
            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
"ApproveUntilDate")
            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
"ComplianceLevel")
            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
"EnableNonSecurity")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"PatchFilterGroup")
      )

instance Prelude.Hashable PatchRule where
  hashWithSalt :: Int -> PatchRule -> Int
hashWithSalt Int
_salt PatchRule' {Maybe Bool
Maybe Natural
Maybe Text
Maybe PatchComplianceLevel
PatchFilterGroup
patchFilterGroup :: PatchFilterGroup
enableNonSecurity :: Maybe Bool
complianceLevel :: Maybe PatchComplianceLevel
approveUntilDate :: Maybe Text
approveAfterDays :: Maybe Natural
$sel:patchFilterGroup:PatchRule' :: PatchRule -> PatchFilterGroup
$sel:enableNonSecurity:PatchRule' :: PatchRule -> Maybe Bool
$sel:complianceLevel:PatchRule' :: PatchRule -> Maybe PatchComplianceLevel
$sel:approveUntilDate:PatchRule' :: PatchRule -> Maybe Text
$sel:approveAfterDays:PatchRule' :: PatchRule -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
approveAfterDays
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
approveUntilDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PatchComplianceLevel
complianceLevel
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enableNonSecurity
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PatchFilterGroup
patchFilterGroup

instance Prelude.NFData PatchRule where
  rnf :: PatchRule -> ()
rnf PatchRule' {Maybe Bool
Maybe Natural
Maybe Text
Maybe PatchComplianceLevel
PatchFilterGroup
patchFilterGroup :: PatchFilterGroup
enableNonSecurity :: Maybe Bool
complianceLevel :: Maybe PatchComplianceLevel
approveUntilDate :: Maybe Text
approveAfterDays :: Maybe Natural
$sel:patchFilterGroup:PatchRule' :: PatchRule -> PatchFilterGroup
$sel:enableNonSecurity:PatchRule' :: PatchRule -> Maybe Bool
$sel:complianceLevel:PatchRule' :: PatchRule -> Maybe PatchComplianceLevel
$sel:approveUntilDate:PatchRule' :: PatchRule -> Maybe Text
$sel:approveAfterDays:PatchRule' :: PatchRule -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
approveAfterDays
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
approveUntilDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe PatchComplianceLevel
complianceLevel
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enableNonSecurity
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf PatchFilterGroup
patchFilterGroup

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