{-# 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.AccessAnalyzer.GetFinding
-- 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)
--
-- Retrieves information about the specified finding.
module Amazonka.AccessAnalyzer.GetFinding
  ( -- * Creating a Request
    GetFinding (..),
    newGetFinding,

    -- * Request Lenses
    getFinding_analyzerArn,
    getFinding_id,

    -- * Destructuring the Response
    GetFindingResponse (..),
    newGetFindingResponse,

    -- * Response Lenses
    getFindingResponse_finding,
    getFindingResponse_httpStatus,
  )
where

import Amazonka.AccessAnalyzer.Types
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

-- | Retrieves a finding.
--
-- /See:/ 'newGetFinding' smart constructor.
data GetFinding = GetFinding'
  { -- | The
    -- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-getting-started.html#permission-resources ARN of the analyzer>
    -- that generated the finding.
    GetFinding -> Text
analyzerArn :: Prelude.Text,
    -- | The ID of the finding to retrieve.
    GetFinding -> Text
id :: Prelude.Text
  }
  deriving (GetFinding -> GetFinding -> Bool
(GetFinding -> GetFinding -> Bool)
-> (GetFinding -> GetFinding -> Bool) -> Eq GetFinding
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFinding -> GetFinding -> Bool
$c/= :: GetFinding -> GetFinding -> Bool
== :: GetFinding -> GetFinding -> Bool
$c== :: GetFinding -> GetFinding -> Bool
Prelude.Eq, ReadPrec [GetFinding]
ReadPrec GetFinding
Int -> ReadS GetFinding
ReadS [GetFinding]
(Int -> ReadS GetFinding)
-> ReadS [GetFinding]
-> ReadPrec GetFinding
-> ReadPrec [GetFinding]
-> Read GetFinding
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFinding]
$creadListPrec :: ReadPrec [GetFinding]
readPrec :: ReadPrec GetFinding
$creadPrec :: ReadPrec GetFinding
readList :: ReadS [GetFinding]
$creadList :: ReadS [GetFinding]
readsPrec :: Int -> ReadS GetFinding
$creadsPrec :: Int -> ReadS GetFinding
Prelude.Read, Int -> GetFinding -> ShowS
[GetFinding] -> ShowS
GetFinding -> String
(Int -> GetFinding -> ShowS)
-> (GetFinding -> String)
-> ([GetFinding] -> ShowS)
-> Show GetFinding
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFinding] -> ShowS
$cshowList :: [GetFinding] -> ShowS
show :: GetFinding -> String
$cshow :: GetFinding -> String
showsPrec :: Int -> GetFinding -> ShowS
$cshowsPrec :: Int -> GetFinding -> ShowS
Prelude.Show, (forall x. GetFinding -> Rep GetFinding x)
-> (forall x. Rep GetFinding x -> GetFinding) -> Generic GetFinding
forall x. Rep GetFinding x -> GetFinding
forall x. GetFinding -> Rep GetFinding x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFinding x -> GetFinding
$cfrom :: forall x. GetFinding -> Rep GetFinding x
Prelude.Generic)

-- |
-- Create a value of 'GetFinding' 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:
--
-- 'analyzerArn', 'getFinding_analyzerArn' - The
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-getting-started.html#permission-resources ARN of the analyzer>
-- that generated the finding.
--
-- 'id', 'getFinding_id' - The ID of the finding to retrieve.
newGetFinding ::
  -- | 'analyzerArn'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  GetFinding
newGetFinding :: Text -> Text -> GetFinding
newGetFinding Text
pAnalyzerArn_ Text
pId_ =
  GetFinding' :: Text -> Text -> GetFinding
GetFinding' {$sel:analyzerArn:GetFinding' :: Text
analyzerArn = Text
pAnalyzerArn_, $sel:id:GetFinding' :: Text
id = Text
pId_}

-- | The
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-getting-started.html#permission-resources ARN of the analyzer>
-- that generated the finding.
getFinding_analyzerArn :: Lens.Lens' GetFinding Prelude.Text
getFinding_analyzerArn :: (Text -> f Text) -> GetFinding -> f GetFinding
getFinding_analyzerArn = (GetFinding -> Text)
-> (GetFinding -> Text -> GetFinding)
-> Lens GetFinding GetFinding Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFinding' {Text
analyzerArn :: Text
$sel:analyzerArn:GetFinding' :: GetFinding -> Text
analyzerArn} -> Text
analyzerArn) (\s :: GetFinding
s@GetFinding' {} Text
a -> GetFinding
s {$sel:analyzerArn:GetFinding' :: Text
analyzerArn = Text
a} :: GetFinding)

-- | The ID of the finding to retrieve.
getFinding_id :: Lens.Lens' GetFinding Prelude.Text
getFinding_id :: (Text -> f Text) -> GetFinding -> f GetFinding
getFinding_id = (GetFinding -> Text)
-> (GetFinding -> Text -> GetFinding)
-> Lens GetFinding GetFinding Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFinding' {Text
id :: Text
$sel:id:GetFinding' :: GetFinding -> Text
id} -> Text
id) (\s :: GetFinding
s@GetFinding' {} Text
a -> GetFinding
s {$sel:id:GetFinding' :: Text
id = Text
a} :: GetFinding)

instance Core.AWSRequest GetFinding where
  type AWSResponse GetFinding = GetFindingResponse
  request :: GetFinding -> Request GetFinding
request = Service -> GetFinding -> Request GetFinding
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetFinding
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFinding)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetFinding))
-> Logger
-> Service
-> Proxy GetFinding
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetFinding)))
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 Finding -> Int -> GetFindingResponse
GetFindingResponse'
            (Maybe Finding -> Int -> GetFindingResponse)
