{-# 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.CloudFront.Types.AllowedMethods
-- 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.CloudFront.Types.AllowedMethods where

import Amazonka.CloudFront.Types.CachedMethods
import Amazonka.CloudFront.Types.Method
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A complex type that controls which HTTP methods CloudFront processes and
-- forwards to your Amazon S3 bucket or your custom origin. There are three
-- choices:
--
-- -   CloudFront forwards only @GET@ and @HEAD@ requests.
--
-- -   CloudFront forwards only @GET@, @HEAD@, and @OPTIONS@ requests.
--
-- -   CloudFront forwards @GET, HEAD, OPTIONS, PUT, PATCH, POST@, and
--     @DELETE@ requests.
--
-- If you pick the third choice, you may need to restrict access to your
-- Amazon S3 bucket or to your custom origin so users can\'t perform
-- operations that you don\'t want them to. For example, you might not want
-- users to have permissions to delete objects from your origin.
--
-- /See:/ 'newAllowedMethods' smart constructor.
data AllowedMethods = AllowedMethods'
  { AllowedMethods -> Maybe CachedMethods
cachedMethods :: Prelude.Maybe CachedMethods,
    -- | The number of HTTP methods that you want CloudFront to forward to your
    -- origin. Valid values are 2 (for @GET@ and @HEAD@ requests), 3 (for
    -- @GET@, @HEAD@, and @OPTIONS@ requests) and 7 (for
    -- @GET, HEAD, OPTIONS, PUT, PATCH, POST@, and @DELETE@ requests).
    AllowedMethods -> Int
quantity :: Prelude.Int,
    -- | A complex type that contains the HTTP methods that you want CloudFront
    -- to process and forward to your origin.
    AllowedMethods -> [Method]
items :: [Method]
  }
  deriving (AllowedMethods -> AllowedMethods -> Bool
(AllowedMethods -> AllowedMethods -> Bool)
-> (AllowedMethods -> AllowedMethods -> Bool) -> Eq AllowedMethods
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AllowedMethods -> AllowedMethods -> Bool
$c/= :: AllowedMethods -> AllowedMethods -> Bool
== :: AllowedMethods -> AllowedMethods -> Bool
$c== :: AllowedMethods -> AllowedMethods -> Bool
Prelude.Eq, ReadPrec [AllowedMethods]
ReadPrec AllowedMethods
Int -> ReadS AllowedMethods
ReadS [AllowedMethods]
(Int -> ReadS AllowedMethods)
-> ReadS [AllowedMethods]
-> ReadPrec AllowedMethods
-> ReadPrec [AllowedMethods]
-> Read AllowedMethods
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AllowedMethods]
$creadListPrec :: ReadPrec [AllowedMethods]
readPrec :: ReadPrec AllowedMethods
$creadPrec :: ReadPrec AllowedMethods
readList :: ReadS [AllowedMethods]
$creadList :: ReadS [AllowedMethods]
readsPrec :: Int -> ReadS AllowedMethods
$creadsPrec :: Int -> ReadS AllowedMethods
Prelude.Read, Int -> AllowedMethods -> ShowS
[AllowedMethods] -> ShowS
AllowedMethods -> String
(Int -> AllowedMethods -> ShowS)
-> (AllowedMethods -> String)
-> ([AllowedMethods] -> ShowS)
-> Show AllowedMethods
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AllowedMethods] -> ShowS
$cshowList :: [AllowedMethods] -> ShowS
show :: AllowedMethods -> String
$cshow :: AllowedMethods -> String
showsPrec :: Int -> AllowedMethods -> ShowS
$cshowsPrec :: Int -> AllowedMethods -> ShowS
Prelude.Show, (forall x. AllowedMethods -> Rep AllowedMethods x)
-> (forall x. Rep AllowedMethods x -> AllowedMethods)
-> Generic AllowedMethods
forall x. Rep AllowedMethods x -> AllowedMethods
forall x. AllowedMethods -> Rep AllowedMethods x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AllowedMethods x -> AllowedMethods
$cfrom :: forall x. AllowedMethods -> Rep AllowedMethods x
Prelude.Generic)

-- |
-- Create a value of 'AllowedMethods' 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:
--
-- 'cachedMethods', 'allowedMethods_cachedMethods' - Undocumented member.
--
-- 'quantity', 'allowedMethods_quantity' - The number of HTTP methods that you want CloudFront to forward to your
-- origin. Valid values are 2 (for @GET@ and @HEAD@ requests), 3 (for
-- @GET@, @HEAD@, and @OPTIONS@ requests) and 7 (for
-- @GET, HEAD, OPTIONS, PUT, PATCH, POST@, and @DELETE@ requests).
--
-- 'items', 'allowedMethods_items' - A complex type that contains the HTTP methods that you want CloudFront
-- to process and forward to your origin.
newAllowedMethods ::
  -- | 'quantity'
  Prelude.Int ->
  AllowedMethods
newAllowedMethods :: Int -> AllowedMethods
newAllowedMethods Int
pQuantity_ =
  AllowedMethods' :: Maybe CachedMethods -> Int -> [Method] -> AllowedMethods
