{-# 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.ImageBuilder.Types.ImageTestsConfiguration
-- 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.ImageBuilder.Types.ImageTestsConfiguration 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

-- | Configure image tests for your pipeline build. Tests run after building
-- the image, to verify that the AMI or container image is valid before
-- distributing it.
--
-- /See:/ 'newImageTestsConfiguration' smart constructor.
data ImageTestsConfiguration = ImageTestsConfiguration'
  { -- | Determines if tests should run after building the image. Image Builder
    -- defaults to enable tests to run following the image build, before image
    -- distribution.
    ImageTestsConfiguration -> Maybe Bool
imageTestsEnabled :: Prelude.Maybe Prelude.Bool,
    -- | The maximum time in minutes that tests are permitted to run.
    ImageTestsConfiguration -> Maybe Natural
timeoutMinutes :: Prelude.Maybe Prelude.Natural
  }
  deriving (ImageTestsConfiguration -> ImageTestsConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImageTestsConfiguration -> ImageTestsConfiguration -> Bool
$c/= :: ImageTestsConfiguration -> ImageTestsConfiguration -> Bool
== :: ImageTestsConfiguration -> ImageTestsConfiguration -> Bool
$c== :: ImageTestsConfiguration -> ImageTestsConfiguration -> Bool
Prelude.Eq, ReadPrec [ImageTestsConfiguration]
ReadPrec ImageTestsConfiguration
Int -> ReadS ImageTestsConfiguration
ReadS [ImageTestsConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ImageTestsConfiguration]
$creadListPrec :: ReadPrec [ImageTestsConfiguration]
readPrec :: ReadPrec ImageTestsConfiguration
$creadPrec :: ReadPrec ImageTestsConfiguration
readList :: ReadS [ImageTestsConfiguration]
$creadList :: ReadS [ImageTestsConfiguration]
readsPrec :: Int -> ReadS ImageTestsConfiguration
$creadsPrec :: Int -> ReadS ImageTestsConfiguration
Prelude.Read, Int -> ImageTestsConfiguration -> ShowS
[ImageTestsConfiguration] -> ShowS
ImageTestsConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImageTestsConfiguration] -> ShowS
$cshowList :: [ImageTestsConfiguration] -> ShowS
show :: ImageTestsConfiguration -> String
$cshow :: ImageTestsConfiguration -> String
showsPrec :: Int -> ImageTestsConfiguration -> ShowS
$cshowsPrec :: Int -> ImageTestsConfiguration -> ShowS
Prelude.Show, forall x. Rep ImageTestsConfiguration x -> ImageTestsConfiguration
forall x. ImageTestsConfiguration -> Rep ImageTestsConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImageTestsConfiguration x -> ImageTestsConfiguration
$cfrom :: forall x. ImageTestsConfiguration -> Rep ImageTestsConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ImageTestsConfiguration' 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:
--
-- 'imageTestsEnabled', 'imageTestsConfiguration_imageTestsEnabled' - Determines if tests should run after building the image. Image Builder
-- defaults to enable tests to run following the image build, before image
-- distribution.
--
-- 'timeoutMinutes', 'imageTestsConfiguration_timeoutMinutes' - The maximum time in minutes that tests are permitted to run.
newImageTestsConfiguration ::
  ImageTestsConfiguration
newImageTestsConfiguration :: ImageTestsConfiguration
newImageTestsConfiguration =
  ImageTestsConfiguration'
    { $sel:imageTestsEnabled:ImageTestsConfiguration' :: Maybe Bool
imageTestsEnabled =
        forall a. Maybe a
Prelude.Nothing,
      $sel:timeoutMinutes:ImageTestsConfiguration' :: Maybe Natural
timeoutMinutes = forall a. Maybe a
Prelude.Nothing
    }

-- | Determines if tests should run after building the image. Image Builder
-- defaults to enable tests to run following the image build, before image
-- distribution.
imageTestsConfiguration_imageTestsEnabled :: Lens.Lens' ImageTestsConfiguration (Prelude.Maybe Prelude.Bool)
imageTestsConfiguration_imageTestsEnabled :: Lens' ImageTestsConfiguration (Maybe Bool)
imageTestsConfiguration_imageTestsEnabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageTestsConfiguration' {Maybe Bool
imageTestsEnabled :: Maybe Bool
$sel:imageTestsEnabled:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Bool
imageTestsEnabled} -> Maybe Bool
imageTestsEnabled) (\s :: ImageTestsConfiguration
s@ImageTestsConfiguration' {} Maybe Bool
a -> ImageTestsConfiguration
s {$sel:imageTestsEnabled:ImageTestsConfiguration' :: Maybe Bool
imageTestsEnabled = Maybe Bool
a} :: ImageTestsConfiguration)

-- | The maximum time in minutes that tests are permitted to run.
imageTestsConfiguration_timeoutMinutes :: Lens.Lens' ImageTestsConfiguration (Prelude.Maybe Prelude.Natural)
imageTestsConfiguration_timeoutMinutes :: Lens' ImageTestsConfiguration (Maybe Natural)
imageTestsConfiguration_timeoutMinutes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImageTestsConfiguration' {Maybe Natural
timeoutMinutes :: Maybe Natural
$sel:timeoutMinutes:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Natural
timeoutMinutes} -> Maybe Natural
timeoutMinutes) (\s :: ImageTestsConfiguration
s@ImageTestsConfiguration' {} Maybe Natural
a -> ImageTestsConfiguration
s {$sel:timeoutMinutes:ImageTestsConfiguration' :: Maybe Natural
timeoutMinutes = Maybe Natural
a} :: ImageTestsConfiguration)

instance Data.FromJSON ImageTestsConfiguration where
  parseJSON :: Value -> Parser ImageTestsConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ImageTestsConfiguration"
      ( \Object
x ->
          Maybe Bool -> Maybe Natural -> ImageTestsConfiguration
ImageTestsConfiguration'
            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
"imageTestsEnabled")
            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
"timeoutMinutes")
      )

instance Prelude.Hashable ImageTestsConfiguration where
  hashWithSalt :: Int -> ImageTestsConfiguration -> Int
hashWithSalt Int
_salt ImageTestsConfiguration' {Maybe Bool
Maybe Natural
timeoutMinutes :: Maybe Natural
imageTestsEnabled :: Maybe Bool
$sel:timeoutMinutes:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Natural
$sel:imageTestsEnabled:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
imageTestsEnabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
timeoutMinutes

instance Prelude.NFData ImageTestsConfiguration where
  rnf :: ImageTestsConfiguration -> ()
rnf ImageTestsConfiguration' {Maybe Bool
Maybe Natural
timeoutMinutes :: Maybe Natural
imageTestsEnabled :: Maybe Bool
$sel:timeoutMinutes:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Natural
$sel:imageTestsEnabled:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
imageTestsEnabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
timeoutMinutes

instance Data.ToJSON ImageTestsConfiguration where
  toJSON :: ImageTestsConfiguration -> Value
toJSON ImageTestsConfiguration' {Maybe Bool
Maybe Natural
timeoutMinutes :: Maybe Natural
imageTestsEnabled :: Maybe Bool
$sel:timeoutMinutes:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Natural
$sel:imageTestsEnabled:ImageTestsConfiguration' :: ImageTestsConfiguration -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"imageTestsEnabled" 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
imageTestsEnabled,
            (Key
"timeoutMinutes" 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
timeoutMinutes
          ]
      )