{-# 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.PatchSource
-- 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.PatchSource 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

-- | Information about the patches to use to update the managed nodes,
-- including target operating systems and source repository. Applies to
-- Linux managed nodes only.
--
-- /See:/ 'newPatchSource' smart constructor.
data PatchSource = PatchSource'
  { -- | The name specified to identify the patch source.
    PatchSource -> Text
name :: Prelude.Text,
    -- | The specific operating system versions a patch repository applies to,
    -- such as \"Ubuntu16.04\", \"AmazonLinux2016.09\",
    -- \"RedhatEnterpriseLinux7.2\" or \"Suse12.7\". For lists of supported
    -- product values, see PatchFilter.
    PatchSource -> NonEmpty Text
products :: Prelude.NonEmpty Prelude.Text,
    -- | The value of the yum repo configuration. For example:
    --
    -- @[main]@
    --
    -- @name=MyCustomRepository@
    --
    -- @baseurl=https:\/\/my-custom-repository@
    --
    -- @enabled=1@
    --
    -- For information about other options available for your yum repository
    -- configuration, see
    -- <https://man7.org/linux/man-pages/man5/dnf.conf.5.html dnf.conf(5)>.
    PatchSource -> Sensitive Text
configuration :: Data.Sensitive Prelude.Text
  }
  deriving (PatchSource -> PatchSource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PatchSource -> PatchSource -> Bool
$c/= :: PatchSource -> PatchSource -> Bool
== :: PatchSource -> PatchSource -> Bool
$c== :: PatchSource -> PatchSource -> Bool
Prelude.Eq, Int -> PatchSource -> ShowS
[PatchSource] -> ShowS
PatchSource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PatchSource] -> ShowS
$cshowList :: [PatchSource] -> ShowS
show :: PatchSource -> String
$cshow :: PatchSource -> String
showsPrec :: Int -> PatchSource -> ShowS
$cshowsPrec :: Int -> PatchSource -> ShowS
Prelude.Show, forall x. Rep PatchSource x -> PatchSource
forall x. PatchSource -> Rep PatchSource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PatchSource x -> PatchSource
$cfrom :: forall x. PatchSource -> Rep PatchSource x
Prelude.Generic)

-- |
-- Create a value of 'PatchSource' 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:
--
-- 'name', 'patchSource_name' - The name specified to identify the patch source.
--
-- 'products', 'patchSource_products' - The specific operating system versions a patch repository applies to,
-- such as \"Ubuntu16.04\", \"AmazonLinux2016.09\",
-- \"RedhatEnterpriseLinux7.2\" or \"Suse12.7\". For lists of supported
-- product values, see PatchFilter.
--
-- 'configuration', 'patchSource_configuration' - The value of the yum repo configuration. For example:
--
-- @[main]@
--
-- @name=MyCustomRepository@
--
-- @baseurl=https:\/\/my-custom-repository@
--
-- @enabled=1@
--
-- For information about other options available for your yum repository
-- configuration, see
-- <https://man7.org/linux/man-pages/man5/dnf.conf.5.html dnf.conf(5)>.
newPatchSource ::
  -- | 'name'
  Prelude.Text ->
  -- | 'products'
  Prelude.NonEmpty Prelude.Text ->
  -- | 'configuration'
  Prelude.Text ->
  PatchSource
newPatchSource :: Text -> NonEmpty Text -> Text -> PatchSource
newPatchSource Text
pName_ NonEmpty Text
pProducts_ Text
pConfiguration_ =
  PatchSource'
    { $sel:name:PatchSource' :: Text
name = Text
pName_,
      $sel:products:PatchSource' :: NonEmpty Text
products = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pProducts_,
      $sel:configuration:PatchSource' :: Sensitive Text
configuration =
        forall a. Iso' (Sensitive a) a
Data._Sensitive forall t b. AReview t b -> b -> t
Lens.# Text
pConfiguration_
    }

