{-# 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.Shield.DescribeProtection
-- 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)
--
-- Lists the details of a Protection object.
module Amazonka.Shield.DescribeProtection
  ( -- * Creating a Request
    DescribeProtection (..),
    newDescribeProtection,

    -- * Request Lenses
    describeProtection_protectionId,
    describeProtection_resourceArn,

    -- * Destructuring the Response
    DescribeProtectionResponse (..),
    newDescribeProtectionResponse,

    -- * Response Lenses
    describeProtectionResponse_protection,
    describeProtectionResponse_httpStatus,
  )
where

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

-- | /See:/ 'newDescribeProtection' smart constructor.
data DescribeProtection = DescribeProtection'
  { -- | The unique identifier (ID) for the Protection object that is described.
    -- When submitting the @DescribeProtection@ request you must provide either
    -- the @ResourceArn@ or the @ProtectionID@, but not both.
    DescribeProtection -> Maybe Text
protectionId :: Prelude.Maybe Prelude.Text,
    -- | The ARN (Amazon Resource Name) of the Amazon Web Services resource for
    -- the Protection object that is described. When submitting the
    -- @DescribeProtection@ request you must provide either the @ResourceArn@
    -- or the @ProtectionID@, but not both.
    DescribeProtection -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text
  }
  deriving (DescribeProtection -> DescribeProtection -> Bool
(DescribeProtection -> DescribeProtection -> Bool)
-> (DescribeProtection -> DescribeProtection -> Bool)
-> Eq DescribeProtection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeProtection -> DescribeProtection -> Bool
$c/= :: DescribeProtection -> DescribeProtection -> Bool
== :: DescribeProtection -> DescribeProtection -> Bool
$c== :: DescribeProtection -> DescribeProtection -> Bool
Prelude.Eq, ReadPrec [DescribeProtection]
ReadPrec DescribeProtection
Int -> ReadS DescribeProtection
ReadS [DescribeProtection]
(Int -> ReadS DescribeProtection)
-> ReadS [DescribeProtection]
-> ReadPrec DescribeProtection
-> ReadPrec [DescribeProtection]
-> Read DescribeProtection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeProtection]
$creadListPrec :: ReadPrec [DescribeProtection]
readPrec :: ReadPrec DescribeProtection
$creadPrec :: ReadPrec DescribeProtection
readList :: ReadS [DescribeProtection]
$creadList :: ReadS [DescribeProtection]
readsPrec :: Int -> ReadS DescribeProtection
$creadsPrec :: Int -> ReadS DescribeProtection
Prelude.Read, Int -> DescribeProtection -> ShowS
[DescribeProtection] -> ShowS
DescribeProtection -> String
(Int -> DescribeProtection -> ShowS)
-> (DescribeProtection -> String)
-> ([DescribeProtection] -> ShowS)
-> Show DescribeProtection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeProtection] -> ShowS
$cshowList :: [DescribeProtection] -> ShowS
show :: DescribeProtection -> String
$cshow :: DescribeProtection -> String
showsPrec :: Int -> DescribeProtection -> ShowS
$cshowsPrec :: Int -> DescribeProtection -> ShowS
Prelude.Show, (forall x. DescribeProtection -> Rep DescribeProtection x)
-> (forall x. Rep DescribeProtection x -> DescribeProtection)
-> Generic DescribeProtection
forall x. Rep DescribeProtection x -> DescribeProtection
forall x. DescribeProtection -> Rep DescribeProtection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeProtection x -> DescribeProtection
$cfrom :: forall x. DescribeProtection -> Rep DescribeProtection x
Prelude.Generic)

-- |
-- Create a value of 'DescribeProtection' 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:
--
-- 'protectionId', 'describeProtection_protectionId' - The unique identifier (ID) for the Protection object that is described.
-- When submitting the @DescribeProtection@ request you must provide either
-- the @ResourceArn@ or the @ProtectionID@, but not both.
--
-- 'resourceArn', 'describeProtection_resourceArn' - The ARN (Amazon Resource Name) of the Amazon Web Services resource for
-- the Protection object that is described. When submitting the
-- @DescribeProtection@ request you must provide either the @ResourceArn@
-- or the @ProtectionID@, but not both.
newDescribeProtection ::
  DescribeProtection
newDescribeProtection :: DescribeProtection
newDescribeProtection =
  DescribeProtection' :: Maybe Text -> Maybe Text -> DescribeProtection
