{-# 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.ELBV2.Types.Rule
-- 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.ELBV2.Types.Rule where

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types.Action
import Amazonka.ELBV2.Types.RuleCondition
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a rule.
--
-- /See:/ 'newRule' smart constructor.
data Rule = Rule'
  { -- | The priority.
    Rule -> Maybe Text
priority :: Prelude.Maybe Prelude.Text,
    -- | The actions. Each rule must include exactly one of the following types
    -- of actions: @forward@, @redirect@, or @fixed-response@, and it must be
    -- the last action to be performed.
    Rule -> Maybe [Action]
actions :: Prelude.Maybe [Action],
    -- | The conditions. Each rule can include zero or one of the following
    -- conditions: @http-request-method@, @host-header@, @path-pattern@, and
    -- @source-ip@, and zero or more of the following conditions: @http-header@
    -- and @query-string@.
    Rule -> Maybe [RuleCondition]
conditions :: Prelude.Maybe [RuleCondition],
    -- | The Amazon Resource Name (ARN) of the rule.
    Rule -> Maybe Text
ruleArn :: Prelude.Maybe Prelude.Text,
    -- | Indicates whether this is the default rule.
    Rule -> Maybe Bool
isDefault :: Prelude.Maybe Prelude.Bool
  }
  deriving (Rule -> Rule -> Bool
(Rule -> Rule -> Bool) -> (Rule -> Rule -> Bool) -> Eq Rule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rule -> Rule -> Bool
$c/= :: Rule -> Rule -> Bool
== :: Rule -> Rule -> Bool
$c== :: Rule -> Rule -> Bool
Prelude.Eq, ReadPrec [Rule]
ReadPrec Rule
Int -> ReadS Rule
ReadS [Rule]
(Int -> ReadS Rule)
-> ReadS [Rule] -> ReadPrec Rule -> ReadPrec [Rule] -> Read Rule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Rule]
$creadListPrec :: ReadPrec [Rule]
readPrec :: ReadPrec Rule
$creadPrec :: ReadPrec Rule
readList :: ReadS [Rule]
$creadList :: ReadS [Rule]
readsPrec :: Int -> ReadS Rule
$creadsPrec :: Int -> ReadS Rule
Prelude.Read, Int -> Rule -> ShowS
[Rule] -> ShowS
Rule -> String
(Int -> Rule -> ShowS)
-> (Rule -> String) -> ([Rule] -> ShowS) -> Show Rule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rule] -> ShowS
$cshowList :: [Rule] -> ShowS
show :: Rule -> String
$cshow :: Rule -> String
showsPrec :: Int -> Rule -> ShowS
$cshowsPrec :: Int -> Rule -> ShowS
Prelude.Show, (forall x. Rule -> Rep Rule x)
-> (forall x. Rep Rule x -> Rule) -> Generic Rule
forall x. Rep Rule x -> Rule
forall x. Rule -> Rep Rule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Rule x -> Rule
$cfrom :: forall x. Rule -> Rep Rule x
Prelude.Generic)

-- |
-- Create a value of 'Rule' 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:
--
-- 'priority', 'rule_priority' - The priority.
--
-- 'actions', 'rule_actions' - The actions. Each rule must include exactly one of the following types
-- of actions: @forward@, @redirect@, or @fixed-response@, and it must be
-- the last action to be performed.
--
-- 'conditions', 'rule_conditions' - The conditions. Each rule can include zero or one of the following
-- conditions: @http-request-method@, @host-header@, @path-pattern@, and
-- @source-ip@, and zero or more of the following conditions: @http-header@
-- and @query-string@.
--
-- 'ruleArn', 'rule_ruleArn' - The Amazon Resource Name (ARN) of the rule.
--
-- 'isDefault', 'rule_isDefault' - Indicates whether this is the default rule.
newRule ::
  Rule
newRule :: Rule
newRule =
  Rule' :: Maybe Text
-> Maybe [Action]
-> Maybe [RuleCondition]
-> Maybe Text
-> Maybe Bool
-> Rule
Rule'
    { $sel:priority:Rule' :: Maybe Text
priority = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:actions:Rule' :: Maybe [Action]
actions = Maybe [Action]
forall a. Maybe a
Prelude.Nothing,
      $sel:conditions:Rule' :: Maybe [RuleCondition]
conditions = Maybe [RuleCondition]
forall a. Maybe a
Prelude.Nothing,
      $sel:ruleArn:Rule' :: Maybe Text
ruleArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:isDefault:Rule' :: Maybe Bool
isDefault = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | The priority.
rule_priority :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_priority :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_priority = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
priority :: Maybe Text
$sel:priority:Rule' :: Rule -> Maybe Text
priority} -> Maybe Text
priority) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:priority:Rule' :: Maybe Text
priority = Maybe Text
a} :: Rule)

-- | The actions. Each rule must include exactly one of the following types
-- of actions: @forward@, @redirect@, or @fixed-response@, and it must be
-- the last action to be performed.
rule_actions :: Lens.Lens' Rule (Prelude.Maybe [Action])
rule_actions :: (Maybe [Action] -> f (Maybe [Action])) -> Rule -> f Rule
rule_actions = (Rule -> Maybe [Action])
-> (Rule -> Maybe [Action] -> Rule)
-> Lens Rule Rule (Maybe [Action]) (Maybe [Action])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe [Action]
actions :: Maybe [Action]
$sel:actions:Rule' :: Rule -> Maybe [Action]
actions} -> Maybe [Action]
actions) (\s :: Rule
s@Rule' {} Maybe [Action]
a -> Rule
s {$sel:actions:Rule' :: Maybe [Action]
actions = Maybe [Action]
a} :: Rule) ((Maybe [Action] -> f (Maybe [Action])) -> Rule -> f Rule)
-> ((Maybe [Action] -> f (Maybe [Action]))
    -> Maybe [Action] -> f (Maybe [Action]))