AllowedMethods'
    { $sel:cachedMethods:AllowedMethods' :: Maybe CachedMethods
cachedMethods = Maybe CachedMethods
forall a. Maybe a
Prelude.Nothing,
      $sel:quantity:AllowedMethods' :: Int
quantity = Int
pQuantity_,
      $sel:items:AllowedMethods' :: [Method]
items = [Method]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Undocumented member.
allowedMethods_cachedMethods :: Lens.Lens' AllowedMethods (Prelude.Maybe CachedMethods)
allowedMethods_cachedMethods :: (Maybe CachedMethods -> f (Maybe CachedMethods))
-> AllowedMethods -> f AllowedMethods
allowedMethods_cachedMethods = (AllowedMethods -> Maybe CachedMethods)
-> (AllowedMethods -> Maybe CachedMethods -> AllowedMethods)
-> Lens
     AllowedMethods
     AllowedMethods
     (Maybe CachedMethods)
     (Maybe CachedMethods)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllowedMethods' {Maybe CachedMethods
cachedMethods :: Maybe CachedMethods
$sel:cachedMethods:AllowedMethods' :: AllowedMethods -> Maybe CachedMethods
cachedMethods} -> Maybe CachedMethods
cachedMethods) (\s :: AllowedMethods
s@AllowedMethods' {} Maybe CachedMethods
a -> AllowedMethods
s {$sel:cachedMethods:AllowedMethods' :: Maybe CachedMethods
cachedMethods = Maybe CachedMethods
a} :: AllowedMethods)

-- | The number of HTTP methods that you want CloudFront to forward to your
-- origin. Valid values are 2 (for @GET@ and @HEAD@ requests), 3 (for
-- @GET@, @HEAD@, and @OPTIONS@ requests) and 7 (for
-- @GET, HEAD, OPTIONS, PUT, PATCH, POST@, and @DELETE@ requests).
allowedMethods_quantity :: Lens.Lens' AllowedMethods Prelude.Int
allowedMethods_quantity :: (Int -> f Int) -> AllowedMethods -> f AllowedMethods
allowedMethods_quantity = (AllowedMethods -> Int)
-> (AllowedMethods -> Int -> AllowedMethods)
-> Lens AllowedMethods AllowedMethods Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllowedMethods' {Int
quantity :: Int
$sel:quantity:AllowedMethods' :: AllowedMethods -> Int
quantity} -> Int
quantity) (\s :: AllowedMethods
s@AllowedMethods' {} Int
a -> AllowedMethods
s {$sel:quantity:AllowedMethods' :: Int
quantity = Int
a} :: AllowedMethods)

-- | A complex type that contains the HTTP methods that you want CloudFront
-- to process and forward to your origin.
allowedMethods_items :: Lens.Lens' AllowedMethods [Method]
allowedMethods_items :: ([Method] -> f [Method]) -> AllowedMethods -> f AllowedMethods
allowedMethods_items = (AllowedMethods -> [Method])
-> (AllowedMethods -> [Method] -> AllowedMethods)
-> Lens AllowedMethods AllowedMethods [Method] [Method]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AllowedMethods' {[Method]
items :: [Method]
$sel:items:AllowedMethods' :: AllowedMethods -> [Method]
items} -> [Method]
items) (\s :: AllowedMethods
s@AllowedMethods' {} [Method]
a -> AllowedMethods
s {$sel:items:AllowedMethods' :: [Method]
items = [Method]
a} :: AllowedMethods) (([Method] -> f [Method]) -> AllowedMethods -> f AllowedMethods)
-> (([Method] -> f [Method]) -> [Method] -> f [Method])
-> ([Method] -> f [Method])
-> AllowedMethods
-> f AllowedMethods
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Method] -> f [Method]) -> [Method] -> f [Method]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromXML AllowedMethods where
  parseXML :: [Node] -> Either String AllowedMethods
parseXML [Node]
x =
    Maybe CachedMethods -> Int -> [Method] -> AllowedMethods
AllowedMethods'
      (Maybe CachedMethods -> Int -> [Method] -> AllowedMethods)
-> Either String (Maybe CachedMethods)
-> Either String (Int -> [Method] -> AllowedMethods)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe CachedMethods)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"CachedMethods")
      Either String (Int -> [Method] -> AllowedMethods)
-> Either String Int -> Either String ([Method] -> AllowedMethods)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Int
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Quantity")
      Either String ([Method] -> AllowedMethods)
-> Either String [Method] -> Either String AllowedMethods
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
"Items" 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 [Method]) -> Either String [Method]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= Text -> [Node] -> Either String [Method]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"Method"
                  )

instance Prelude.Hashable AllowedMethods

instance Prelude.NFData AllowedMethods

instance Core.ToXML AllowedMethods where
  toXML :: AllowedMethods -> XML
toXML AllowedMethods' {Int
[Method]
Maybe CachedMethods
items :: [Method]
quantity :: Int
cachedMethods :: Maybe CachedMethods
$sel:items:AllowedMethods' :: AllowedMethods -> [Method]
$sel:quantity:AllowedMethods' :: AllowedMethods -> Int
$sel:cachedMethods:AllowedMethods' :: AllowedMethods -> Maybe CachedMethods
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"CachedMethods" Name -> Maybe CachedMethods -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe CachedMethods
cachedMethods,
        Name
"Quantity" Name -> Int -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Int
quantity,
        Name
"Items" Name -> XML -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Name -> [Method] -> XML
forall a. (IsList a, ToXML (Item a)) => Name -> a -> XML
Core.toXMLList Name
"Method" [Method]
items
      ]