{-# 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.EMR.Types.BlockPublicAccessConfiguration
-- 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.EMR.Types.BlockPublicAccessConfiguration where

import qualified Amazonka.Core as Core
import Amazonka.EMR.Types.PortRange
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A configuration for Amazon EMR block public access. When
-- @BlockPublicSecurityGroupRules@ is set to @true@, Amazon EMR prevents
-- cluster creation if one of the cluster\'s security groups has a rule
-- that allows inbound traffic from 0.0.0.0\/0 or ::\/0 on a port, unless
-- the port is specified as an exception using
-- @PermittedPublicSecurityGroupRuleRanges@.
--
-- /See:/ 'newBlockPublicAccessConfiguration' smart constructor.
data BlockPublicAccessConfiguration = BlockPublicAccessConfiguration'
  { -- | Specifies ports and port ranges that are permitted to have security
    -- group rules that allow inbound traffic from all public sources. For
    -- example, if Port 23 (Telnet) is specified for
    -- @PermittedPublicSecurityGroupRuleRanges@, Amazon EMR allows cluster
    -- creation if a security group associated with the cluster has a rule that
    -- allows inbound traffic on Port 23 from IPv4 0.0.0.0\/0 or IPv6 port
    -- ::\/0 as the source.
    --
    -- By default, Port 22, which is used for SSH access to the cluster EC2
    -- instances, is in the list of @PermittedPublicSecurityGroupRuleRanges@.
    BlockPublicAccessConfiguration -> Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges :: Prelude.Maybe [PortRange],
    -- | Indicates whether Amazon EMR block public access is enabled (@true@) or
    -- disabled (@false@). By default, the value is @false@ for accounts that
    -- have created EMR clusters before July 2019. For accounts created after
    -- this, the default is @true@.
    BlockPublicAccessConfiguration -> Bool
blockPublicSecurityGroupRules :: Prelude.Bool
  }
  deriving (BlockPublicAccessConfiguration
-> BlockPublicAccessConfiguration -> Bool
(BlockPublicAccessConfiguration
 -> BlockPublicAccessConfiguration -> Bool)
-> (BlockPublicAccessConfiguration
    -> BlockPublicAccessConfiguration -> Bool)
-> Eq BlockPublicAccessConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlockPublicAccessConfiguration
-> BlockPublicAccessConfiguration -> Bool
$c/= :: BlockPublicAccessConfiguration
-> BlockPublicAccessConfiguration -> Bool
== :: BlockPublicAccessConfiguration
-> BlockPublicAccessConfiguration -> Bool
$c== :: BlockPublicAccessConfiguration
-> BlockPublicAccessConfiguration -> Bool
Prelude.Eq, ReadPrec [BlockPublicAccessConfiguration]
ReadPrec BlockPublicAccessConfiguration
Int -> ReadS BlockPublicAccessConfiguration
ReadS [BlockPublicAccessConfiguration]
(Int -> ReadS BlockPublicAccessConfiguration)
-> ReadS [BlockPublicAccessConfiguration]
-> ReadPrec BlockPublicAccessConfiguration
-> ReadPrec [BlockPublicAccessConfiguration]
-> Read BlockPublicAccessConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlockPublicAccessConfiguration]
$creadListPrec :: ReadPrec [BlockPublicAccessConfiguration]
readPrec :: ReadPrec BlockPublicAccessConfiguration
$creadPrec :: ReadPrec BlockPublicAccessConfiguration
readList :: ReadS [BlockPublicAccessConfiguration]
$creadList :: ReadS [BlockPublicAccessConfiguration]
readsPrec :: Int -> ReadS BlockPublicAccessConfiguration
$creadsPrec :: Int -> ReadS BlockPublicAccessConfiguration
Prelude.Read, Int -> BlockPublicAccessConfiguration -> ShowS
[BlockPublicAccessConfiguration] -> ShowS
BlockPublicAccessConfiguration -> String
(Int -> BlockPublicAccessConfiguration -> ShowS)
-> (BlockPublicAccessConfiguration -> String)
-> ([BlockPublicAccessConfiguration] -> ShowS)
-> Show BlockPublicAccessConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockPublicAccessConfiguration] -> ShowS
$cshowList :: [BlockPublicAccessConfiguration] -> ShowS
show :: BlockPublicAccessConfiguration -> String
$cshow :: BlockPublicAccessConfiguration -> String
showsPrec :: Int -> BlockPublicAccessConfiguration -> ShowS
$cshowsPrec :: Int -> BlockPublicAccessConfiguration -> ShowS
Prelude.Show, (forall x.
 BlockPublicAccessConfiguration
 -> Rep BlockPublicAccessConfiguration x)