-> (Maybe [Action] -> f (Maybe [Action]))
-> Rule
-> f Rule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Action] [Action] [Action] [Action]
-> Iso
     (Maybe [Action]) (Maybe [Action]) (Maybe [Action]) (Maybe [Action])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Action] [Action] [Action] [Action]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The conditions. Each rule can include zero or one of the following
-- conditions: @http-request-method@, @host-header@, @path-pattern@, and
-- @source-ip@, and zero or more of the following conditions: @http-header@
-- and @query-string@.
rule_conditions :: Lens.Lens' Rule (Prelude.Maybe [RuleCondition])
rule_conditions :: (Maybe [RuleCondition] -> f (Maybe [RuleCondition]))
-> Rule -> f Rule
rule_conditions = (Rule -> Maybe [RuleCondition])
-> (Rule -> Maybe [RuleCondition] -> Rule)
-> Lens Rule Rule (Maybe [RuleCondition]) (Maybe [RuleCondition])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe [RuleCondition]
conditions :: Maybe [RuleCondition]
$sel:conditions:Rule' :: Rule -> Maybe [RuleCondition]
conditions} -> Maybe [RuleCondition]
conditions) (\s :: Rule
s@Rule' {} Maybe [RuleCondition]
a -> Rule
s {$sel:conditions:Rule' :: Maybe [RuleCondition]
conditions = Maybe [RuleCondition]
a} :: Rule) ((Maybe [RuleCondition] -> f (Maybe [RuleCondition]))
 -> Rule -> f Rule)
-> ((Maybe [RuleCondition] -> f (Maybe [RuleCondition]))
    -> Maybe [RuleCondition] -> f (Maybe [RuleCondition]))
-> (Maybe [RuleCondition] -> f (Maybe [RuleCondition]))
-> Rule
-> f Rule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [RuleCondition] [RuleCondition] [RuleCondition] [RuleCondition]
-> Iso
     (Maybe [RuleCondition])
     (Maybe [RuleCondition])
     (Maybe [RuleCondition])
     (Maybe [RuleCondition])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [RuleCondition] [RuleCondition] [RuleCondition] [RuleCondition]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the rule.
rule_ruleArn :: Lens.Lens' Rule (Prelude.Maybe Prelude.Text)
rule_ruleArn :: (Maybe Text -> f (Maybe Text)) -> Rule -> f Rule
rule_ruleArn = (Rule -> Maybe Text)
-> (Rule -> Maybe Text -> Rule)
-> Lens Rule Rule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Text
ruleArn :: Maybe Text
$sel:ruleArn:Rule' :: Rule -> Maybe Text
ruleArn} -> Maybe Text
ruleArn) (\s :: Rule
s@Rule' {} Maybe Text
a -> Rule
s {$sel:ruleArn:Rule' :: Maybe Text
ruleArn = Maybe Text
a} :: Rule)

-- | Indicates whether this is the default rule.
rule_isDefault :: Lens.Lens' Rule (Prelude.Maybe Prelude.Bool)
rule_isDefault :: (Maybe Bool -> f (Maybe Bool)) -> Rule -> f Rule
rule_isDefault = (Rule -> Maybe Bool)
-> (Rule -> Maybe Bool -> Rule)
-> Lens Rule Rule (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Rule' {Maybe Bool
isDefault :: Maybe Bool
$sel:isDefault:Rule' :: Rule -> Maybe Bool
isDefault} -> Maybe Bool
isDefault) (\s :: Rule
s@Rule' {} Maybe Bool
a -> Rule
s {$sel:isDefault:Rule' :: Maybe Bool
isDefault = Maybe Bool
a} :: Rule)

instance Core.FromXML Rule where
  parseXML :: [Node] -> Either String Rule
parseXML [Node]
x =
    Maybe Text
-> Maybe [Action]
-> Maybe [RuleCondition]
-> Maybe Text
-> Maybe Bool
-> Rule
Rule'
      (Maybe Text
 -> Maybe [Action]
 -> Maybe [RuleCondition]
 -> Maybe Text
 -> Maybe Bool
 -> Rule)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe [Action]
      -> Maybe [RuleCondition] -> Maybe Text -> Maybe Bool -> Rule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Priority")
      Either
  String
  (Maybe [Action]
   -> Maybe [RuleCondition] -> Maybe Text -> Maybe Bool -> Rule)
-> Either String (Maybe [Action])
-> Either
     String (Maybe [RuleCondition] -> Maybe Text -> Maybe Bool -> Rule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Actions" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Action]))
-> Either String (Maybe [Action])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Action])
-> [Node] -> Either String (Maybe [Action])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Action]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either
  String (Maybe [RuleCondition] -> Maybe Text -> Maybe Bool -> Rule)
-> Either String (Maybe [RuleCondition])
-> Either String (Maybe Text -> Maybe Bool -> Rule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Conditions" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [RuleCondition]))
-> Either String (Maybe [RuleCondition])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [RuleCondition])
-> [Node] -> Either String (Maybe [RuleCondition])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [RuleCondition]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either String (Maybe Text -> Maybe Bool -> Rule)
-> Either String (Maybe Text) -> Either String (Maybe Bool -> Rule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"RuleArn")
      Either String (Maybe Bool -> Rule)
-> Either String (Maybe Bool) -> Either String Rule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Bool)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"IsDefault")

instance Prelude.Hashable Rule

instance Prelude.NFData Rule