DescribeProtection'
    { $sel:protectionId:DescribeProtection' :: Maybe Text
protectionId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:DescribeProtection' :: Maybe Text
resourceArn = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The unique identifier (ID) for the Protection object that is described.
-- When submitting the @DescribeProtection@ request you must provide either
-- the @ResourceArn@ or the @ProtectionID@, but not both.
describeProtection_protectionId :: Lens.Lens' DescribeProtection (Prelude.Maybe Prelude.Text)
describeProtection_protectionId :: (Maybe Text -> f (Maybe Text))
-> DescribeProtection -> f DescribeProtection
describeProtection_protectionId = (DescribeProtection -> Maybe Text)
-> (DescribeProtection -> Maybe Text -> DescribeProtection)
-> Lens
     DescribeProtection DescribeProtection (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtection' {Maybe Text
protectionId :: Maybe Text
$sel:protectionId:DescribeProtection' :: DescribeProtection -> Maybe Text
protectionId} -> Maybe Text
protectionId) (\s :: DescribeProtection
s@DescribeProtection' {} Maybe Text
a -> DescribeProtection
s {$sel:protectionId:DescribeProtection' :: Maybe Text
protectionId = Maybe Text
a} :: DescribeProtection)

-- | The ARN (Amazon Resource Name) of the Amazon Web Services resource for
-- the Protection object that is described. When submitting the
-- @DescribeProtection@ request you must provide either the @ResourceArn@
-- or the @ProtectionID@, but not both.
describeProtection_resourceArn :: Lens.Lens' DescribeProtection (Prelude.Maybe Prelude.Text)
describeProtection_resourceArn :: (Maybe Text -> f (Maybe Text))
-> DescribeProtection -> f DescribeProtection
describeProtection_resourceArn = (DescribeProtection -> Maybe Text)
-> (DescribeProtection -> Maybe Text -> DescribeProtection)
-> Lens
     DescribeProtection DescribeProtection (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtection' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:DescribeProtection' :: DescribeProtection -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: DescribeProtection
s@DescribeProtection' {} Maybe Text
a -> DescribeProtection
s {$sel:resourceArn:DescribeProtection' :: Maybe Text
resourceArn = Maybe Text
a} :: DescribeProtection)

instance Core.AWSRequest DescribeProtection where
  type
    AWSResponse DescribeProtection =
      DescribeProtectionResponse
  request :: DescribeProtection -> Request DescribeProtection
request = Service -> DescribeProtection -> Request DescribeProtection
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeProtection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeProtection)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeProtection))
-> Logger
-> Service
-> Proxy DescribeProtection
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeProtection)))
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 Protection -> Int -> DescribeProtectionResponse
DescribeProtectionResponse'
            (Maybe Protection -> Int -> DescribeProtectionResponse)
-> Either String (Maybe Protection)
-> Either String (Int -> DescribeProtectionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Protection)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Protection")
            Either String (Int -> DescribeProtectionResponse)
-> Either String Int -> Either String DescribeProtectionResponse
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 DescribeProtection

instance Prelude.NFData DescribeProtection

instance Core.ToHeaders DescribeProtection where
  toHeaders :: DescribeProtection -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeProtection -> 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
"AWSShield_20160616.DescribeProtection" ::
                          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 DescribeProtection where
  toJSON :: DescribeProtection -> Value
toJSON DescribeProtection' {Maybe Text
resourceArn :: Maybe Text
protectionId :: Maybe Text
$sel:resourceArn:DescribeProtection' :: DescribeProtection -> Maybe Text
$sel:protectionId:DescribeProtection' :: DescribeProtection -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ProtectionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
protectionId,
            (Text
"ResourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
resourceArn
          ]
      )

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

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

