{-# 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.DescribeAttack
-- 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)
--
-- Describes the details of a DDoS attack.
module Amazonka.Shield.DescribeAttack
  ( -- * Creating a Request
    DescribeAttack (..),
    newDescribeAttack,

    -- * Request Lenses
    describeAttack_attackId,

    -- * Destructuring the Response
    DescribeAttackResponse (..),
    newDescribeAttackResponse,

    -- * Response Lenses
    describeAttackResponse_attack,
    describeAttackResponse_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:/ 'newDescribeAttack' smart constructor.
data DescribeAttack = DescribeAttack'
  { -- | The unique identifier (ID) for the attack that to be described.
    DescribeAttack -> Text
attackId :: Prelude.Text
  }
  deriving (DescribeAttack -> DescribeAttack -> Bool
(DescribeAttack -> DescribeAttack -> Bool)
-> (DescribeAttack -> DescribeAttack -> Bool) -> Eq DescribeAttack
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeAttack -> DescribeAttack -> Bool
$c/= :: DescribeAttack -> DescribeAttack -> Bool
== :: DescribeAttack -> DescribeAttack -> Bool
$c== :: DescribeAttack -> DescribeAttack -> Bool
Prelude.Eq, ReadPrec [DescribeAttack]
ReadPrec DescribeAttack
Int -> ReadS DescribeAttack
ReadS [DescribeAttack]
(Int -> ReadS DescribeAttack)
-> ReadS [DescribeAttack]
-> ReadPrec DescribeAttack
-> ReadPrec [DescribeAttack]
-> Read DescribeAttack
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeAttack]
$creadListPrec :: ReadPrec [DescribeAttack]
readPrec :: ReadPrec DescribeAttack
$creadPrec :: ReadPrec DescribeAttack
readList :: ReadS [DescribeAttack]
$creadList :: ReadS [DescribeAttack]
readsPrec :: Int -> ReadS DescribeAttack
$creadsPrec :: Int -> ReadS DescribeAttack
Prelude.Read, Int -> DescribeAttack -> ShowS
[DescribeAttack] -> ShowS
DescribeAttack -> String
(Int -> DescribeAttack -> ShowS)
-> (DescribeAttack -> String)
-> ([DescribeAttack] -> ShowS)
-> Show DescribeAttack
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeAttack] -> ShowS
$cshowList :: [DescribeAttack] -> ShowS
show :: DescribeAttack -> String
$cshow :: DescribeAttack -> String
showsPrec :: Int -> DescribeAttack -> ShowS
$cshowsPrec :: Int -> DescribeAttack -> ShowS
Prelude.Show, (forall x. DescribeAttack -> Rep DescribeAttack x)
-> (forall x. Rep DescribeAttack x -> DescribeAttack)
-> Generic DescribeAttack
forall x. Rep DescribeAttack x -> DescribeAttack
forall x. DescribeAttack -> Rep DescribeAttack x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeAttack x -> DescribeAttack
$cfrom :: forall x. DescribeAttack -> Rep DescribeAttack x
Prelude.Generic)

-- |
-- Create a value of 'DescribeAttack' 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:
--
-- 'attackId', 'describeAttack_attackId' - The unique identifier (ID) for the attack that to be described.
newDescribeAttack ::
  -- | 'attackId'
  Prelude.Text ->
  DescribeAttack
newDescribeAttack :: Text -> DescribeAttack
newDescribeAttack Text
pAttackId_ =
  DescribeAttack' :: Text -> DescribeAttack
DescribeAttack' {$sel:attackId:DescribeAttack' :: Text
attackId = Text
pAttackId_}

-- | The unique identifier (ID) for the attack that to be described.
describeAttack_attackId :: Lens.Lens' DescribeAttack Prelude.Text
describeAttack_attackId :: (Text -> f Text) -> DescribeAttack -> f DescribeAttack
describeAttack_attackId = (DescribeAttack -> Text)
-> (DescribeAttack -> Text -> DescribeAttack)
-> Lens DescribeAttack DescribeAttack Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAttack' {Text
attackId :: Text
$sel:attackId:DescribeAttack' :: DescribeAttack -> Text
attackId} -> Text
attackId) (\s :: DescribeAttack
s@DescribeAttack' {} Text
a -> DescribeAttack
s {$sel:attackId:DescribeAttack' :: Text
attackId = Text
a} :: DescribeAttack)

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

instance Prelude.NFData DescribeAttack

instance Core.ToHeaders DescribeAttack where
  toHeaders :: DescribeAttack -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeAttack -> 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.DescribeAttack" ::
                          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 DescribeAttack where
  toJSON :: DescribeAttack -> Value
toJSON DescribeAttack' {Text
attackId :: Text
$sel:attackId:DescribeAttack' :: DescribeAttack -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"AttackId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
attackId)]
      )

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

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

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

-- |
-- Create a value of 'DescribeAttackResponse' 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:
--
-- 'attack', 'describeAttackResponse_attack' - The attack that is described.
--
-- 'httpStatus', 'describeAttackResponse_httpStatus' - The response's http status code.
newDescribeAttackResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeAttackResponse
newDescribeAttackResponse :: Int -> DescribeAttackResponse
newDescribeAttackResponse Int
pHttpStatus_ =
  DescribeAttackResponse' :: Maybe AttackDetail -> Int -> DescribeAttackResponse
DescribeAttackResponse'
    { $sel:attack:DescribeAttackResponse' :: Maybe AttackDetail
attack = Maybe AttackDetail
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeAttackResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The attack that is described.
describeAttackResponse_attack :: Lens.Lens' DescribeAttackResponse (Prelude.Maybe AttackDetail)
describeAttackResponse_attack :: (Maybe AttackDetail -> f (Maybe AttackDetail))
-> DescribeAttackResponse -> f DescribeAttackResponse
describeAttackResponse_attack = (DescribeAttackResponse -> Maybe AttackDetail)
-> (DescribeAttackResponse
    -> Maybe AttackDetail -> DescribeAttackResponse)
-> Lens
     DescribeAttackResponse
     DescribeAttackResponse
     (Maybe AttackDetail)
     (Maybe AttackDetail)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAttackResponse' {Maybe AttackDetail
attack :: Maybe AttackDetail
$sel:attack:DescribeAttackResponse' :: DescribeAttackResponse -> Maybe AttackDetail
attack} -> Maybe AttackDetail
attack) (\s :: DescribeAttackResponse
s@DescribeAttackResponse' {} Maybe AttackDetail
a -> DescribeAttackResponse
s {$sel:attack:DescribeAttackResponse' :: Maybe AttackDetail
attack = Maybe AttackDetail
a} :: DescribeAttackResponse)

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

instance Prelude.NFData DescribeAttackResponse