{-# 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.SecurityHub.Types.Severity
-- 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.SecurityHub.Types.Severity where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SecurityHub.Types.SeverityLabel

-- | The severity of the finding.
--
-- The finding provider can provide the initial severity. The finding
-- provider can only update the severity if it has not been updated using
-- @BatchUpdateFindings@.
--
-- The finding must have either @Label@ or @Normalized@ populated. If only
-- one of these attributes is populated, then Security Hub automatically
-- populates the other one. If neither attribute is populated, then the
-- finding is invalid. @Label@ is the preferred attribute.
--
-- /See:/ 'newSeverity' smart constructor.
data Severity = Severity'
  { -- | Deprecated. This attribute is being deprecated. Instead of providing
    -- @Product@, provide @Original@.
    --
    -- The native severity as defined by the Amazon Web Services service or
    -- integrated partner product that generated the finding.
    Severity -> Maybe Double
product :: Prelude.Maybe Prelude.Double,
    -- | The severity value of the finding. The allowed values are the following.
    --
    -- -   @INFORMATIONAL@ - No issue was found.
    --
    -- -   @LOW@ - The issue does not require action on its own.
    --
    -- -   @MEDIUM@ - The issue must be addressed but not urgently.
    --
    -- -   @HIGH@ - The issue must be addressed as a priority.
    --
    -- -   @CRITICAL@ - The issue must be remediated immediately to avoid it
    --     escalating.
    --
    -- If you provide @Normalized@ and do not provide @Label@, then @Label@ is
    -- set automatically as follows.
    --
    -- -   0 - @INFORMATIONAL@
    --
    -- -   1–39 - @LOW@
    --
    -- -   40–69 - @MEDIUM@
    --
    -- -   70–89 - @HIGH@
    --
    -- -   90–100 - @CRITICAL@
    Severity -> Maybe SeverityLabel
label :: Prelude.Maybe SeverityLabel,
    -- | The native severity from the finding product that generated the finding.
    Severity -> Maybe Text
original :: Prelude.Maybe Prelude.Text,
    -- | Deprecated. The normalized severity of a finding. This attribute is
    -- being deprecated. Instead of providing @Normalized@, provide @Label@.
    --
    -- If you provide @Label@ and do not provide @Normalized@, then
    -- @Normalized@ is set automatically as follows.
    --
    -- -   @INFORMATIONAL@ - 0
    --
    -- -   @LOW@ - 1
    --
    -- -   @MEDIUM@ - 40
    --
    -- -   @HIGH@ - 70
    --
    -- -   @CRITICAL@ - 90
    Severity -> Maybe Int
normalized :: Prelude.Maybe Prelude.Int
  }
  deriving (Severity -> Severity -> Bool
(Severity -> Severity -> Bool)
-> (Severity -> Severity -> Bool) -> Eq Severity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Severity -> Severity -> Bool
$c/= :: Severity -> Severity -> Bool
== :: Severity -> Severity -> Bool
$c== :: Severity -> Severity -> Bool
Prelude.Eq, ReadPrec [Severity]
ReadPrec Severity
Int -> ReadS Severity
ReadS [Severity]
(Int -> ReadS Severity)
-> ReadS [Severity]
-> ReadPrec Severity
-> ReadPrec [Severity]
-> Read Severity
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Severity]
$creadListPrec :: ReadPrec [Severity]
readPrec :: ReadPrec Severity
$creadPrec :: ReadPrec Severity
readList :: ReadS [Severity]
$creadList :: ReadS [Severity]
readsPrec :: Int -> ReadS Severity
$creadsPrec :: Int -> ReadS Severity
Prelude.Read, Int -> Severity -> ShowS
[Severity] -> ShowS
Severity -> String
(Int -> Severity -> ShowS)
-> (Severity -> String) -> ([Severity] -> ShowS) -> Show Severity
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Severity] -> ShowS
$cshowList :: [Severity] -> ShowS
show :: Severity -> String
$cshow :: Severity -> String
showsPrec :: Int -> Severity -> ShowS
$cshowsPrec :: Int -> Severity -> ShowS
Prelude.Show, (forall x. Severity -> Rep Severity x)
-> (forall x. Rep Severity x -> Severity) -> Generic Severity
forall x. Rep Severity x -> Severity
forall x. Severity -> Rep Severity x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Severity x -> Severity
$cfrom :: forall x. Severity -> Rep Severity x
Prelude.Generic)