-- | /See:/ 'newDescribeProtectionResponse' smart constructor.
data DescribeProtectionResponse = DescribeProtectionResponse'
  { -- | The Protection object that is described.
    DescribeProtectionResponse -> Maybe Protection
protection :: Prelude.Maybe Protection,
    -- | The response's http status code.
    DescribeProtectionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeProtectionResponse -> DescribeProtectionResponse -> Bool
(DescribeProtectionResponse -> DescribeProtectionResponse -> Bool)
-> (DescribeProtectionResponse
    -> DescribeProtectionResponse -> Bool)
-> Eq DescribeProtectionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeProtectionResponse -> DescribeProtectionResponse -> Bool
$c/= :: DescribeProtectionResponse -> DescribeProtectionResponse -> Bool
== :: DescribeProtectionResponse -> DescribeProtectionResponse -> Bool
$c== :: DescribeProtectionResponse -> DescribeProtectionResponse -> Bool
Prelude.Eq, ReadPrec [DescribeProtectionResponse]
ReadPrec DescribeProtectionResponse
Int -> ReadS DescribeProtectionResponse
ReadS [DescribeProtectionResponse]
(Int -> ReadS DescribeProtectionResponse)
-> ReadS [DescribeProtectionResponse]
-> ReadPrec DescribeProtectionResponse
-> ReadPrec [DescribeProtectionResponse]
-> Read DescribeProtectionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeProtectionResponse]
$creadListPrec :: ReadPrec [DescribeProtectionResponse]
readPrec :: ReadPrec DescribeProtectionResponse
$creadPrec :: ReadPrec DescribeProtectionResponse
readList :: ReadS [DescribeProtectionResponse]
$creadList :: ReadS [DescribeProtectionResponse]
readsPrec :: Int -> ReadS DescribeProtectionResponse
$creadsPrec :: Int -> ReadS DescribeProtectionResponse
Prelude.Read, Int -> DescribeProtectionResponse -> ShowS
[DescribeProtectionResponse] -> ShowS
DescribeProtectionResponse -> String
(Int -> DescribeProtectionResponse -> ShowS)
-> (DescribeProtectionResponse -> String)
-> ([DescribeProtectionResponse] -> ShowS)
-> Show DescribeProtectionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeProtectionResponse] -> ShowS
$cshowList :: [DescribeProtectionResponse] -> ShowS
show :: DescribeProtectionResponse -> String
$cshow :: DescribeProtectionResponse -> String
showsPrec :: Int -> DescribeProtectionResponse -> ShowS
$cshowsPrec :: Int -> DescribeProtectionResponse -> ShowS
Prelude.Show, (forall x.
 DescribeProtectionResponse -> Rep DescribeProtectionResponse x)
-> (forall x.
    Rep DescribeProtectionResponse x -> DescribeProtectionResponse)
-> Generic DescribeProtectionResponse
forall x.
Rep DescribeProtectionResponse x -> DescribeProtectionResponse
forall x.
DescribeProtectionResponse -> Rep DescribeProtectionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeProtectionResponse x -> DescribeProtectionResponse
$cfrom :: forall x.
DescribeProtectionResponse -> Rep DescribeProtectionResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeProtectionResponse' 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:
--
-- 'protection', 'describeProtectionResponse_protection' - The Protection object that is described.
--
-- 'httpStatus', 'describeProtectionResponse_httpStatus' - The response's http status code.
newDescribeProtectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeProtectionResponse
newDescribeProtectionResponse :: Int -> DescribeProtectionResponse
newDescribeProtectionResponse Int
pHttpStatus_ =
  DescribeProtectionResponse' :: Maybe Protection -> Int -> DescribeProtectionResponse
DescribeProtectionResponse'
    { $sel:protection:DescribeProtectionResponse' :: Maybe Protection
protection =
        Maybe Protection
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeProtectionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Protection object that is described.
describeProtectionResponse_protection :: Lens.Lens' DescribeProtectionResponse (Prelude.Maybe Protection)
describeProtectionResponse_protection :: (Maybe Protection -> f (Maybe Protection))
-> DescribeProtectionResponse -> f DescribeProtectionResponse
describeProtectionResponse_protection = (DescribeProtectionResponse -> Maybe Protection)
-> (DescribeProtectionResponse
    -> Maybe Protection -> DescribeProtectionResponse)
-> Lens
     DescribeProtectionResponse
     DescribeProtectionResponse
     (Maybe Protection)
     (Maybe Protection)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeProtectionResponse' {Maybe Protection
protection :: Maybe Protection
$sel:protection:DescribeProtectionResponse' :: DescribeProtectionResponse -> Maybe Protection
protection} -> Maybe Protection
protection) (\s :: DescribeProtectionResponse
s@DescribeProtectionResponse' {} Maybe Protection
a -> DescribeProtectionResponse
s {$sel:protection:DescribeProtectionResponse' :: Maybe Protection
protection = Maybe Protection
a} :: DescribeProtectionResponse)

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

instance Prelude.NFData DescribeProtectionResponse