{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.FMS.PutPolicy
-- 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)
--
-- Creates an Firewall Manager policy.
--
-- Firewall Manager provides the following types of policies:
--
-- -   An WAF policy (type WAFV2), which defines rule groups to run first
--     in the corresponding WAF web ACL and rule groups to run last in the
--     web ACL.
--
-- -   An WAF Classic policy (type WAF), which defines a rule group.
--
-- -   A Shield Advanced policy, which applies Shield Advanced protection
--     to specified accounts and resources.
--
-- -   A security group policy, which manages VPC security groups across
--     your Amazon Web Services organization.
--
-- -   An Network Firewall policy, which provides firewall rules to filter
--     network traffic in specified Amazon VPCs.
--
-- -   A DNS Firewall policy, which provides Route 53 Resolver DNS Firewall
--     rules to filter DNS queries for specified VPCs.
--
-- Each policy is specific to one of the types. If you want to enforce more
-- than one policy type across accounts, create multiple policies. You can
-- create multiple policies for each type.
--
-- You must be subscribed to Shield Advanced to create a Shield Advanced
-- policy. For more information about subscribing to Shield Advanced, see
-- <https://docs.aws.amazon.com/waf/latest/DDOSAPIReference/API_CreateSubscription.html CreateSubscription>.
module Amazonka.FMS.PutPolicy
  ( -- * Creating a Request
    PutPolicy (..),
    newPutPolicy,

    -- * Request Lenses
    putPolicy_tagList,
    putPolicy_policy,

    -- * Destructuring the Response
    PutPolicyResponse (..),
    newPutPolicyResponse,

    -- * Response Lenses
    putPolicyResponse_policyArn,
    putPolicyResponse_policy,
    putPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.FMS.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutPolicy' smart constructor.
data PutPolicy = PutPolicy'
  { -- | The tags to add to the Amazon Web Services resource.
    PutPolicy -> Maybe [Tag]
tagList :: Prelude.Maybe [Tag],
    -- | The details of the Firewall Manager policy to be created.
    PutPolicy -> Policy
policy :: Policy
  }
  deriving (PutPolicy -> PutPolicy -> Bool
(PutPolicy -> PutPolicy -> Bool)
-> (PutPolicy -> PutPolicy -> Bool) -> Eq PutPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutPolicy -> PutPolicy -> Bool
$c/= :: PutPolicy -> PutPolicy -> Bool
== :: PutPolicy -> PutPolicy -> Bool
$c== :: PutPolicy -> PutPolicy -> Bool
Prelude.Eq, ReadPrec [PutPolicy]
ReadPrec PutPolicy
Int -> ReadS PutPolicy
ReadS [PutPolicy]
(Int -> ReadS PutPolicy)
-> ReadS [PutPolicy]
-> ReadPrec PutPolicy
-> ReadPrec [PutPolicy]
-> Read PutPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutPolicy]
$creadListPrec :: ReadPrec [PutPolicy]
readPrec :: ReadPrec PutPolicy
$creadPrec :: ReadPrec PutPolicy
readList :: ReadS [PutPolicy]
$creadList :: ReadS [PutPolicy]
readsPrec :: Int -> ReadS PutPolicy
$creadsPrec :: Int -> ReadS PutPolicy
Prelude.Read, Int -> PutPolicy -> ShowS
[PutPolicy] -> ShowS
PutPolicy -> String
(Int -> PutPolicy -> ShowS)
-> (PutPolicy -> String)
-> ([PutPolicy] -> ShowS)
-> Show PutPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutPolicy] -> ShowS
$cshowList :: [PutPolicy] -> ShowS
show :: PutPolicy -> String
$cshow :: PutPolicy -> String
showsPrec :: Int -> PutPolicy -> ShowS
$cshowsPrec :: Int -> PutPolicy -> ShowS
Prelude.Show, (forall x. PutPolicy -> Rep PutPolicy x)
-> (forall x. Rep PutPolicy x -> PutPolicy) -> Generic PutPolicy
forall x. Rep PutPolicy x -> PutPolicy
forall x. PutPolicy -> Rep PutPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutPolicy x -> PutPolicy
$cfrom :: forall x. PutPolicy -> Rep PutPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutPolicy' 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:
--
-- 'tagList', 'putPolicy_tagList' - The tags to add to the Amazon Web Services resource.
--
-- 'policy', 'putPolicy_policy' - The details of the Firewall Manager policy to be created.
newPutPolicy ::
  -- | 'policy'
  Policy ->
  PutPolicy
newPutPolicy :: Policy -> PutPolicy
newPutPolicy Policy
pPolicy_ =
  PutPolicy' :: Maybe [Tag] -> Policy -> PutPolicy
