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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SecurityHub.Types.AwsApiCallAction
import Amazonka.SecurityHub.Types.DnsRequestAction
import Amazonka.SecurityHub.Types.NetworkConnectionAction
import Amazonka.SecurityHub.Types.PortProbeAction

-- | Provides details about one of the following actions that affects or that
-- was taken on a resource:
--
-- -   A remote IP address issued an Amazon Web Services API call
--
-- -   A DNS request was received
--
-- -   A remote IP address attempted to connect to an EC2 instance
--
-- -   A remote IP address attempted a port probe on an EC2 instance
--
-- /See:/ 'newAction' smart constructor.
data Action = Action'
  { -- | Included if @ActionType@ is @NETWORK_CONNECTION@. Provides details about
    -- the network connection that was detected.
    Action -> Maybe NetworkConnectionAction
networkConnectionAction :: Prelude.Maybe NetworkConnectionAction,
    -- | Included if @ActionType@ is @PORT_PROBE@. Provides details about the
    -- port probe that was detected.
    Action -> Maybe PortProbeAction
portProbeAction :: Prelude.Maybe PortProbeAction,
    -- | The type of action that was detected. The possible action types are:
    --
    -- -   @NETWORK_CONNECTION@
    --
    -- -   @AWS_API_CALL@
    --
    -- -   @DNS_REQUEST@
    --
    -- -   @PORT_PROBE@
    Action -> Maybe Text
actionType :: Prelude.Maybe Prelude.Text,
    -- | Included if @ActionType@ is @DNS_REQUEST@. Provides details about the
    -- DNS request that was detected.
    Action -> Maybe DnsRequestAction
dnsRequestAction :: Prelude.Maybe DnsRequestAction,
    -- | Included if @ActionType@ is @AWS_API_CALL@. Provides details about the
    -- API call that was detected.
    Action -> Maybe AwsApiCallAction
awsApiCallAction :: Prelude.Maybe AwsApiCallAction
  }
  deriving (Action -> Action -> Bool
(Action -> Action -> Bool)
-> (Action -> Action -> Bool) -> Eq Action
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Action -> Action -> Bool
$c/= :: Action -> Action -> Bool
== :: Action -> Action -> Bool
$c== :: Action -> Action -> Bool
Prelude.Eq, ReadPrec [Action]
ReadPrec Action
Int -> ReadS Action
ReadS [Action]
(Int -> ReadS Action)
-> ReadS [Action]
-> ReadPrec Action
-> ReadPrec [Action]
-> Read Action
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Action]
$creadListPrec :: ReadPrec [Action]
readPrec :: ReadPrec Action
$creadPrec :: ReadPrec Action
readList :: ReadS [Action]
$creadList :: ReadS [Action]
readsPrec :: Int -> ReadS Action
$creadsPrec :: Int -> ReadS Action
Prelude.Read, Int -> Action -> ShowS
[Action] -> ShowS
Action -> String
(Int -> Action -> ShowS)
-> (Action -> String) -> ([Action] -> ShowS) -> Show Action
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Action] -> ShowS
$cshowList :: [Action] -> ShowS
show :: Action -> String
$cshow :: Action -> String
showsPrec :: Int -> Action -> ShowS
$cshowsPrec :: Int -> Action -> ShowS
Prelude.Show, (forall x. Action -> Rep Action x)
-> (forall x. Rep Action x -> Action) -> Generic Action
forall x. Rep Action x -> Action
forall x. Action -> Rep Action x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Action x -> Action
$cfrom :: forall x. Action -> Rep Action x
Prelude.Generic)

-- |
-- Create a value of 'Action' 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:
--
-- 'networkConnectionAction', 'action_networkConnectionAction' - Included if @ActionType@ is @NETWORK_CONNECTION@. Provides details about
-- the network connection that was detected.
--
-- 'portProbeAction', 'action_portProbeAction' - Included if @ActionType@ is @PORT_PROBE@. Provides details about the
-- port probe that was detected.
--
-- 'actionType', 'action_actionType' - The type of action that was detected. The possible action types are:
--
-- -   @NETWORK_CONNECTION@
--
-- -   @AWS_API_CALL@
--
-- -   @DNS_REQUEST@
--
-- -   @PORT_PROBE@
--
-- 'dnsRequestAction', 'action_dnsRequestAction' - Included if @ActionType@ is @DNS_REQUEST@. Provides details about the
-- DNS request that was detected.
--
-- 'awsApiCallAction', 'action_awsApiCallAction' - Included if @ActionType@ is @AWS_API_CALL@. Provides details about the
-- API call that was detected.
newAction ::
  Action
newAction :: Action
newAction =
  Action' :: Maybe NetworkConnectionAction
