{-# 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.Inspector.DescribeFindings
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Describes the findings that are specified by the ARNs of the findings.
module Amazonka.Inspector.DescribeFindings
  ( -- * Creating a Request
    DescribeFindings (..),
    newDescribeFindings,

    -- * Request Lenses
    describeFindings_locale,
    describeFindings_findingArns,

    -- * Destructuring the Response
    DescribeFindingsResponse (..),
    newDescribeFindingsResponse,

    -- * Response Lenses
    describeFindingsResponse_httpStatus,
    describeFindingsResponse_findings,
    describeFindingsResponse_failedItems,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Inspector.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDescribeFindings' smart constructor.
data DescribeFindings = DescribeFindings'
  { -- | The locale into which you want to translate a finding description,
    -- recommendation, and the short description that identifies the finding.
    DescribeFindings -> Maybe Locale
locale :: Prelude.Maybe Locale,
    -- | The ARN that specifies the finding that you want to describe.
    DescribeFindings -> NonEmpty Text
findingArns :: Prelude.NonEmpty Prelude.Text
  }
  deriving (DescribeFindings -> DescribeFindings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeFindings -> DescribeFindings -> Bool
$c/= :: DescribeFindings -> DescribeFindings -> Bool
== :: DescribeFindings -> DescribeFindings -> Bool
$c== :: DescribeFindings -> DescribeFindings -> Bool
Prelude.Eq, ReadPrec [DescribeFindings]
ReadPrec DescribeFindings
Int -> ReadS DescribeFindings
ReadS [DescribeFindings]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeFindings]
$creadListPrec :: ReadPrec [DescribeFindings]
readPrec :: ReadPrec DescribeFindings
$creadPrec :: ReadPrec DescribeFindings
readList :: ReadS [DescribeFindings]
$creadList :: ReadS [DescribeFindings]
readsPrec :: Int -> ReadS DescribeFindings
$creadsPrec :: Int -> ReadS DescribeFindings
Prelude.Read, Int -> DescribeFindings -> ShowS
[DescribeFindings] -> ShowS
DescribeFindings -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeFindings] -> ShowS
$cshowList :: [DescribeFindings] -> ShowS
show :: DescribeFindings -> String
$cshow :: DescribeFindings -> String
showsPrec :: Int -> DescribeFindings -> ShowS
$cshowsPrec :: Int -> DescribeFindings -> ShowS
Prelude.Show, forall x. Rep DescribeFindings x -> DescribeFindings
forall x. DescribeFindings -> Rep DescribeFindings x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeFindings x -> DescribeFindings
$cfrom :: forall x. DescribeFindings -> Rep DescribeFindings x
Prelude.Generic)

-- |
-- Create a value of 'DescribeFindings' 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:
--
-- 'locale', 'describeFindings_locale' - The locale into which you want to translate a finding description,
-- recommendation, and the short description that identifies the finding.
--
-- 'findingArns', 'describeFindings_findingArns' - The ARN that specifies the finding that you want to describe.
newDescribeFindings ::
  -- | 'findingArns'
  Prelude.NonEmpty Prelude.Text ->
  DescribeFindings
newDescribeFindings :: NonEmpty Text -> DescribeFindings
newDescribeFindings NonEmpty Text
pFindingArns_ =
  DescribeFindings'
    { $sel:locale:DescribeFindings' :: Maybe Locale
locale = forall a. Maybe a
Prelude.Nothing,
      $sel:findingArns:DescribeFindings' :: NonEmpty Text
findingArns = forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pFindingArns_
    }

-- | The locale into which you want to translate a finding description,
-- recommendation, and the short description that identifies the finding.
describeFindings_locale :: Lens.Lens' DescribeFindings (Prelude.Maybe Locale)
describeFindings_locale :: Lens' DescribeFindings (Maybe Locale)
describeFindings_locale = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFindings' {Maybe Locale
locale :: Maybe Locale
$sel:locale:DescribeFindings' :: DescribeFindings -> Maybe Locale
locale} -> Maybe Locale
locale) (\s :: DescribeFindings
s@DescribeFindings' {} Maybe Locale
a -> DescribeFindings
s {$sel:locale:DescribeFindings' :: Maybe Locale
locale = Maybe Locale
a} :: DescribeFindings)

