{-# 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.DescribeAttackStatistics
-- 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)
--
-- Provides information about the number and type of attacks Shield has
-- detected in the last year for all resources that belong to your account,
-- regardless of whether you\'ve defined Shield protections for them. This
-- operation is available to Shield customers as well as to Shield Advanced
-- customers.
--
-- The operation returns data for the time range of midnight UTC, one year
-- ago, to midnight UTC, today. For example, if the current time is
-- @2020-10-26 15:39:32 PDT@, equal to @2020-10-26 22:39:32 UTC@, then the
-- time range for the attack data returned is from
-- @2019-10-26 00:00:00 UTC@ to @2020-10-26 00:00:00 UTC@.
--
-- The time range indicates the period covered by the attack statistics
-- data items.
module Amazonka.Shield.DescribeAttackStatistics
  ( -- * Creating a Request
    DescribeAttackStatistics (..),
    newDescribeAttackStatistics,

    -- * Destructuring the Response
    DescribeAttackStatisticsResponse (..),
    newDescribeAttackStatisticsResponse,

    -- * Response Lenses
    describeAttackStatisticsResponse_httpStatus,
    describeAttackStatisticsResponse_timeRange,
    describeAttackStatisticsResponse_dataItems,
  )
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:/ 'newDescribeAttackStatistics' smart constructor.
data DescribeAttackStatistics = DescribeAttackStatistics'
  {
  }
  deriving (DescribeAttackStatistics -> DescribeAttackStatistics -> Bool
(DescribeAttackStatistics -> DescribeAttackStatistics -> Bool)
-> (DescribeAttackStatistics -> DescribeAttackStatistics -> Bool)
-> Eq DescribeAttackStatistics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeAttackStatistics -> DescribeAttackStatistics -> Bool
$c/= :: DescribeAttackStatistics -> DescribeAttackStatistics -> Bool
== :: DescribeAttackStatistics -> DescribeAttackStatistics -> Bool
$c== :: DescribeAttackStatistics -> DescribeAttackStatistics -> Bool
Prelude.Eq, ReadPrec [DescribeAttackStatistics]
ReadPrec DescribeAttackStatistics
Int -> ReadS DescribeAttackStatistics
ReadS [DescribeAttackStatistics]
(Int -> ReadS DescribeAttackStatistics)
-> ReadS [DescribeAttackStatistics]
-> ReadPrec DescribeAttackStatistics
-> ReadPrec [DescribeAttackStatistics]
-> Read DescribeAttackStatistics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeAttackStatistics]
$creadListPrec :: ReadPrec [DescribeAttackStatistics]
readPrec :: ReadPrec DescribeAttackStatistics
$creadPrec :: ReadPrec DescribeAttackStatistics
readList :: ReadS [DescribeAttackStatistics]
$creadList :: ReadS [DescribeAttackStatistics]
readsPrec :: Int -> ReadS DescribeAttackStatistics
$creadsPrec :: Int -> ReadS DescribeAttackStatistics
Prelude.Read, Int -> DescribeAttackStatistics -> ShowS
[DescribeAttackStatistics] -> ShowS
DescribeAttackStatistics -> String
(Int -> DescribeAttackStatistics -> ShowS)
-> (DescribeAttackStatistics -> String)
-> ([DescribeAttackStatistics] -> ShowS)
-> Show DescribeAttackStatistics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeAttackStatistics] -> ShowS
$cshowList :: [DescribeAttackStatistics] -> ShowS
show :: DescribeAttackStatistics -> String
$cshow :: DescribeAttackStatistics -> String
showsPrec :: Int -> DescribeAttackStatistics -> ShowS
$cshowsPrec :: Int -> DescribeAttackStatistics -> ShowS
Prelude.Show, (forall x.
 DescribeAttackStatistics -> Rep DescribeAttackStatistics x)
-> (forall x.
    Rep DescribeAttackStatistics x -> DescribeAttackStatistics)