-> Maybe PortProbeAction
-> Maybe Text
-> Maybe DnsRequestAction
-> Maybe AwsApiCallAction
-> Action
Action'
    { $sel:networkConnectionAction:Action' :: Maybe NetworkConnectionAction
networkConnectionAction = Maybe NetworkConnectionAction
forall a. Maybe a
Prelude.Nothing,
      $sel:portProbeAction:Action' :: Maybe PortProbeAction
portProbeAction = Maybe PortProbeAction
forall a. Maybe a
Prelude.Nothing,
      $sel:actionType:Action' :: Maybe Text
actionType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:dnsRequestAction:Action' :: Maybe DnsRequestAction
dnsRequestAction = Maybe DnsRequestAction
forall a. Maybe a
Prelude.Nothing,
      $sel:awsApiCallAction:Action' :: Maybe AwsApiCallAction
awsApiCallAction = Maybe AwsApiCallAction
forall a. Maybe a
Prelude.Nothing
    }

-- | Included if @ActionType@ is @NETWORK_CONNECTION@. Provides details about
-- the network connection that was detected.
action_networkConnectionAction :: Lens.Lens' Action (Prelude.Maybe NetworkConnectionAction)
action_networkConnectionAction :: (Maybe NetworkConnectionAction
 -> f (Maybe NetworkConnectionAction))
-> Action -> f Action
action_networkConnectionAction = (Action -> Maybe NetworkConnectionAction)
-> (Action -> Maybe NetworkConnectionAction -> Action)
-> Lens
     Action
     Action
     (Maybe NetworkConnectionAction)
     (Maybe NetworkConnectionAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe NetworkConnectionAction
networkConnectionAction :: Maybe NetworkConnectionAction
$sel:networkConnectionAction:Action' :: Action -> Maybe NetworkConnectionAction
networkConnectionAction} -> Maybe NetworkConnectionAction
networkConnectionAction) (\s :: Action
s@Action' {} Maybe NetworkConnectionAction
a -> Action
s {$sel:networkConnectionAction:Action' :: Maybe NetworkConnectionAction
networkConnectionAction = Maybe NetworkConnectionAction
a} :: Action)

-- | Included if @ActionType@ is @PORT_PROBE@. Provides details about the
-- port probe that was detected.
action_portProbeAction :: Lens.Lens' Action (Prelude.Maybe PortProbeAction)
action_portProbeAction :: (Maybe PortProbeAction -> f (Maybe PortProbeAction))
-> Action -> f Action
action_portProbeAction = (Action -> Maybe PortProbeAction)
-> (Action -> Maybe PortProbeAction -> Action)
-> Lens
     Action Action (Maybe PortProbeAction) (Maybe PortProbeAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe PortProbeAction
portProbeAction :: Maybe PortProbeAction
$sel:portProbeAction:Action' :: Action -> Maybe PortProbeAction
portProbeAction} -> Maybe PortProbeAction
portProbeAction) (\s :: Action
s@Action' {} Maybe PortProbeAction
a -> Action
s {$sel:portProbeAction:Action' :: Maybe PortProbeAction
portProbeAction = Maybe PortProbeAction
a} :: Action)

-- | The type of action that was detected. The possible action types are:
--
-- -   @NETWORK_CONNECTION@
--
-- -   @AWS_API_CALL@
--
-- -   @DNS_REQUEST@
--
-- -   @PORT_PROBE@
action_actionType :: Lens.Lens' Action (Prelude.Maybe Prelude.Text)
action_actionType :: (Maybe Text -> f (Maybe Text)) -> Action -> f Action
action_actionType = (Action -> Maybe Text)
-> (Action -> Maybe Text -> Action)
-> Lens Action Action (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe Text
actionType :: Maybe Text
$sel:actionType:Action' :: Action -> Maybe Text
actionType} -> Maybe Text
actionType) (\s :: Action
s@Action' {} Maybe Text
a -> Action
s {$sel:actionType:Action' :: Maybe Text
actionType = Maybe Text
a} :: Action)

-- | Included if @ActionType@ is @DNS_REQUEST@. Provides details about the
-- DNS request that was detected.
action_dnsRequestAction :: Lens.Lens' Action (Prelude.Maybe DnsRequestAction)
action_dnsRequestAction :: (Maybe DnsRequestAction -> f (Maybe DnsRequestAction))
-> Action -> f Action
action_dnsRequestAction = (Action -> Maybe DnsRequestAction)
-> (Action -> Maybe DnsRequestAction -> Action)
-> Lens
     Action Action (Maybe DnsRequestAction) (Maybe DnsRequestAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe DnsRequestAction
dnsRequestAction :: Maybe DnsRequestAction
$sel:dnsRequestAction:Action' :: Action -> Maybe DnsRequestAction
dnsRequestAction} -> Maybe DnsRequestAction
dnsRequestAction) (\s :: Action
s@Action' {} Maybe DnsRequestAction
a -> Action
s {$sel:dnsRequestAction:Action' :: Maybe DnsRequestAction
dnsRequestAction = Maybe DnsRequestAction
a} :: Action)