-> (forall x.
    Rep BlockPublicAccessConfiguration x
    -> BlockPublicAccessConfiguration)
-> Generic BlockPublicAccessConfiguration
forall x.
Rep BlockPublicAccessConfiguration x
-> BlockPublicAccessConfiguration
forall x.
BlockPublicAccessConfiguration
-> Rep BlockPublicAccessConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BlockPublicAccessConfiguration x
-> BlockPublicAccessConfiguration
$cfrom :: forall x.
BlockPublicAccessConfiguration
-> Rep BlockPublicAccessConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'BlockPublicAccessConfiguration' 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:
--
-- 'permittedPublicSecurityGroupRuleRanges', 'blockPublicAccessConfiguration_permittedPublicSecurityGroupRuleRanges' - Specifies ports and port ranges that are permitted to have security
-- group rules that allow inbound traffic from all public sources. For
-- example, if Port 23 (Telnet) is specified for
-- @PermittedPublicSecurityGroupRuleRanges@, Amazon EMR allows cluster
-- creation if a security group associated with the cluster has a rule that
-- allows inbound traffic on Port 23 from IPv4 0.0.0.0\/0 or IPv6 port
-- ::\/0 as the source.
--
-- By default, Port 22, which is used for SSH access to the cluster EC2
-- instances, is in the list of @PermittedPublicSecurityGroupRuleRanges@.
--
-- 'blockPublicSecurityGroupRules', 'blockPublicAccessConfiguration_blockPublicSecurityGroupRules' - Indicates whether Amazon EMR block public access is enabled (@true@) or
-- disabled (@false@). By default, the value is @false@ for accounts that
-- have created EMR clusters before July 2019. For accounts created after
-- this, the default is @true@.
newBlockPublicAccessConfiguration ::
  -- | 'blockPublicSecurityGroupRules'
  Prelude.Bool ->
  BlockPublicAccessConfiguration
newBlockPublicAccessConfiguration :: Bool -> BlockPublicAccessConfiguration
newBlockPublicAccessConfiguration
  Bool
pBlockPublicSecurityGroupRules_ =
    BlockPublicAccessConfiguration' :: Maybe [PortRange] -> Bool -> BlockPublicAccessConfiguration
BlockPublicAccessConfiguration'
      { $sel:permittedPublicSecurityGroupRuleRanges:BlockPublicAccessConfiguration' :: Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges =
          Maybe [PortRange]
forall a. Maybe a
Prelude.Nothing,
        $sel:blockPublicSecurityGroupRules:BlockPublicAccessConfiguration' :: Bool
blockPublicSecurityGroupRules =
          Bool
pBlockPublicSecurityGroupRules_
      }

-- | Specifies ports and port ranges that are permitted to have security
-- group rules that allow inbound traffic from all public sources. For
-- example, if Port 23 (Telnet) is specified for
-- @PermittedPublicSecurityGroupRuleRanges@, Amazon EMR allows cluster
-- creation if a security group associated with the cluster has a rule that
-- allows inbound traffic on Port 23 from IPv4 0.0.0.0\/0 or IPv6 port
-- ::\/0 as the source.
--
-- By default, Port 22, which is used for SSH access to the cluster EC2
-- instances, is in the list of @PermittedPublicSecurityGroupRuleRanges@.
blockPublicAccessConfiguration_permittedPublicSecurityGroupRuleRanges :: Lens.Lens' BlockPublicAccessConfiguration (Prelude.Maybe [PortRange])
blockPublicAccessConfiguration_permittedPublicSecurityGroupRuleRanges :: (Maybe [PortRange] -> f (Maybe [PortRange]))
-> BlockPublicAccessConfiguration
-> f BlockPublicAccessConfiguration
blockPublicAccessConfiguration_permittedPublicSecurityGroupRuleRanges = (BlockPublicAccessConfiguration -> Maybe [PortRange])
-> (BlockPublicAccessConfiguration
    -> Maybe [PortRange] -> BlockPublicAccessConfiguration)
-> Lens
     BlockPublicAccessConfiguration
     BlockPublicAccessConfiguration
     (Maybe [PortRange])
     (Maybe [PortRange])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockPublicAccessConfiguration' {Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges :: Maybe [PortRange]
$sel:permittedPublicSecurityGroupRuleRanges:BlockPublicAccessConfiguration' :: BlockPublicAccessConfiguration -> Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges} -> Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges) (\s :: BlockPublicAccessConfiguration
s@BlockPublicAccessConfiguration' {} Maybe [PortRange]
a -> BlockPublicAccessConfiguration
s {$sel:permittedPublicSecurityGroupRuleRanges:BlockPublicAccessConfiguration' :: Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges = Maybe [PortRange]
a} :: BlockPublicAccessConfiguration) ((Maybe [PortRange] -> f (Maybe [PortRange]))
 -> BlockPublicAccessConfiguration
 -> f BlockPublicAccessConfiguration)