-> Generic DescribeAttackStatistics
forall x.
Rep DescribeAttackStatistics x -> DescribeAttackStatistics
forall x.
DescribeAttackStatistics -> Rep DescribeAttackStatistics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeAttackStatistics x -> DescribeAttackStatistics
$cfrom :: forall x.
DescribeAttackStatistics -> Rep DescribeAttackStatistics x
Prelude.Generic)

-- |
-- Create a value of 'DescribeAttackStatistics' 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.
newDescribeAttackStatistics ::
  DescribeAttackStatistics
newDescribeAttackStatistics :: DescribeAttackStatistics
newDescribeAttackStatistics =
  DescribeAttackStatistics
DescribeAttackStatistics'

instance Core.AWSRequest DescribeAttackStatistics where
  type
    AWSResponse DescribeAttackStatistics =
      DescribeAttackStatisticsResponse
  request :: DescribeAttackStatistics -> Request DescribeAttackStatistics
request = Service
-> DescribeAttackStatistics -> Request DescribeAttackStatistics
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DescribeAttackStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeAttackStatistics)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DescribeAttackStatistics))
-> Logger
-> Service
-> Proxy DescribeAttackStatistics
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse DescribeAttackStatistics)))
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 ->
          Int
-> TimeRange
-> [AttackStatisticsDataItem]
-> DescribeAttackStatisticsResponse
DescribeAttackStatisticsResponse'
            (Int
 -> TimeRange
 -> [AttackStatisticsDataItem]
 -> DescribeAttackStatisticsResponse)
-> Either String Int
-> Either
     String
     (TimeRange
      -> [AttackStatisticsDataItem] -> DescribeAttackStatisticsResponse)
forall (f :: * -> *) a b. Functor 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))
            Either
  String
  (TimeRange
   -> [AttackStatisticsDataItem] -> DescribeAttackStatisticsResponse)
-> Either String TimeRange
-> Either
     String
     ([AttackStatisticsDataItem] -> DescribeAttackStatisticsResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Key -> Either String TimeRange
forall a. FromJSON a => Object -> Key -> Either String a
Core..:> Key
"TimeRange")
            Either
  String
  ([AttackStatisticsDataItem] -> DescribeAttackStatisticsResponse)
-> Either String [AttackStatisticsDataItem]
-> Either String DescribeAttackStatisticsResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Key -> Either String (Maybe [AttackStatisticsDataItem])
forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Core..?> Key
"DataItems" Either String (Maybe [AttackStatisticsDataItem])
-> [AttackStatisticsDataItem]
-> Either String [AttackStatisticsDataItem]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [AttackStatisticsDataItem]
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DescribeAttackStatistics

instance Prelude.NFData DescribeAttackStatistics

instance Core.ToHeaders DescribeAttackStatistics where
  toHeaders :: DescribeAttackStatistics -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeAttackStatistics -> 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.DescribeAttackStatistics" ::
                          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 DescribeAttackStatistics where
  toJSON :: DescribeAttackStatistics -> Value
toJSON = Value -> DescribeAttackStatistics -> Value
forall a b. a -> b -> a
Prelude.const (Object -> Value
Core.Object Object
forall a. Monoid a => a
Prelude.mempty)

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

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

