{-# 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.GuardDuty.GetFindings
-- 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 Amazon GuardDuty findings specified by finding IDs.
module Amazonka.GuardDuty.GetFindings
  ( -- * Creating a Request
    GetFindings (..),
    newGetFindings,

    -- * Request Lenses
    getFindings_sortCriteria,
    getFindings_detectorId,
    getFindings_findingIds,

    -- * Destructuring the Response
    GetFindingsResponse (..),
    newGetFindingsResponse,

    -- * Response Lenses
    getFindingsResponse_httpStatus,
    getFindingsResponse_findings,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.GuardDuty.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:/ 'newGetFindings' smart constructor.
data GetFindings = GetFindings'
  { -- | Represents the criteria used for sorting findings.
    GetFindings -> Maybe SortCriteria
sortCriteria :: Prelude.Maybe SortCriteria,
    -- | The ID of the detector that specifies the GuardDuty service whose
    -- findings you want to retrieve.
    GetFindings -> Text
detectorId :: Prelude.Text,
    -- | The IDs of the findings that you want to retrieve.
    GetFindings -> [Text]
findingIds :: [Prelude.Text]
  }
  deriving (GetFindings -> GetFindings -> Bool
(GetFindings -> GetFindings -> Bool)
-> (GetFindings -> GetFindings -> Bool) -> Eq GetFindings
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFindings -> GetFindings -> Bool
$c/= :: GetFindings -> GetFindings -> Bool
== :: GetFindings -> GetFindings -> Bool
$c== :: GetFindings -> GetFindings -> Bool
Prelude.Eq, ReadPrec [GetFindings]
ReadPrec GetFindings
Int -> ReadS GetFindings
ReadS [GetFindings]
(Int -> ReadS GetFindings)
-> ReadS [GetFindings]
-> ReadPrec GetFindings
-> ReadPrec [GetFindings]
-> Read GetFindings
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFindings]
$creadListPrec :: ReadPrec [GetFindings]
readPrec :: ReadPrec GetFindings
$creadPrec :: ReadPrec GetFindings
readList :: ReadS [GetFindings]
$creadList :: ReadS [GetFindings]
readsPrec :: Int -> ReadS GetFindings
$creadsPrec :: Int -> ReadS GetFindings
Prelude.Read, Int -> GetFindings -> ShowS
[GetFindings] -> ShowS
GetFindings -> String
(Int -> GetFindings -> ShowS)
-> (GetFindings -> String)
-> ([GetFindings] -> ShowS)
-> Show GetFindings
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFindings] -> ShowS
$cshowList :: [GetFindings] -> ShowS
show :: GetFindings -> String
$cshow :: GetFindings -> String
showsPrec :: Int -> GetFindings -> ShowS
$cshowsPrec :: Int -> GetFindings -> ShowS
Prelude.Show, (forall x. GetFindings -> Rep GetFindings x)
-> (forall x. Rep GetFindings x -> GetFindings)
-> Generic GetFindings
forall x. Rep GetFindings x -> GetFindings
forall x. GetFindings -> Rep GetFindings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFindings x -> GetFindings
$cfrom :: forall x. GetFindings -> Rep GetFindings x
Prelude.Generic)

-- |
-- Create a value of 'GetFindings' 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:
--
-- 'sortCriteria', 'getFindings_sortCriteria' - Represents the criteria used for sorting findings.
--
-- 'detectorId', 'getFindings_detectorId' - The ID of the detector that specifies the GuardDuty service whose
-- findings you want to retrieve.
--
-- 'findingIds', 'getFindings_findingIds' - The IDs of the findings that you want to retrieve.
newGetFindings ::
  -- | 'detectorId'
  Prelude.Text ->
  GetFindings
newGetFindings :: Text -> GetFindings
newGetFindings Text
pDetectorId_ =
  GetFindings' :: Maybe SortCriteria -> Text -> [Text] -> GetFindings
GetFindings'
    { $sel:sortCriteria:GetFindings' :: Maybe SortCriteria
sortCriteria = Maybe SortCriteria
forall a. Maybe a
Prelude.Nothing,
      $sel:detectorId:GetFindings' :: Text
detectorId = Text
pDetectorId_,
      $sel:findingIds:GetFindings' :: [Text]
findingIds = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Represents the criteria used for sorting findings.
getFindings_sortCriteria :: Lens.Lens' GetFindings (Prelude.Maybe SortCriteria)
getFindings_sortCriteria :: (Maybe SortCriteria -> f (Maybe SortCriteria))
-> GetFindings -> f GetFindings
getFindings_sortCriteria = (GetFindings -> Maybe SortCriteria)
-> (GetFindings -> Maybe SortCriteria -> GetFindings)
-> Lens
     GetFindings GetFindings (Maybe SortCriteria) (Maybe SortCriteria)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindings' {Maybe SortCriteria
sortCriteria :: Maybe SortCriteria
$sel:sortCriteria:GetFindings' :: GetFindings -> Maybe SortCriteria
sortCriteria} -> Maybe SortCriteria
sortCriteria) (\s :: GetFindings
s@GetFindings' {} Maybe SortCriteria
a -> GetFindings
s {$sel:sortCriteria:GetFindings' :: Maybe SortCriteria
sortCriteria = Maybe SortCriteria
a} :: GetFindings)