-- |
-- Create a value of 'Severity' 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:
--
-- 'product', 'severity_product' - Deprecated. This attribute is being deprecated. Instead of providing
-- @Product@, provide @Original@.
--
-- The native severity as defined by the Amazon Web Services service or
-- integrated partner product that generated the finding.
--
-- 'label', 'severity_label' - The severity value of the finding. The allowed values are the following.
--
-- -   @INFORMATIONAL@ - No issue was found.
--
-- -   @LOW@ - The issue does not require action on its own.
--
-- -   @MEDIUM@ - The issue must be addressed but not urgently.
--
-- -   @HIGH@ - The issue must be addressed as a priority.
--
-- -   @CRITICAL@ - The issue must be remediated immediately to avoid it
--     escalating.
--
-- If you provide @Normalized@ and do not provide @Label@, then @Label@ is
-- set automatically as follows.
--
-- -   0 - @INFORMATIONAL@
--
-- -   1–39 - @LOW@
--
-- -   40–69 - @MEDIUM@
--
-- -   70–89 - @HIGH@
--
-- -   90–100 - @CRITICAL@
--
-- 'original', 'severity_original' - The native severity from the finding product that generated the finding.
--
-- 'normalized', 'severity_normalized' - Deprecated. The normalized severity of a finding. This attribute is
-- being deprecated. Instead of providing @Normalized@, provide @Label@.
--
-- If you provide @Label@ and do not provide @Normalized@, then
-- @Normalized@ is set automatically as follows.
--
-- -   @INFORMATIONAL@ - 0
--
-- -   @LOW@ - 1
--
-- -   @MEDIUM@ - 40
--
-- -   @HIGH@ - 70
--
-- -   @CRITICAL@ - 90
newSeverity ::
  Severity
newSeverity :: Severity
newSeverity =
  Severity' :: Maybe Double
-> Maybe SeverityLabel -> Maybe Text -> Maybe Int -> Severity
Severity'
    { $sel:product:Severity' :: Maybe Double
product = Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:label:Severity' :: Maybe SeverityLabel
label = Maybe SeverityLabel
forall a. Maybe a
Prelude.Nothing,
      $sel:original:Severity' :: Maybe Text
original = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:normalized:Severity' :: Maybe Int
normalized = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Deprecated. This attribute is being deprecated. Instead of providing
-- @Product@, provide @Original@.
--
-- The native severity as defined by the Amazon Web Services service or
-- integrated partner product that generated the finding.
severity_product :: Lens.Lens' Severity (Prelude.Maybe Prelude.Double)
severity_product :: (Maybe Double -> f (Maybe Double)) -> Severity -> f Severity
severity_product = (Severity -> Maybe Double)
-> (Severity -> Maybe Double -> Severity)
-> Lens Severity Severity (Maybe Double) (Maybe Double)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Severity' {Maybe Double
product :: Maybe Double
$sel:product:Severity' :: Severity -> Maybe Double
product} -> Maybe Double
product) (\s :: Severity
s@Severity' {} Maybe Double
a -> Severity
s {$sel:product:Severity' :: Maybe Double
product = Maybe Double
a} :: Severity)

-- | The severity value of the finding. The allowed values are the following.
--
-- -   @INFORMATIONAL@ - No issue was found.
--
-- -   @LOW@ - The issue does not require action on its own.
--
-- -   @MEDIUM@ - The issue must be addressed but not urgently.
--
-- -   @HIGH@ - The issue must be addressed as a priority.
--
-- -   @CRITICAL@ - The issue must be remediated immediately to avoid it
--     escalating.
--
-- If you provide @Normalized@ and do not provide @Label@, then @Label@ is
-- set automatically as follows.
--
-- -   0 - @INFORMATIONAL@
--
-- -   1–39 - @LOW@
--
-- -   40–69 - @MEDIUM@
--
-- -   70–89 - @HIGH@
--
-- -   90–100 - @CRITICAL@
severity_label :: Lens.Lens' Severity (Prelude.Maybe SeverityLabel)
severity_label :: (Maybe SeverityLabel -> f (Maybe SeverityLabel))
-> Severity -> f Severity
severity_label = (Severity -> Maybe SeverityLabel)
-> (Severity -> Maybe SeverityLabel -> Severity)
-> Lens
     Severity Severity (Maybe SeverityLabel) (Maybe SeverityLabel)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Severity' {Maybe SeverityLabel