-- | /See:/ 'newDescribeAttackStatisticsResponse' smart constructor.
data DescribeAttackStatisticsResponse = DescribeAttackStatisticsResponse'
  { -- | The response's http status code.
    DescribeAttackStatisticsResponse -> Int
httpStatus :: Prelude.Int,
    DescribeAttackStatisticsResponse -> TimeRange
timeRange :: TimeRange,
    -- | The data that describes the attacks detected during the time period.
    DescribeAttackStatisticsResponse -> [AttackStatisticsDataItem]
dataItems :: [AttackStatisticsDataItem]
  }
  deriving (DescribeAttackStatisticsResponse
-> DescribeAttackStatisticsResponse -> Bool
(DescribeAttackStatisticsResponse
 -> DescribeAttackStatisticsResponse -> Bool)
-> (DescribeAttackStatisticsResponse
    -> DescribeAttackStatisticsResponse -> Bool)
-> Eq DescribeAttackStatisticsResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeAttackStatisticsResponse
-> DescribeAttackStatisticsResponse -> Bool
$c/= :: DescribeAttackStatisticsResponse
-> DescribeAttackStatisticsResponse -> Bool
== :: DescribeAttackStatisticsResponse
-> DescribeAttackStatisticsResponse -> Bool
$c== :: DescribeAttackStatisticsResponse
-> DescribeAttackStatisticsResponse -> Bool
Prelude.Eq, ReadPrec [DescribeAttackStatisticsResponse]
ReadPrec DescribeAttackStatisticsResponse
Int -> ReadS DescribeAttackStatisticsResponse
ReadS [DescribeAttackStatisticsResponse]
(Int -> ReadS DescribeAttackStatisticsResponse)
-> ReadS [DescribeAttackStatisticsResponse]
-> ReadPrec DescribeAttackStatisticsResponse
-> ReadPrec [DescribeAttackStatisticsResponse]
-> Read DescribeAttackStatisticsResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeAttackStatisticsResponse]
$creadListPrec :: ReadPrec [DescribeAttackStatisticsResponse]
readPrec :: ReadPrec DescribeAttackStatisticsResponse
$creadPrec :: ReadPrec DescribeAttackStatisticsResponse
readList :: ReadS [DescribeAttackStatisticsResponse]
$creadList :: ReadS [DescribeAttackStatisticsResponse]
readsPrec :: Int -> ReadS DescribeAttackStatisticsResponse
$creadsPrec :: Int -> ReadS DescribeAttackStatisticsResponse
Prelude.Read, Int -> DescribeAttackStatisticsResponse -> ShowS
[DescribeAttackStatisticsResponse] -> ShowS
DescribeAttackStatisticsResponse -> String
(Int -> DescribeAttackStatisticsResponse -> ShowS)
-> (DescribeAttackStatisticsResponse -> String)
-> ([DescribeAttackStatisticsResponse] -> ShowS)
-> Show DescribeAttackStatisticsResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeAttackStatisticsResponse] -> ShowS
$cshowList :: [DescribeAttackStatisticsResponse] -> ShowS
show :: DescribeAttackStatisticsResponse -> String
$cshow :: DescribeAttackStatisticsResponse -> String
showsPrec :: Int -> DescribeAttackStatisticsResponse -> ShowS
$cshowsPrec :: Int -> DescribeAttackStatisticsResponse -> ShowS
Prelude.Show, (forall x.
 DescribeAttackStatisticsResponse
 -> Rep DescribeAttackStatisticsResponse x)
-> (forall x.
    Rep DescribeAttackStatisticsResponse x
    -> DescribeAttackStatisticsResponse)
-> Generic DescribeAttackStatisticsResponse
forall x.
Rep DescribeAttackStatisticsResponse x
-> DescribeAttackStatisticsResponse
forall x.
DescribeAttackStatisticsResponse
-> Rep DescribeAttackStatisticsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeAttackStatisticsResponse x
-> DescribeAttackStatisticsResponse
$cfrom :: forall x.
DescribeAttackStatisticsResponse
-> Rep DescribeAttackStatisticsResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeAttackStatisticsResponse' 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:
--
-- 'httpStatus', 'describeAttackStatisticsResponse_httpStatus' - The response's http status code.
--
-- 'timeRange', 'describeAttackStatisticsResponse_timeRange' - Undocumented member.
--
-- 'dataItems', 'describeAttackStatisticsResponse_dataItems' - The data that describes the attacks detected during the time period.
newDescribeAttackStatisticsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'timeRange'
  TimeRange ->
  DescribeAttackStatisticsResponse
newDescribeAttackStatisticsResponse :: Int -> TimeRange -> DescribeAttackStatisticsResponse
newDescribeAttackStatisticsResponse
  Int
pHttpStatus_
  TimeRange
pTimeRange_ =
    DescribeAttackStatisticsResponse' :: Int