PutPolicy'
    { $sel:tagList:PutPolicy' :: Maybe [Tag]
tagList = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:policy:PutPolicy' :: Policy
policy = Policy
pPolicy_
    }

-- | The tags to add to the Amazon Web Services resource.
putPolicy_tagList :: Lens.Lens' PutPolicy (Prelude.Maybe [Tag])
putPolicy_tagList :: (Maybe [Tag] -> f (Maybe [Tag])) -> PutPolicy -> f PutPolicy
putPolicy_tagList = (PutPolicy -> Maybe [Tag])
-> (PutPolicy -> Maybe [Tag] -> PutPolicy)
-> Lens PutPolicy PutPolicy (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPolicy' {Maybe [Tag]
tagList :: Maybe [Tag]
$sel:tagList:PutPolicy' :: PutPolicy -> Maybe [Tag]
tagList} -> Maybe [Tag]
tagList) (\s :: PutPolicy
s@PutPolicy' {} Maybe [Tag]
a -> PutPolicy
s {$sel:tagList:PutPolicy' :: Maybe [Tag]
tagList = Maybe [Tag]
a} :: PutPolicy) ((Maybe [Tag] -> f (Maybe [Tag])) -> PutPolicy -> f PutPolicy)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> PutPolicy
-> f PutPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
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 [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The details of the Firewall Manager policy to be created.
putPolicy_policy :: Lens.Lens' PutPolicy Policy
putPolicy_policy :: (Policy -> f Policy) -> PutPolicy -> f PutPolicy
putPolicy_policy = (PutPolicy -> Policy)
-> (PutPolicy -> Policy -> PutPolicy)
-> Lens PutPolicy PutPolicy Policy Policy
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPolicy' {Policy
policy :: Policy
$sel:policy:PutPolicy' :: PutPolicy -> Policy
policy} -> Policy
policy) (\s :: PutPolicy
s@PutPolicy' {} Policy
a -> PutPolicy
s {$sel:policy:PutPolicy' :: Policy
policy = Policy
a} :: PutPolicy)

instance Core.AWSRequest PutPolicy where
  type AWSResponse PutPolicy = PutPolicyResponse
  request :: PutPolicy -> Request PutPolicy
request = Service -> PutPolicy -> Request PutPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutPolicy))
-> Logger
-> Service
-> Proxy PutPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Maybe Policy -> Int -> PutPolicyResponse
PutPolicyResponse'
            (Maybe Text -> Maybe Policy -> Int -> PutPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Policy -> Int -> PutPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"PolicyArn")
            Either String (Maybe Policy -> Int -> PutPolicyResponse)
-> Either String (Maybe Policy)
-> Either String (Int -> PutPolicyResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Policy)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Policy")
            Either String (Int -> PutPolicyResponse)
-> Either String Int -> Either String PutPolicyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable PutPolicy

instance Prelude.NFData PutPolicy

instance Core.ToHeaders PutPolicy where
  toHeaders :: PutPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"AWSFMS_20180101.PutPolicy" :: Prelude.ByteString),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutPolicy where
  toJSON :: PutPolicy -> Value
toJSON PutPolicy' {Maybe [Tag]
Policy
policy :: Policy
tagList :: Maybe [Tag]
$sel:policy:PutPolicy' :: PutPolicy -> Policy
$sel:tagList:PutPolicy' :: PutPolicy -> Maybe [Tag]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"TagList" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tagList,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Policy" Text -> Policy -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Policy
policy)
          ]
      )

instance Core.ToPath PutPolicy where
  toPath :: PutPolicy -> ByteString
toPath = ByteString -> PutPolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery PutPolicy where
  toQuery :: PutPolicy -> QueryString