label :: Maybe SeverityLabel
$sel:label:Severity' :: Severity -> Maybe SeverityLabel
label} -> Maybe SeverityLabel
label) (\s :: Severity
s@Severity' {} Maybe SeverityLabel
a -> Severity
s {$sel:label:Severity' :: Maybe SeverityLabel
label = Maybe SeverityLabel
a} :: Severity)

-- | The native severity from the finding product that generated the finding.
severity_original :: Lens.Lens' Severity (Prelude.Maybe Prelude.Text)
severity_original :: (Maybe Text -> f (Maybe Text)) -> Severity -> f Severity
severity_original = (Severity -> Maybe Text)
-> (Severity -> Maybe Text -> Severity)
-> Lens Severity Severity (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Severity' {Maybe Text
original :: Maybe Text
$sel:original:Severity' :: Severity -> Maybe Text
original} -> Maybe Text
original) (\s :: Severity
s@Severity' {} Maybe Text
a -> Severity
s {$sel:original:Severity' :: Maybe Text
original = Maybe Text
a} :: Severity)

-- | Deprecated. The normalized severity of a finding. This attribute is
-- being deprecated. Instead of providing @Normalized@, provide @Label@.
--
-- If you provide @Label@ and do not provide @Normalized@, then
-- @Normalized@ is set automatically as follows.
--
-- -   @INFORMATIONAL@ - 0
--
-- -   @LOW@ - 1
--
-- -   @MEDIUM@ - 40
--
-- -   @HIGH@ - 70
--
-- -   @CRITICAL@ - 90
severity_normalized :: Lens.Lens' Severity (Prelude.Maybe Prelude.Int)
severity_normalized :: (Maybe Int -> f (Maybe Int)) -> Severity -> f Severity
severity_normalized = (Severity -> Maybe Int)
-> (Severity -> Maybe Int -> Severity)
-> Lens Severity Severity (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Severity' {Maybe Int
normalized :: Maybe Int
$sel:normalized:Severity' :: Severity -> Maybe Int
normalized} -> Maybe Int
normalized) (\s :: Severity
s@Severity' {} Maybe Int
a -> Severity
s {$sel:normalized:Severity' :: Maybe Int
normalized = Maybe Int
a} :: Severity)

instance Core.FromJSON Severity where
  parseJSON :: Value -> Parser Severity
parseJSON =
    String -> (Object -> Parser Severity) -> Value -> Parser Severity
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Severity"
      ( \Object
x ->
          Maybe Double
-> Maybe SeverityLabel -> Maybe Text -> Maybe Int -> Severity
Severity'
            (Maybe Double
 -> Maybe SeverityLabel -> Maybe Text -> Maybe Int -> Severity)
-> Parser (Maybe Double)
-> Parser
     (Maybe SeverityLabel -> Maybe Text -> Maybe Int -> Severity)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Product")
            Parser (Maybe SeverityLabel -> Maybe Text -> Maybe Int -> Severity)
-> Parser (Maybe SeverityLabel)
-> Parser (Maybe Text -> Maybe Int -> Severity)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe SeverityLabel)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Label")
            Parser (Maybe Text -> Maybe Int -> Severity)
-> Parser (Maybe Text) -> Parser (Maybe Int -> Severity)
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
"Original")
            Parser (Maybe Int -> Severity)
-> Parser (Maybe Int) -> Parser Severity
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Normalized")
      )

instance Prelude.Hashable Severity

instance Prelude.NFData Severity

instance Core.ToJSON Severity where
  toJSON :: Severity -> Value
toJSON Severity' {Maybe Double
Maybe Int
Maybe Text
Maybe SeverityLabel
normalized :: Maybe Int
original :: Maybe Text
label :: Maybe SeverityLabel
product :: Maybe Double
$sel:normalized:Severity' :: Severity -> Maybe Int
$sel:original:Severity' :: Severity -> Maybe Text
$sel:label:Severity' :: Severity -> Maybe SeverityLabel
$sel:product:Severity' :: Severity -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Product" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
product,
            (Text
"Label" Text -> SeverityLabel -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SeverityLabel -> Pair) -> Maybe SeverityLabel -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SeverityLabel
label,
            (Text
"Original" 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
original,
            (Text
"Normalized" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
normalized
          ]
      )