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

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

-- | Information about a network path component.
--
-- /See:/ 'newNetworkPathComponent' smart constructor.
data NetworkPathComponent = NetworkPathComponent'
  { -- | The type of component.
    NetworkPathComponent -> Maybe Text
componentType :: Prelude.Maybe Prelude.Text,
    -- | Information about the component that comes before the current node in
    -- the network path.
    NetworkPathComponent -> Maybe NetworkHeader
ingress :: Prelude.Maybe NetworkHeader,
    -- | The identifier of a component in the network path.
    NetworkPathComponent -> Maybe Text
componentId :: Prelude.Maybe Prelude.Text,
    -- | Information about the component that comes after the current component
    -- in the network path.
    NetworkPathComponent -> Maybe NetworkHeader
egress :: Prelude.Maybe NetworkHeader
  }
  deriving (NetworkPathComponent -> NetworkPathComponent -> Bool
(NetworkPathComponent -> NetworkPathComponent -> Bool)
-> (NetworkPathComponent -> NetworkPathComponent -> Bool)
-> Eq NetworkPathComponent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NetworkPathComponent -> NetworkPathComponent -> Bool
$c/= :: NetworkPathComponent -> NetworkPathComponent -> Bool
== :: NetworkPathComponent -> NetworkPathComponent -> Bool
$c== :: NetworkPathComponent -> NetworkPathComponent -> Bool
Prelude.Eq, ReadPrec [NetworkPathComponent]
ReadPrec NetworkPathComponent
Int -> ReadS NetworkPathComponent
ReadS [NetworkPathComponent]
(Int -> ReadS NetworkPathComponent)
-> ReadS [NetworkPathComponent]
-> ReadPrec NetworkPathComponent
-> ReadPrec [NetworkPathComponent]
-> Read NetworkPathComponent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NetworkPathComponent]
$creadListPrec :: ReadPrec [NetworkPathComponent]
readPrec :: ReadPrec NetworkPathComponent
$creadPrec :: ReadPrec NetworkPathComponent
readList :: ReadS [NetworkPathComponent]
$creadList :: ReadS [NetworkPathComponent]
readsPrec :: Int -> ReadS NetworkPathComponent
$creadsPrec :: Int -> ReadS NetworkPathComponent
Prelude.Read, Int -> NetworkPathComponent -> ShowS
[NetworkPathComponent] -> ShowS
NetworkPathComponent -> String
(Int -> NetworkPathComponent -> ShowS)
-> (NetworkPathComponent -> String)
-> ([NetworkPathComponent] -> ShowS)
-> Show NetworkPathComponent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NetworkPathComponent] -> ShowS
$cshowList :: [NetworkPathComponent] -> ShowS
show :: NetworkPathComponent -> String
$cshow :: NetworkPathComponent -> String
showsPrec :: Int -> NetworkPathComponent -> ShowS
$cshowsPrec :: Int -> NetworkPathComponent -> ShowS
Prelude.Show, (forall x. NetworkPathComponent -> Rep NetworkPathComponent x)
-> (forall x. Rep NetworkPathComponent x -> NetworkPathComponent)
-> Generic NetworkPathComponent
forall x. Rep NetworkPathComponent x -> NetworkPathComponent
forall x. NetworkPathComponent -> Rep NetworkPathComponent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NetworkPathComponent x -> NetworkPathComponent
$cfrom :: forall x. NetworkPathComponent -> Rep NetworkPathComponent x
Prelude.Generic)

-- |
-- Create a value of 'NetworkPathComponent' 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:
--
-- 'componentType', 'networkPathComponent_componentType' - The type of component.
--
-- 'ingress', 'networkPathComponent_ingress' - Information about the component that comes before the current node in
-- the network path.
--
-- 'componentId', 'networkPathComponent_componentId' - The identifier of a component in the network path.
--
-- 'egress', 'networkPathComponent_egress' - Information about the component that comes after the current component
-- in the network path.
newNetworkPathComponent ::
  NetworkPathComponent