-- | The ID of the detector that specifies the GuardDuty service whose
-- findings you want to retrieve.
getFindings_detectorId :: Lens.Lens' GetFindings Prelude.Text
getFindings_detectorId :: (Text -> f Text) -> GetFindings -> f GetFindings
getFindings_detectorId = (GetFindings -> Text)
-> (GetFindings -> Text -> GetFindings)
-> Lens GetFindings GetFindings Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindings' {Text
detectorId :: Text
$sel:detectorId:GetFindings' :: GetFindings -> Text
detectorId} -> Text
detectorId) (\s :: GetFindings
s@GetFindings' {} Text
a -> GetFindings
s {$sel:detectorId:GetFindings' :: Text
detectorId = Text
a} :: GetFindings)

-- | The IDs of the findings that you want to retrieve.
getFindings_findingIds :: Lens.Lens' GetFindings [Prelude.Text]
getFindings_findingIds :: ([Text] -> f [Text]) -> GetFindings -> f GetFindings
getFindings_findingIds = (GetFindings -> [Text])
-> (GetFindings -> [Text] -> GetFindings)
-> Lens GetFindings GetFindings [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindings' {[Text]
findingIds :: [Text]
$sel:findingIds:GetFindings' :: GetFindings -> [Text]
findingIds} -> [Text]
findingIds) (\s :: GetFindings
s@GetFindings' {} [Text]
a -> GetFindings
s {$sel:findingIds:GetFindings' :: [Text]
findingIds = [Text]
a} :: GetFindings) (([Text] -> f [Text]) -> GetFindings -> f GetFindings)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GetFindings
-> f GetFindings
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable GetFindings

instance Prelude.NFData GetFindings

instance Core.ToHeaders GetFindings where
  toHeaders :: GetFindings -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetFindings -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 GetFindings where
  toJSON :: GetFindings -> Value
toJSON GetFindings' {[Text]
Maybe SortCriteria
Text
findingIds :: [Text]
detectorId :: Text
sortCriteria :: Maybe SortCriteria
$sel:findingIds:GetFindings' :: GetFindings -> [Text]
$sel:detectorId:GetFindings' :: GetFindings -> Text
$sel:sortCriteria:GetFindings' :: GetFindings -> Maybe SortCriteria
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"sortCriteria" Text -> SortCriteria -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (SortCriteria -> Pair) -> Maybe SortCriteria -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe SortCriteria
sortCriteria,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"findingIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
findingIds)
          ]
      )

instance Core.ToPath GetFindings where
  toPath :: GetFindings -> ByteString
toPath GetFindings' {[Text]
Maybe SortCriteria
Text
findingIds :: [Text]
detectorId :: Text
sortCriteria :: Maybe SortCriteria
$sel:findingIds:GetFindings' :: GetFindings -> [Text]
$sel:detectorId:GetFindings' :: GetFindings -> Text
$sel:sortCriteria:GetFindings' :: GetFindings -> Maybe SortCriteria
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/detector/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
detectorId, ByteString
"/findings/get"]

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

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

-- |
-- Create a value of 'GetFindingsResponse' 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', 'getFindingsResponse_httpStatus' - The response's http status code.
--
-- 'findings', 'getFindingsResponse_findings' - A list of findings.
newGetFindingsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetFindingsResponse
newGetFindingsResponse :: Int -> GetFindingsResponse
newGetFindingsResponse Int
pHttpStatus_ =
  GetFindingsResponse' :: Int -> [Finding] -> GetFindingsResponse
GetFindingsResponse'
    { $sel:httpStatus:GetFindingsResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:findings:GetFindingsResponse' :: [Finding]
findings = [Finding]
forall a. Monoid a => a
Prelude.mempty
    }

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

-- | A list of findings.
getFindingsResponse_findings :: Lens.Lens' GetFindingsResponse [Finding]
getFindingsResponse_findings :: ([Finding] -> f [Finding])
-> GetFindingsResponse -> f GetFindingsResponse
getFindingsResponse_findings = (GetFindingsResponse -> [Finding])
-> (GetFindingsResponse -> [Finding] -> GetFindingsResponse)
-> Lens GetFindingsResponse GetFindingsResponse [Finding] [Finding]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindingsResponse' {[Finding]
findings :: [Finding]
$sel:findings:GetFindingsResponse' :: GetFindingsResponse -> [Finding]
findings} -> [Finding]
findings) (\s :: GetFindingsResponse
s@GetFindingsResponse' {} [Finding]
a -> GetFindingsResponse
s {$sel:findings:GetFindingsResponse' :: [Finding]
findings = [Finding]
a} :: GetFindingsResponse) (([Finding] -> f [Finding])
 -> GetFindingsResponse -> f GetFindingsResponse)
-> (([Finding] -> f [Finding]) -> [Finding] -> f [Finding])
-> ([Finding] -> f [Finding])
-> GetFindingsResponse
-> f GetFindingsResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Finding] -> f [Finding]) -> [Finding] -> f [Finding]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData GetFindingsResponse