-- | Included if @ActionType@ is @AWS_API_CALL@. Provides details about the
-- API call that was detected.
action_awsApiCallAction :: Lens.Lens' Action (Prelude.Maybe AwsApiCallAction)
action_awsApiCallAction :: (Maybe AwsApiCallAction -> f (Maybe AwsApiCallAction))
-> Action -> f Action
action_awsApiCallAction = (Action -> Maybe AwsApiCallAction)
-> (Action -> Maybe AwsApiCallAction -> Action)
-> Lens
     Action Action (Maybe AwsApiCallAction) (Maybe AwsApiCallAction)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Action' {Maybe AwsApiCallAction
awsApiCallAction :: Maybe AwsApiCallAction
$sel:awsApiCallAction:Action' :: Action -> Maybe AwsApiCallAction
awsApiCallAction} -> Maybe AwsApiCallAction
awsApiCallAction) (\s :: Action
s@Action' {} Maybe AwsApiCallAction
a -> Action
s {$sel:awsApiCallAction:Action' :: Maybe AwsApiCallAction
awsApiCallAction = Maybe AwsApiCallAction
a} :: Action)

instance Core.FromJSON Action where
  parseJSON :: Value -> Parser Action
parseJSON =
    String -> (Object -> Parser Action) -> Value -> Parser Action
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Action"
      ( \Object
x ->
          Maybe NetworkConnectionAction
-> Maybe PortProbeAction
-> Maybe Text
-> Maybe DnsRequestAction
-> Maybe AwsApiCallAction
-> Action
Action'
            (Maybe NetworkConnectionAction
 -> Maybe PortProbeAction
 -> Maybe Text
 -> Maybe DnsRequestAction
 -> Maybe AwsApiCallAction
 -> Action)
-> Parser (Maybe NetworkConnectionAction)
-> Parser
     (Maybe PortProbeAction
      -> Maybe Text
      -> Maybe DnsRequestAction
      -> Maybe AwsApiCallAction
      -> Action)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe NetworkConnectionAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"NetworkConnectionAction")
            Parser
  (Maybe PortProbeAction
   -> Maybe Text
   -> Maybe DnsRequestAction
   -> Maybe AwsApiCallAction
   -> Action)
-> Parser (Maybe PortProbeAction)
-> Parser
     (Maybe Text
      -> Maybe DnsRequestAction -> Maybe AwsApiCallAction -> Action)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe PortProbeAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PortProbeAction")
            Parser
  (Maybe Text
   -> Maybe DnsRequestAction -> Maybe AwsApiCallAction -> Action)
-> Parser (Maybe Text)
-> Parser
     (Maybe DnsRequestAction -> Maybe AwsApiCallAction -> Action)
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
"ActionType")
            Parser (Maybe DnsRequestAction -> Maybe AwsApiCallAction -> Action)
-> Parser (Maybe DnsRequestAction)
-> Parser (Maybe AwsApiCallAction -> Action)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe DnsRequestAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DnsRequestAction")
            Parser (Maybe AwsApiCallAction -> Action)
-> Parser (Maybe AwsApiCallAction) -> Parser Action
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AwsApiCallAction)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AwsApiCallAction")
      )

instance Prelude.Hashable Action

instance Prelude.NFData Action

instance Core.ToJSON Action where
  toJSON :: Action -> Value
toJSON Action' {Maybe Text
Maybe DnsRequestAction
Maybe AwsApiCallAction
Maybe NetworkConnectionAction
Maybe PortProbeAction
awsApiCallAction :: Maybe AwsApiCallAction
dnsRequestAction :: Maybe DnsRequestAction
actionType :: Maybe Text
portProbeAction :: Maybe PortProbeAction
networkConnectionAction :: Maybe NetworkConnectionAction
$sel:awsApiCallAction:Action' :: Action -> Maybe AwsApiCallAction
$sel:dnsRequestAction:Action' :: Action -> Maybe DnsRequestAction
$sel:actionType:Action' :: Action -> Maybe Text
$sel:portProbeAction:Action' :: Action -> Maybe PortProbeAction
$sel:networkConnectionAction:Action' :: Action -> Maybe NetworkConnectionAction
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"NetworkConnectionAction" Text -> NetworkConnectionAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (NetworkConnectionAction -> Pair)
-> Maybe NetworkConnectionAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe NetworkConnectionAction
networkConnectionAction,
            (Text
"PortProbeAction" Text -> PortProbeAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (PortProbeAction -> Pair) -> Maybe PortProbeAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe PortProbeAction
portProbeAction,
            (Text
"ActionType" 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
actionType,
            (Text
"DnsRequestAction" Text -> DnsRequestAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (DnsRequestAction -> Pair) -> Maybe DnsRequestAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DnsRequestAction
dnsRequestAction,
            (Text
"AwsApiCallAction" Text -> AwsApiCallAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AwsApiCallAction -> Pair) -> Maybe AwsApiCallAction -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AwsApiCallAction
awsApiCallAction
          ]
      )