-> ((Maybe [PortRange] -> f (Maybe [PortRange]))
    -> Maybe [PortRange] -> f (Maybe [PortRange]))
-> (Maybe [PortRange] -> f (Maybe [PortRange]))
-> BlockPublicAccessConfiguration
-> f BlockPublicAccessConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [PortRange] [PortRange] [PortRange] [PortRange]
-> Iso
     (Maybe [PortRange])
     (Maybe [PortRange])
     (Maybe [PortRange])
     (Maybe [PortRange])
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 [PortRange] [PortRange] [PortRange] [PortRange]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Indicates whether Amazon EMR block public access is enabled (@true@) or
-- disabled (@false@). By default, the value is @false@ for accounts that
-- have created EMR clusters before July 2019. For accounts created after
-- this, the default is @true@.
blockPublicAccessConfiguration_blockPublicSecurityGroupRules :: Lens.Lens' BlockPublicAccessConfiguration Prelude.Bool
blockPublicAccessConfiguration_blockPublicSecurityGroupRules :: (Bool -> f Bool)
-> BlockPublicAccessConfiguration
-> f BlockPublicAccessConfiguration
blockPublicAccessConfiguration_blockPublicSecurityGroupRules = (BlockPublicAccessConfiguration -> Bool)
-> (BlockPublicAccessConfiguration
    -> Bool -> BlockPublicAccessConfiguration)
-> Lens
     BlockPublicAccessConfiguration
     BlockPublicAccessConfiguration
     Bool
     Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockPublicAccessConfiguration' {Bool
blockPublicSecurityGroupRules :: Bool
$sel:blockPublicSecurityGroupRules:BlockPublicAccessConfiguration' :: BlockPublicAccessConfiguration -> Bool
blockPublicSecurityGroupRules} -> Bool
blockPublicSecurityGroupRules) (\s :: BlockPublicAccessConfiguration
s@BlockPublicAccessConfiguration' {} Bool
a -> BlockPublicAccessConfiguration
s {$sel:blockPublicSecurityGroupRules:BlockPublicAccessConfiguration' :: Bool
blockPublicSecurityGroupRules = Bool
a} :: BlockPublicAccessConfiguration)

instance Core.FromJSON BlockPublicAccessConfiguration where
  parseJSON :: Value -> Parser BlockPublicAccessConfiguration
parseJSON =
    String
-> (Object -> Parser BlockPublicAccessConfiguration)
-> Value
-> Parser BlockPublicAccessConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"BlockPublicAccessConfiguration"
      ( \Object
x ->
          Maybe [PortRange] -> Bool -> BlockPublicAccessConfiguration
BlockPublicAccessConfiguration'
            (Maybe [PortRange] -> Bool -> BlockPublicAccessConfiguration)
-> Parser (Maybe [PortRange])
-> Parser (Bool -> BlockPublicAccessConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [PortRange]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PermittedPublicSecurityGroupRuleRanges"
                            Parser (Maybe (Maybe [PortRange]))
-> Maybe [PortRange] -> Parser (Maybe [PortRange])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [PortRange]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Bool -> BlockPublicAccessConfiguration)
-> Parser Bool -> Parser BlockPublicAccessConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"BlockPublicSecurityGroupRules")
      )

instance
  Prelude.Hashable
    BlockPublicAccessConfiguration

instance
  Prelude.NFData
    BlockPublicAccessConfiguration

instance Core.ToJSON BlockPublicAccessConfiguration where
  toJSON :: BlockPublicAccessConfiguration -> Value
toJSON BlockPublicAccessConfiguration' {Bool
Maybe [PortRange]
blockPublicSecurityGroupRules :: Bool
permittedPublicSecurityGroupRuleRanges :: Maybe [PortRange]
$sel:blockPublicSecurityGroupRules:BlockPublicAccessConfiguration' :: BlockPublicAccessConfiguration -> Bool
$sel:permittedPublicSecurityGroupRuleRanges:BlockPublicAccessConfiguration' :: BlockPublicAccessConfiguration -> Maybe [PortRange]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PermittedPublicSecurityGroupRuleRanges" Text -> [PortRange] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([PortRange] -> Pair) -> Maybe [PortRange] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PortRange]
permittedPublicSecurityGroupRuleRanges,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"BlockPublicSecurityGroupRules"
                  Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
blockPublicSecurityGroupRules
              )
          ]
      )