{-# 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.AppMesh.Types.EgressFilter
-- 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.AppMesh.Types.EgressFilter where

import Amazonka.AppMesh.Types.EgressFilterType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that represents the egress filter rules for a service mesh.
--
-- /See:/ 'newEgressFilter' smart constructor.
data EgressFilter = EgressFilter'
  { -- | The egress filter type. By default, the type is @DROP_ALL@, which allows
    -- egress only from virtual nodes to other defined resources in the service
    -- mesh (and any traffic to @*.amazonaws.com@ for Amazon Web Services API
    -- calls). You can set the egress filter type to @ALLOW_ALL@ to allow
    -- egress to any endpoint inside or outside of the service mesh.
    EgressFilter -> EgressFilterType
type' :: EgressFilterType
  }
  deriving (EgressFilter -> EgressFilter -> Bool
(EgressFilter -> EgressFilter -> Bool)
-> (EgressFilter -> EgressFilter -> Bool) -> Eq EgressFilter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EgressFilter -> EgressFilter -> Bool
$c/= :: EgressFilter -> EgressFilter -> Bool
== :: EgressFilter -> EgressFilter -> Bool
$c== :: EgressFilter -> EgressFilter -> Bool
Prelude.Eq, ReadPrec [EgressFilter]
ReadPrec EgressFilter
Int -> ReadS EgressFilter
ReadS [EgressFilter]
(Int -> ReadS EgressFilter)
-> ReadS [EgressFilter]
-> ReadPrec EgressFilter
-> ReadPrec [EgressFilter]
-> Read EgressFilter
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EgressFilter]
$creadListPrec :: ReadPrec [EgressFilter]
readPrec :: ReadPrec EgressFilter
$creadPrec :: ReadPrec EgressFilter
readList :: ReadS [EgressFilter]
$creadList :: ReadS [EgressFilter]
readsPrec :: Int -> ReadS EgressFilter
$creadsPrec :: Int -> ReadS EgressFilter
Prelude.Read, Int -> EgressFilter -> ShowS
[EgressFilter] -> ShowS
EgressFilter -> String
(Int -> EgressFilter -> ShowS)
-> (EgressFilter -> String)
-> ([EgressFilter] -> ShowS)
-> Show EgressFilter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EgressFilter] -> ShowS
$cshowList :: [EgressFilter] -> ShowS
show :: EgressFilter -> String
$cshow :: EgressFilter -> String
showsPrec :: Int -> EgressFilter -> ShowS
$cshowsPrec :: Int -> EgressFilter -> ShowS
Prelude.Show, (forall x. EgressFilter -> Rep EgressFilter x)
-> (forall x. Rep EgressFilter x -> EgressFilter)
-> Generic EgressFilter
forall x. Rep EgressFilter x -> EgressFilter
forall x. EgressFilter -> Rep EgressFilter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep EgressFilter x -> EgressFilter
$cfrom :: forall x. EgressFilter -> Rep EgressFilter x
Prelude.Generic)

-- |
-- Create a value of 'EgressFilter' 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:
--
-- 'type'', 'egressFilter_type' - The egress filter type. By default, the type is @DROP_ALL@, which allows
-- egress only from virtual nodes to other defined resources in the service
-- mesh (and any traffic to @*.amazonaws.com@ for Amazon Web Services API
-- calls). You can set the egress filter type to @ALLOW_ALL@ to allow
-- egress to any endpoint inside or outside of the service mesh.
newEgressFilter ::
  -- | 'type''
  EgressFilterType ->
  EgressFilter
newEgressFilter :: EgressFilterType -> EgressFilter
newEgressFilter EgressFilterType
pType_ =
  EgressFilter' :: EgressFilterType -> EgressFilter
EgressFilter' {$sel:type':EgressFilter' :: EgressFilterType
type' = EgressFilterType
pType_}

-- | The egress filter type. By default, the type is @DROP_ALL@, which allows
-- egress only from virtual nodes to other defined resources in the service
-- mesh (and any traffic to @*.amazonaws.com@ for Amazon Web Services API
-- calls). You can set the egress filter type to @ALLOW_ALL@ to allow
-- egress to any endpoint inside or outside of the service mesh.
egressFilter_type :: Lens.Lens' EgressFilter EgressFilterType
egressFilter_type :: (EgressFilterType -> f EgressFilterType)
-> EgressFilter -> f EgressFilter
egressFilter_type = (EgressFilter -> EgressFilterType)
-> (EgressFilter -> EgressFilterType -> EgressFilter)
-> Lens EgressFilter EgressFilter EgressFilterType EgressFilterType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EgressFilter' {EgressFilterType
type' :: EgressFilterType
$sel:type':EgressFilter' :: EgressFilter -> EgressFilterType
type'} -> EgressFilterType
type') (\s :: EgressFilter
s@EgressFilter' {} EgressFilterType
a -> EgressFilter
s {$sel:type':EgressFilter' :: EgressFilterType
type' = EgressFilterType
a} :: EgressFilter)

instance Core.FromJSON EgressFilter where
  parseJSON :: Value -> Parser EgressFilter
parseJSON =
    String
-> (Object -> Parser EgressFilter) -> Value -> Parser EgressFilter
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"EgressFilter"
      (\Object
x -> EgressFilterType -> EgressFilter
EgressFilter' (EgressFilterType -> EgressFilter)
-> Parser EgressFilterType -> Parser EgressFilter
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser EgressFilterType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type"))

instance Prelude.Hashable EgressFilter

instance Prelude.NFData EgressFilter

instance Core.ToJSON EgressFilter where
  toJSON :: EgressFilter -> Value
toJSON EgressFilter' {EgressFilterType
type' :: EgressFilterType
$sel:type':EgressFilter' :: EgressFilter -> EgressFilterType
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> EgressFilterType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= EgressFilterType
type')]
      )