newNetworkPathComponent :: NetworkPathComponent
newNetworkPathComponent =
  NetworkPathComponent' :: Maybe Text
-> Maybe NetworkHeader
-> Maybe Text
-> Maybe NetworkHeader
-> NetworkPathComponent
NetworkPathComponent'
    { $sel:componentType:NetworkPathComponent' :: Maybe Text
componentType =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:ingress:NetworkPathComponent' :: Maybe NetworkHeader
ingress = Maybe NetworkHeader
forall a. Maybe a
Prelude.Nothing,
      $sel:componentId:NetworkPathComponent' :: Maybe Text
componentId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:egress:NetworkPathComponent' :: Maybe NetworkHeader
egress = Maybe NetworkHeader
forall a. Maybe a
Prelude.Nothing
    }

-- | The type of component.
networkPathComponent_componentType :: Lens.Lens' NetworkPathComponent (Prelude.Maybe Prelude.Text)
networkPathComponent_componentType :: (Maybe Text -> f (Maybe Text))
-> NetworkPathComponent -> f NetworkPathComponent
networkPathComponent_componentType = (NetworkPathComponent -> Maybe Text)
-> (NetworkPathComponent -> Maybe Text -> NetworkPathComponent)
-> Lens
     NetworkPathComponent NetworkPathComponent (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkPathComponent' {Maybe Text
componentType :: Maybe Text
$sel:componentType:NetworkPathComponent' :: NetworkPathComponent -> Maybe Text
componentType} -> Maybe Text
componentType) (\s :: NetworkPathComponent
s@NetworkPathComponent' {} Maybe Text
a -> NetworkPathComponent
s {$sel:componentType:NetworkPathComponent' :: Maybe Text
componentType = Maybe Text
a} :: NetworkPathComponent)

-- | Information about the component that comes before the current node in
-- the network path.
networkPathComponent_ingress :: Lens.Lens' NetworkPathComponent (Prelude.Maybe NetworkHeader)
networkPathComponent_ingress :: (Maybe NetworkHeader -> f (Maybe NetworkHeader))
-> NetworkPathComponent -> f NetworkPathComponent
networkPathComponent_ingress = (NetworkPathComponent -> Maybe NetworkHeader)
-> (NetworkPathComponent
    -> Maybe NetworkHeader -> NetworkPathComponent)
-> Lens
     NetworkPathComponent
     NetworkPathComponent
     (Maybe NetworkHeader)
     (Maybe NetworkHeader)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkPathComponent' {Maybe NetworkHeader
ingress :: Maybe NetworkHeader
$sel:ingress:NetworkPathComponent' :: NetworkPathComponent -> Maybe NetworkHeader
ingress} -> Maybe NetworkHeader
ingress) (\s :: NetworkPathComponent
s@NetworkPathComponent' {} Maybe NetworkHeader
a -> NetworkPathComponent
s {$sel:ingress:NetworkPathComponent' :: Maybe NetworkHeader
ingress = Maybe NetworkHeader
a} :: NetworkPathComponent)

-- | The identifier of a component in the network path.
networkPathComponent_componentId :: Lens.Lens' NetworkPathComponent (Prelude.Maybe Prelude.Text)
networkPathComponent_componentId :: (Maybe Text -> f (Maybe Text))
-> NetworkPathComponent -> f NetworkPathComponent
networkPathComponent_componentId = (NetworkPathComponent -> Maybe Text)
-> (NetworkPathComponent -> Maybe Text -> NetworkPathComponent)
-> Lens
     NetworkPathComponent NetworkPathComponent (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkPathComponent' {Maybe Text
componentId :: Maybe Text
$sel:componentId:NetworkPathComponent' :: NetworkPathComponent -> Maybe Text
componentId} -> Maybe Text
componentId) (\s :: NetworkPathComponent
s@NetworkPathComponent' {} Maybe Text
a -> NetworkPathComponent
s {$sel:componentId:NetworkPathComponent' :: Maybe Text
componentId = Maybe Text
a} :: NetworkPathComponent)