-- | The ARN that specifies the finding that you want to describe.
describeFindings_findingArns :: Lens.Lens' DescribeFindings (Prelude.NonEmpty Prelude.Text)
describeFindings_findingArns :: Lens' DescribeFindings (NonEmpty Text)
describeFindings_findingArns = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFindings' {NonEmpty Text
findingArns :: NonEmpty Text
$sel:findingArns:DescribeFindings' :: DescribeFindings -> NonEmpty Text
findingArns} -> NonEmpty Text
findingArns) (\s :: DescribeFindings
s@DescribeFindings' {} NonEmpty Text
a -> DescribeFindings
s {$sel:findingArns:DescribeFindings' :: NonEmpty Text
findingArns = NonEmpty Text
a} :: DescribeFindings) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest DescribeFindings where
  type
    AWSResponse DescribeFindings =
      DescribeFindingsResponse
  request :: (Service -> Service)
-> DescribeFindings -> Request DescribeFindings
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy DescribeFindings
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DescribeFindings)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int
-> [Finding]
-> HashMap Text FailedItemDetails
-> DescribeFindingsResponse
DescribeFindingsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"findings" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"failedItems" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable DescribeFindings where
  hashWithSalt :: Int -> DescribeFindings -> Int
hashWithSalt Int
_salt DescribeFindings' {Maybe Locale
NonEmpty Text
findingArns :: NonEmpty Text
locale :: Maybe Locale
$sel:findingArns:DescribeFindings' :: DescribeFindings -> NonEmpty Text
$sel:locale:DescribeFindings' :: DescribeFindings -> Maybe Locale
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Locale
locale
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` NonEmpty Text
findingArns

instance Prelude.NFData DescribeFindings where
  rnf :: DescribeFindings -> ()
rnf DescribeFindings' {Maybe Locale
NonEmpty Text
findingArns :: NonEmpty Text
locale :: Maybe Locale
$sel:findingArns:DescribeFindings' :: DescribeFindings -> NonEmpty Text
$sel:locale:DescribeFindings' :: DescribeFindings -> Maybe Locale
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Locale
locale
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf NonEmpty Text
findingArns

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

instance Data.ToJSON DescribeFindings where
  toJSON :: DescribeFindings -> Value
toJSON DescribeFindings' {Maybe Locale
NonEmpty Text
findingArns :: NonEmpty Text
locale :: Maybe Locale
$sel:findingArns:DescribeFindings' :: DescribeFindings -> NonEmpty Text
$sel:locale:DescribeFindings' :: DescribeFindings -> Maybe Locale
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"locale" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Locale
locale,
            forall a. a -> Maybe a
Prelude.Just (Key
"findingArns" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= NonEmpty Text
findingArns)
          ]
      )

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

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

-- | /See:/ 'newDescribeFindingsResponse' smart constructor.
data DescribeFindingsResponse = DescribeFindingsResponse'
  { -- | The response's http status code.
    DescribeFindingsResponse -> Int
httpStatus :: Prelude.Int,
    -- | Information about the finding.
    DescribeFindingsResponse -> [Finding]
findings :: [Finding],
    -- | Finding details that cannot be described. An error code is provided for
    -- each failed item.
    DescribeFindingsResponse -> HashMap Text FailedItemDetails
failedItems :: Prelude.HashMap Prelude.Text FailedItemDetails
  }
  deriving (DescribeFindingsResponse -> DescribeFindingsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeFindingsResponse -> DescribeFindingsResponse -> Bool
$c/= :: DescribeFindingsResponse -> DescribeFindingsResponse -> Bool
== :: DescribeFindingsResponse -> DescribeFindingsResponse -> Bool
$c== :: DescribeFindingsResponse -> DescribeFindingsResponse -> Bool
Prelude.Eq, ReadPrec [DescribeFindingsResponse]
ReadPrec DescribeFindingsResponse
Int -> ReadS DescribeFindingsResponse
ReadS [DescribeFindingsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeFindingsResponse]
$creadListPrec :: ReadPrec [DescribeFindingsResponse]
readPrec :: ReadPrec DescribeFindingsResponse
$creadPrec :: ReadPrec DescribeFindingsResponse
readList :: ReadS [DescribeFindingsResponse]
$creadList :: ReadS [DescribeFindingsResponse]
readsPrec :: Int -> ReadS DescribeFindingsResponse
$creadsPrec :: Int -> ReadS DescribeFindingsResponse
Prelude.Read, Int -> DescribeFindingsResponse -> ShowS
[DescribeFindingsResponse] -> ShowS
DescribeFindingsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeFindingsResponse] -> ShowS
$cshowList :: [DescribeFindingsResponse] -> ShowS
show :: DescribeFindingsResponse -> String
$cshow :: DescribeFindingsResponse -> String
showsPrec :: Int -> DescribeFindingsResponse -> ShowS
$cshowsPrec :: Int -> DescribeFindingsResponse -> ShowS
Prelude.Show, forall x.
Rep DescribeFindingsResponse x -> DescribeFindingsResponse
forall x.
DescribeFindingsResponse -> Rep DescribeFindingsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeFindingsResponse x -> DescribeFindingsResponse
$cfrom :: forall x.
DescribeFindingsResponse -> Rep DescribeFindingsResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeFindingsResponse' 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', 'describeFindingsResponse_httpStatus' - The response's http status code.
--
-- 'findings', 'describeFindingsResponse_findings' - Information about the finding.
--
-- 'failedItems', 'describeFindingsResponse_failedItems' - Finding details that cannot be described. An error code is provided for
-- each failed item.
newDescribeFindingsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeFindingsResponse
newDescribeFindingsResponse :: Int -> DescribeFindingsResponse
newDescribeFindingsResponse Int
pHttpStatus_ =
  DescribeFindingsResponse'
    { $sel:httpStatus:DescribeFindingsResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:findings:DescribeFindingsResponse' :: [Finding]
findings = forall a. Monoid a => a
Prelude.mempty,
      $sel:failedItems:DescribeFindingsResponse' :: HashMap Text FailedItemDetails
failedItems = forall a. Monoid a => a
Prelude.mempty
    }

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

-- | Information about the finding.
describeFindingsResponse_findings :: Lens.Lens' DescribeFindingsResponse [Finding]
describeFindingsResponse_findings :: Lens' DescribeFindingsResponse [Finding]
describeFindingsResponse_findings = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFindingsResponse' {[Finding]
findings :: [Finding]
$sel:findings:DescribeFindingsResponse' :: DescribeFindingsResponse -> [Finding]
findings} -> [Finding]
findings) (\s :: DescribeFindingsResponse
s@DescribeFindingsResponse' {} [Finding]
a -> DescribeFindingsResponse
s {$sel:findings:DescribeFindingsResponse' :: [Finding]
findings = [Finding]
a} :: DescribeFindingsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Finding details that cannot be described. An error code is provided for
-- each failed item.
describeFindingsResponse_failedItems :: Lens.Lens' DescribeFindingsResponse (Prelude.HashMap Prelude.Text FailedItemDetails)
describeFindingsResponse_failedItems :: Lens' DescribeFindingsResponse (HashMap Text FailedItemDetails)
describeFindingsResponse_failedItems = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeFindingsResponse' {HashMap Text FailedItemDetails
failedItems :: HashMap Text FailedItemDetails
$sel:failedItems:DescribeFindingsResponse' :: DescribeFindingsResponse -> HashMap Text FailedItemDetails
failedItems} -> HashMap Text FailedItemDetails
failedItems) (\s :: DescribeFindingsResponse
s@DescribeFindingsResponse' {} HashMap Text FailedItemDetails
a -> DescribeFindingsResponse
s {$sel:failedItems:DescribeFindingsResponse' :: HashMap Text FailedItemDetails
failedItems = HashMap Text FailedItemDetails
a} :: DescribeFindingsResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData DescribeFindingsResponse where
  rnf :: DescribeFindingsResponse -> ()
rnf DescribeFindingsResponse' {Int
[Finding]
HashMap Text FailedItemDetails
failedItems :: HashMap Text FailedItemDetails
findings :: [Finding]
httpStatus :: Int
$sel:failedItems:DescribeFindingsResponse' :: DescribeFindingsResponse -> HashMap Text FailedItemDetails
$sel:findings:DescribeFindingsResponse' :: DescribeFindingsResponse -> [Finding]
$sel:httpStatus:DescribeFindingsResponse' :: DescribeFindingsResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Finding]
findings
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf HashMap Text FailedItemDetails
failedItems