-> Either String (Maybe Finding)
-> Either String (Int -> GetFindingResponse)
forall (f :: * -> *) a b. Functor 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
"finding")
            Either String (Int -> GetFindingResponse)
-> Either String Int -> Either String GetFindingResponse
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 GetFinding

instance Prelude.NFData GetFinding

instance Core.ToHeaders GetFinding where
  toHeaders :: GetFinding -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetFinding -> 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.ToPath GetFinding where
  toPath :: GetFinding -> ByteString
toPath GetFinding' {Text
id :: Text
analyzerArn :: Text
$sel:id:GetFinding' :: GetFinding -> Text
$sel:analyzerArn:GetFinding' :: GetFinding -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/finding/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
id]

instance Core.ToQuery GetFinding where
  toQuery :: GetFinding -> QueryString
toQuery GetFinding' {Text
id :: Text
analyzerArn :: Text
$sel:id:GetFinding' :: GetFinding -> Text
$sel:analyzerArn:GetFinding' :: GetFinding -> Text
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"analyzerArn" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
analyzerArn]

-- | The response to the request.
--
-- /See:/ 'newGetFindingResponse' smart constructor.
data GetFindingResponse = GetFindingResponse'
  { -- | A @finding@ object that contains finding details.
    GetFindingResponse -> Maybe Finding
finding :: Prelude.Maybe Finding,
    -- | The response's http status code.
    GetFindingResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetFindingResponse -> GetFindingResponse -> Bool
(GetFindingResponse -> GetFindingResponse -> Bool)
-> (GetFindingResponse -> GetFindingResponse -> Bool)
-> Eq GetFindingResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetFindingResponse -> GetFindingResponse -> Bool
$c/= :: GetFindingResponse -> GetFindingResponse -> Bool
== :: GetFindingResponse -> GetFindingResponse -> Bool
$c== :: GetFindingResponse -> GetFindingResponse -> Bool
Prelude.Eq, ReadPrec [GetFindingResponse]
ReadPrec GetFindingResponse
Int -> ReadS GetFindingResponse
ReadS [GetFindingResponse]
(Int -> ReadS GetFindingResponse)
-> ReadS [GetFindingResponse]
-> ReadPrec GetFindingResponse
-> ReadPrec [GetFindingResponse]
-> Read GetFindingResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetFindingResponse]
$creadListPrec :: ReadPrec [GetFindingResponse]
readPrec :: ReadPrec GetFindingResponse
$creadPrec :: ReadPrec GetFindingResponse
readList :: ReadS [GetFindingResponse]
$creadList :: ReadS [GetFindingResponse]
readsPrec :: Int -> ReadS GetFindingResponse
$creadsPrec :: Int -> ReadS GetFindingResponse
Prelude.Read, Int -> GetFindingResponse -> ShowS
[GetFindingResponse] -> ShowS
GetFindingResponse -> String
(Int -> GetFindingResponse -> ShowS)
-> (GetFindingResponse -> String)
-> ([GetFindingResponse] -> ShowS)
-> Show GetFindingResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetFindingResponse] -> ShowS
$cshowList :: [GetFindingResponse] -> ShowS
show :: GetFindingResponse -> String
$cshow :: GetFindingResponse -> String
showsPrec :: Int -> GetFindingResponse -> ShowS
$cshowsPrec :: Int -> GetFindingResponse -> ShowS
Prelude.Show, (forall x. GetFindingResponse -> Rep GetFindingResponse x)
-> (forall x. Rep GetFindingResponse x -> GetFindingResponse)
-> Generic GetFindingResponse
forall x. Rep GetFindingResponse x -> GetFindingResponse
forall x. GetFindingResponse -> Rep GetFindingResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetFindingResponse x -> GetFindingResponse
$cfrom :: forall x. GetFindingResponse -> Rep GetFindingResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetFindingResponse' 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:
--
-- 'finding', 'getFindingResponse_finding' - A @finding@ object that contains finding details.
--
-- 'httpStatus', 'getFindingResponse_httpStatus' - The response's http status code.
newGetFindingResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetFindingResponse
newGetFindingResponse :: Int -> GetFindingResponse
newGetFindingResponse Int
pHttpStatus_ =
  GetFindingResponse' :: Maybe Finding -> Int -> GetFindingResponse
GetFindingResponse'
    { $sel:finding:GetFindingResponse' :: Maybe Finding
finding = Maybe Finding
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetFindingResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | A @finding@ object that contains finding details.
getFindingResponse_finding :: Lens.Lens' GetFindingResponse (Prelude.Maybe Finding)
getFindingResponse_finding :: (Maybe Finding -> f (Maybe Finding))
-> GetFindingResponse -> f GetFindingResponse
getFindingResponse_finding = (GetFindingResponse -> Maybe Finding)
-> (GetFindingResponse -> Maybe Finding -> GetFindingResponse)
-> Lens
     GetFindingResponse
     GetFindingResponse
     (Maybe Finding)
     (Maybe Finding)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetFindingResponse' {Maybe Finding
finding :: Maybe Finding
$sel:finding:GetFindingResponse' :: GetFindingResponse -> Maybe Finding
finding} -> Maybe Finding
finding) (\s :: GetFindingResponse
s@GetFindingResponse' {} Maybe Finding
a -> GetFindingResponse
s {$sel:finding:GetFindingResponse' :: Maybe Finding
finding = Maybe Finding
a} :: GetFindingResponse)

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

instance Prelude.NFData GetFindingResponse