toQuery = QueryString -> PutPolicy -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newPutPolicyResponse' smart constructor.
data PutPolicyResponse = PutPolicyResponse'
  { -- | The Amazon Resource Name (ARN) of the policy.
    PutPolicyResponse -> Maybe Text
policyArn :: Prelude.Maybe Prelude.Text,
    -- | The details of the Firewall Manager policy.
    PutPolicyResponse -> Maybe Policy
policy :: Prelude.Maybe Policy,
    -- | The response's http status code.
    PutPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutPolicyResponse -> PutPolicyResponse -> Bool
(PutPolicyResponse -> PutPolicyResponse -> Bool)
-> (PutPolicyResponse -> PutPolicyResponse -> Bool)
-> Eq PutPolicyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutPolicyResponse -> PutPolicyResponse -> Bool
$c/= :: PutPolicyResponse -> PutPolicyResponse -> Bool
== :: PutPolicyResponse -> PutPolicyResponse -> Bool
$c== :: PutPolicyResponse -> PutPolicyResponse -> Bool
Prelude.Eq, ReadPrec [PutPolicyResponse]
ReadPrec PutPolicyResponse
Int -> ReadS PutPolicyResponse
ReadS [PutPolicyResponse]
(Int -> ReadS PutPolicyResponse)
-> ReadS [PutPolicyResponse]
-> ReadPrec PutPolicyResponse
-> ReadPrec [PutPolicyResponse]
-> Read PutPolicyResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutPolicyResponse]
$creadListPrec :: ReadPrec [PutPolicyResponse]
readPrec :: ReadPrec PutPolicyResponse
$creadPrec :: ReadPrec PutPolicyResponse
readList :: ReadS [PutPolicyResponse]
$creadList :: ReadS [PutPolicyResponse]
readsPrec :: Int -> ReadS PutPolicyResponse
$creadsPrec :: Int -> ReadS PutPolicyResponse
Prelude.Read, Int -> PutPolicyResponse -> ShowS
[PutPolicyResponse] -> ShowS
PutPolicyResponse -> String
(Int -> PutPolicyResponse -> ShowS)
-> (PutPolicyResponse -> String)
-> ([PutPolicyResponse] -> ShowS)
-> Show PutPolicyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutPolicyResponse] -> ShowS
$cshowList :: [PutPolicyResponse] -> ShowS
show :: PutPolicyResponse -> String
$cshow :: PutPolicyResponse -> String
showsPrec :: Int -> PutPolicyResponse -> ShowS
$cshowsPrec :: Int -> PutPolicyResponse -> ShowS
Prelude.Show, (forall x. PutPolicyResponse -> Rep PutPolicyResponse x)
-> (forall x. Rep PutPolicyResponse x -> PutPolicyResponse)
-> Generic PutPolicyResponse
forall x. Rep PutPolicyResponse x -> PutPolicyResponse
forall x. PutPolicyResponse -> Rep PutPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutPolicyResponse x -> PutPolicyResponse
$cfrom :: forall x. PutPolicyResponse -> Rep PutPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutPolicyResponse' 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:
--
-- 'policyArn', 'putPolicyResponse_policyArn' - The Amazon Resource Name (ARN) of the policy.
--
-- 'policy', 'putPolicyResponse_policy' - The details of the Firewall Manager policy.
--
-- 'httpStatus', 'putPolicyResponse_httpStatus' - The response's http status code.
newPutPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutPolicyResponse
newPutPolicyResponse :: Int -> PutPolicyResponse
newPutPolicyResponse Int
pHttpStatus_ =
  PutPolicyResponse' :: Maybe Text -> Maybe Policy -> Int -> PutPolicyResponse
PutPolicyResponse'
    { $sel:policyArn:PutPolicyResponse' :: Maybe Text
policyArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policy:PutPolicyResponse' :: Maybe Policy
policy = Maybe Policy
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

-- | The details of the Firewall Manager policy.
putPolicyResponse_policy :: Lens.Lens' PutPolicyResponse (Prelude.Maybe Policy)
putPolicyResponse_policy :: (Maybe Policy -> f (Maybe Policy))
-> PutPolicyResponse -> f PutPolicyResponse
putPolicyResponse_policy = (PutPolicyResponse -> Maybe Policy)
-> (PutPolicyResponse -> Maybe Policy -> PutPolicyResponse)
-> Lens
     PutPolicyResponse PutPolicyResponse (Maybe Policy) (Maybe Policy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPolicyResponse' {Maybe Policy
policy :: Maybe Policy
$sel:policy:PutPolicyResponse' :: PutPolicyResponse -> Maybe Policy
policy} -> Maybe Policy
policy) (\s :: PutPolicyResponse
s@PutPolicyResponse' {} Maybe Policy
a -> PutPolicyResponse
s {$sel:policy:PutPolicyResponse' :: Maybe Policy
policy = Maybe Policy
a} :: PutPolicyResponse)

-- | The response's http status code.
putPolicyResponse_httpStatus :: Lens.Lens' PutPolicyResponse Prelude.Int
putPolicyResponse_httpStatus :: (Int -> f Int) -> PutPolicyResponse -> f PutPolicyResponse
putPolicyResponse_httpStatus = (PutPolicyResponse -> Int)
-> (PutPolicyResponse -> Int -> PutPolicyResponse)
-> Lens PutPolicyResponse PutPolicyResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutPolicyResponse' {Int
httpStatus :: Int
$sel:httpStatus:PutPolicyResponse' :: PutPolicyResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: PutPolicyResponse
s@PutPolicyResponse' {} Int
a -> PutPolicyResponse
s {$sel:httpStatus:PutPolicyResponse' :: Int
httpStatus = Int
a} :: PutPolicyResponse)

instance Prelude.NFData PutPolicyResponse