-- | Information about the component that comes after the current component
-- in the network path.
networkPathComponent_egress :: Lens.Lens' NetworkPathComponent (Prelude.Maybe NetworkHeader)
networkPathComponent_egress :: (Maybe NetworkHeader -> f (Maybe NetworkHeader))
-> NetworkPathComponent -> f NetworkPathComponent
networkPathComponent_egress = (NetworkPathComponent -> Maybe NetworkHeader)
-> (NetworkPathComponent
    -> Maybe NetworkHeader -> NetworkPathComponent)
-> Lens
     NetworkPathComponent
     NetworkPathComponent
     (Maybe NetworkHeader)
     (Maybe NetworkHeader)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\NetworkPathComponent' {Maybe NetworkHeader
egress :: Maybe NetworkHeader
$sel:egress:NetworkPathComponent' :: NetworkPathComponent -> Maybe NetworkHeader
egress} -> Maybe NetworkHeader
egress) (\s :: NetworkPathComponent
s@NetworkPathComponent' {} Maybe NetworkHeader
a -> NetworkPathComponent
s {$sel:egress:NetworkPathComponent' :: Maybe NetworkHeader
egress = Maybe NetworkHeader
a} :: NetworkPathComponent)

instance Core.FromJSON NetworkPathComponent where
  parseJSON :: Value -> Parser NetworkPathComponent
parseJSON =
    String
-> (Object -> Parser NetworkPathComponent)
-> Value
-> Parser NetworkPathComponent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"NetworkPathComponent"
      ( \Object
x ->
          Maybe Text
-> Maybe NetworkHeader
-> Maybe Text
-> Maybe NetworkHeader
-> NetworkPathComponent
NetworkPathComponent'
            (Maybe Text
 -> Maybe NetworkHeader
 -> Maybe Text
 -> Maybe NetworkHeader
 -> NetworkPathComponent)
-> Parser (Maybe Text)
-> Parser
     (Maybe NetworkHeader
      -> Maybe Text -> Maybe NetworkHeader -> NetworkPathComponent)
forall (f :: * -> *) a b. Functor 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
"ComponentType")
            Parser
  (Maybe NetworkHeader
   -> Maybe Text -> Maybe NetworkHeader -> NetworkPathComponent)
-> Parser (Maybe NetworkHeader)
-> Parser
     (Maybe Text -> Maybe NetworkHeader -> NetworkPathComponent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe NetworkHeader)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Ingress")
            Parser (Maybe Text -> Maybe NetworkHeader -> NetworkPathComponent)
-> Parser (Maybe Text)
-> Parser (Maybe NetworkHeader -> NetworkPathComponent)
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
"ComponentId")
            Parser (Maybe NetworkHeader -> NetworkPathComponent)
-> Parser (Maybe NetworkHeader) -> Parser NetworkPathComponent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe NetworkHeader)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Egress")
      )

instance Prelude.Hashable NetworkPathComponent

instance Prelude.NFData NetworkPathComponent

instance Core.ToJSON NetworkPathComponent where
  toJSON :: NetworkPathComponent -> Value
toJSON NetworkPathComponent' {Maybe Text
Maybe NetworkHeader
egress :: Maybe NetworkHeader
componentId :: Maybe Text
ingress :: Maybe NetworkHeader
componentType :: Maybe Text
$sel:egress:NetworkPathComponent' :: NetworkPathComponent -> Maybe NetworkHeader
$sel:componentId:NetworkPathComponent' :: NetworkPathComponent -> Maybe Text
$sel:ingress:NetworkPathComponent' :: NetworkPathComponent -> Maybe NetworkHeader
$sel:componentType:NetworkPathComponent' :: NetworkPathComponent -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ComponentType" 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
componentType,
            (Text
"Ingress" Text -> NetworkHeader -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NetworkHeader -> Pair) -> Maybe NetworkHeader -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe NetworkHeader
ingress,
            (Text
"ComponentId" 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
componentId,
            (Text
"Egress" Text -> NetworkHeader -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NetworkHeader -> Pair) -> Maybe NetworkHeader -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe NetworkHeader
egress
          ]
      )