-- | The name specified to identify the patch source.
patchSource_name :: Lens.Lens' PatchSource Prelude.Text
patchSource_name :: Lens' PatchSource Text
patchSource_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchSource' {Text
name :: Text
$sel:name:PatchSource' :: PatchSource -> Text
name} -> Text
name) (\s :: PatchSource
s@PatchSource' {} Text
a -> PatchSource
s {$sel:name:PatchSource' :: Text
name = Text
a} :: PatchSource)

-- | The specific operating system versions a patch repository applies to,
-- such as \"Ubuntu16.04\", \"AmazonLinux2016.09\",
-- \"RedhatEnterpriseLinux7.2\" or \"Suse12.7\". For lists of supported
-- product values, see PatchFilter.
patchSource_products :: Lens.Lens' PatchSource (Prelude.NonEmpty Prelude.Text)
patchSource_products :: Lens' PatchSource (NonEmpty Text)
patchSource_products = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchSource' {NonEmpty Text
products :: NonEmpty Text
$sel:products:PatchSource' :: PatchSource -> NonEmpty Text
products} -> NonEmpty Text
products) (\s :: PatchSource
s@PatchSource' {} NonEmpty Text
a -> PatchSource
s {$sel:products:PatchSource' :: NonEmpty Text
products = NonEmpty Text
a} :: PatchSource) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The value of the yum repo configuration. For example:
--
-- @[main]@
--
-- @name=MyCustomRepository@
--
-- @baseurl=https:\/\/my-custom-repository@
--
-- @enabled=1@
--
-- For information about other options available for your yum repository
-- configuration, see
-- <https://man7.org/linux/man-pages/man5/dnf.conf.5.html dnf.conf(5)>.
patchSource_configuration :: Lens.Lens' PatchSource Prelude.Text
patchSource_configuration :: Lens' PatchSource Text
patchSource_configuration = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PatchSource' {Sensitive Text
configuration :: Sensitive Text
$sel:configuration:PatchSource' :: PatchSource -> Sensitive Text
configuration} -> Sensitive Text
configuration) (\s :: PatchSource
s@PatchSource' {} Sensitive Text
a -> PatchSource
s {$sel:configuration:PatchSource' :: Sensitive Text
configuration = Sensitive Text
a} :: PatchSource) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall a. Iso' (Sensitive a) a
Data._Sensitive

instance Data.FromJSON PatchSource where
  parseJSON :: Value -> Parser PatchSource
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PatchSource"
      ( \Object
x ->
          Text -> NonEmpty Text -> Sensitive Text -> PatchSource
PatchSource'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
            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
"Products")
            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
"Configuration")
      )

instance Prelude.Hashable PatchSource where
  hashWithSalt :: Int -> PatchSource -> Int
hashWithSalt Int
_salt PatchSource' {NonEmpty Text
Text
Sensitive Text
configuration :: Sensitive Text
products :: NonEmpty Text
name :: Text
$sel:configuration:PatchSource' :: PatchSource -> Sensitive Text
$sel:products:PatchSource' :: PatchSource -> NonEmpty Text
$sel:name:PatchSource' :: PatchSource -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
products
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Sensitive Text
configuration

instance Prelude.NFData PatchSource where
  rnf :: PatchSource -> ()
rnf PatchSource' {NonEmpty Text
Text
Sensitive Text
configuration :: Sensitive Text
products :: NonEmpty Text
name :: Text
$sel:configuration:PatchSource' :: PatchSource -> Sensitive Text
$sel:products:PatchSource' :: PatchSource -> NonEmpty Text
$sel:name:PatchSource' :: PatchSource -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
products
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Sensitive Text
configuration

instance Data.ToJSON PatchSource where
  toJSON :: PatchSource -> Value
toJSON PatchSource' {NonEmpty Text
Text
Sensitive Text
configuration :: Sensitive Text
products :: NonEmpty Text
name :: Text
$sel:configuration:PatchSource' :: PatchSource -> Sensitive Text
$sel:products:PatchSource' :: PatchSource -> NonEmpty Text
$sel:name:PatchSource' :: PatchSource -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name),
            forall a. a -> Maybe a
Prelude.Just (Key
"Products" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
products),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"Configuration" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Sensitive Text
configuration)
          ]
      )