-> TimeRange
-> [AttackStatisticsDataItem]
-> DescribeAttackStatisticsResponse
DescribeAttackStatisticsResponse'
      { $sel:httpStatus:DescribeAttackStatisticsResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:timeRange:DescribeAttackStatisticsResponse' :: TimeRange
timeRange = TimeRange
pTimeRange_,
        $sel:dataItems:DescribeAttackStatisticsResponse' :: [AttackStatisticsDataItem]
dataItems = [AttackStatisticsDataItem]
forall a. Monoid a => a
Prelude.mempty
      }

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

-- | Undocumented member.
describeAttackStatisticsResponse_timeRange :: Lens.Lens' DescribeAttackStatisticsResponse TimeRange
describeAttackStatisticsResponse_timeRange :: (TimeRange -> f TimeRange)
-> DescribeAttackStatisticsResponse
-> f DescribeAttackStatisticsResponse
describeAttackStatisticsResponse_timeRange = (DescribeAttackStatisticsResponse -> TimeRange)
-> (DescribeAttackStatisticsResponse
    -> TimeRange -> DescribeAttackStatisticsResponse)
-> Lens
     DescribeAttackStatisticsResponse
     DescribeAttackStatisticsResponse
     TimeRange
     TimeRange
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAttackStatisticsResponse' {TimeRange
timeRange :: TimeRange
$sel:timeRange:DescribeAttackStatisticsResponse' :: DescribeAttackStatisticsResponse -> TimeRange
timeRange} -> TimeRange
timeRange) (\s :: DescribeAttackStatisticsResponse
s@DescribeAttackStatisticsResponse' {} TimeRange
a -> DescribeAttackStatisticsResponse
s {$sel:timeRange:DescribeAttackStatisticsResponse' :: TimeRange
timeRange = TimeRange
a} :: DescribeAttackStatisticsResponse)

-- | The data that describes the attacks detected during the time period.
describeAttackStatisticsResponse_dataItems :: Lens.Lens' DescribeAttackStatisticsResponse [AttackStatisticsDataItem]
describeAttackStatisticsResponse_dataItems :: ([AttackStatisticsDataItem] -> f [AttackStatisticsDataItem])
-> DescribeAttackStatisticsResponse
-> f DescribeAttackStatisticsResponse
describeAttackStatisticsResponse_dataItems = (DescribeAttackStatisticsResponse -> [AttackStatisticsDataItem])
-> (DescribeAttackStatisticsResponse
    -> [AttackStatisticsDataItem] -> DescribeAttackStatisticsResponse)
-> Lens
     DescribeAttackStatisticsResponse
     DescribeAttackStatisticsResponse
     [AttackStatisticsDataItem]
     [AttackStatisticsDataItem]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeAttackStatisticsResponse' {[AttackStatisticsDataItem]
dataItems :: [AttackStatisticsDataItem]
$sel:dataItems:DescribeAttackStatisticsResponse' :: DescribeAttackStatisticsResponse -> [AttackStatisticsDataItem]
dataItems} -> [AttackStatisticsDataItem]
dataItems) (\s :: DescribeAttackStatisticsResponse
s@DescribeAttackStatisticsResponse' {} [AttackStatisticsDataItem]
a -> DescribeAttackStatisticsResponse
s {$sel:dataItems:DescribeAttackStatisticsResponse' :: [AttackStatisticsDataItem]
dataItems = [AttackStatisticsDataItem]
a} :: DescribeAttackStatisticsResponse) (([AttackStatisticsDataItem] -> f [AttackStatisticsDataItem])
 -> DescribeAttackStatisticsResponse
 -> f DescribeAttackStatisticsResponse)
-> (([AttackStatisticsDataItem] -> f [AttackStatisticsDataItem])
    -> [AttackStatisticsDataItem] -> f [AttackStatisticsDataItem])
-> ([AttackStatisticsDataItem] -> f [AttackStatisticsDataItem])
-> DescribeAttackStatisticsResponse
-> f DescribeAttackStatisticsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([AttackStatisticsDataItem] -> f [AttackStatisticsDataItem])
-> [AttackStatisticsDataItem] -> f [AttackStatisticsDataItem]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance
  Prelude.NFData
    DescribeAttackStatisticsResponse