{-# 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.GetAccessPreview
-- 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 an access preview for the specified
-- analyzer.
module Amazonka.AccessAnalyzer.GetAccessPreview
  ( -- * Creating a Request
    GetAccessPreview (..),
    newGetAccessPreview,

    -- * Request Lenses
    getAccessPreview_accessPreviewId,
    getAccessPreview_analyzerArn,

    -- * Destructuring the Response
    GetAccessPreviewResponse (..),
    newGetAccessPreviewResponse,

    -- * Response Lenses
    getAccessPreviewResponse_httpStatus,
    getAccessPreviewResponse_accessPreview,
  )
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

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

-- |
-- Create a value of 'GetAccessPreview' 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:
--
-- 'accessPreviewId', 'getAccessPreview_accessPreviewId' - The unique ID for the access preview.
--
-- 'analyzerArn', 'getAccessPreview_analyzerArn' - The
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-getting-started.html#permission-resources ARN of the analyzer>
-- used to generate the access preview.
newGetAccessPreview ::
  -- | 'accessPreviewId'
  Prelude.Text ->
  -- | 'analyzerArn'
  Prelude.Text ->
  GetAccessPreview
newGetAccessPreview :: Text -> Text -> GetAccessPreview
newGetAccessPreview Text
pAccessPreviewId_ Text
pAnalyzerArn_ =
  GetAccessPreview' :: Text -> Text -> GetAccessPreview
GetAccessPreview'
    { $sel:accessPreviewId:GetAccessPreview' :: Text
accessPreviewId =
        Text
pAccessPreviewId_,
      $sel:analyzerArn:GetAccessPreview' :: Text
analyzerArn = Text
pAnalyzerArn_
    }

-- | The unique ID for the access preview.
getAccessPreview_accessPreviewId :: Lens.Lens' GetAccessPreview Prelude.Text
getAccessPreview_accessPreviewId :: (Text -> f Text) -> GetAccessPreview -> f GetAccessPreview
getAccessPreview_accessPreviewId = (GetAccessPreview -> Text)
-> (GetAccessPreview -> Text -> GetAccessPreview)
-> Lens GetAccessPreview GetAccessPreview Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAccessPreview' {Text
accessPreviewId :: Text
$sel:accessPreviewId:GetAccessPreview' :: GetAccessPreview -> Text
accessPreviewId} -> Text
accessPreviewId) (\s :: GetAccessPreview
s@GetAccessPreview' {} Text
a -> GetAccessPreview
s {$sel:accessPreviewId:GetAccessPreview' :: Text
accessPreviewId = Text
a} :: GetAccessPreview)

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

instance Core.AWSRequest GetAccessPreview where
  type
    AWSResponse GetAccessPreview =
      GetAccessPreviewResponse
  request :: GetAccessPreview -> Request GetAccessPreview
request = Service -> GetAccessPreview -> Request GetAccessPreview
forall a. ToRequest a => Service -> a -> Request a
Request.get Service
defaultService
  response :: Logger
-> Service
-> Proxy GetAccessPreview
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAccessPreview)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetAccessPreview))
-> Logger
-> Service
-> Proxy GetAccessPreview
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetAccessPreview)))
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 -> AccessPreview -> GetAccessPreviewResponse
GetAccessPreviewResponse'
            (Int -> AccessPreview -> GetAccessPreviewResponse)
-> Either String Int
-> Either String (AccessPreview -> GetAccessPreviewResponse)
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 (AccessPreview -> GetAccessPreviewResponse)
-> Either String AccessPreview
-> Either String GetAccessPreviewResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String AccessPreview
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"accessPreview")
      )

instance Prelude.Hashable GetAccessPreview

instance Prelude.NFData GetAccessPreview

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

instance Core.ToQuery GetAccessPreview where
  toQuery :: GetAccessPreview -> QueryString
toQuery GetAccessPreview' {Text
analyzerArn :: Text
accessPreviewId :: Text
$sel:analyzerArn:GetAccessPreview' :: GetAccessPreview -> Text
$sel:accessPreviewId:GetAccessPreview' :: GetAccessPreview -> 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]

-- | /See:/ 'newGetAccessPreviewResponse' smart constructor.
data GetAccessPreviewResponse = GetAccessPreviewResponse'
  { -- | The response's http status code.
    GetAccessPreviewResponse -> Int
httpStatus :: Prelude.Int,
    -- | An object that contains information about the access preview.
    GetAccessPreviewResponse -> AccessPreview
accessPreview :: AccessPreview
  }
  deriving (GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool
(GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool)
-> (GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool)
-> Eq GetAccessPreviewResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool
$c/= :: GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool
== :: GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool
$c== :: GetAccessPreviewResponse -> GetAccessPreviewResponse -> Bool
Prelude.Eq, ReadPrec [GetAccessPreviewResponse]
ReadPrec GetAccessPreviewResponse
Int -> ReadS GetAccessPreviewResponse
ReadS [GetAccessPreviewResponse]
(Int -> ReadS GetAccessPreviewResponse)
-> ReadS [GetAccessPreviewResponse]
-> ReadPrec GetAccessPreviewResponse
-> ReadPrec [GetAccessPreviewResponse]
-> Read GetAccessPreviewResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetAccessPreviewResponse]
$creadListPrec :: ReadPrec [GetAccessPreviewResponse]
readPrec :: ReadPrec GetAccessPreviewResponse
$creadPrec :: ReadPrec GetAccessPreviewResponse
readList :: ReadS [GetAccessPreviewResponse]
$creadList :: ReadS [GetAccessPreviewResponse]
readsPrec :: Int -> ReadS GetAccessPreviewResponse
$creadsPrec :: Int -> ReadS GetAccessPreviewResponse
Prelude.Read, Int -> GetAccessPreviewResponse -> ShowS
[GetAccessPreviewResponse] -> ShowS
GetAccessPreviewResponse -> String
(Int -> GetAccessPreviewResponse -> ShowS)
-> (GetAccessPreviewResponse -> String)
-> ([GetAccessPreviewResponse] -> ShowS)
-> Show GetAccessPreviewResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetAccessPreviewResponse] -> ShowS
$cshowList :: [GetAccessPreviewResponse] -> ShowS
show :: GetAccessPreviewResponse -> String
$cshow :: GetAccessPreviewResponse -> String
showsPrec :: Int -> GetAccessPreviewResponse -> ShowS
$cshowsPrec :: Int -> GetAccessPreviewResponse -> ShowS
Prelude.Show, (forall x.
 GetAccessPreviewResponse -> Rep GetAccessPreviewResponse x)
-> (forall x.
    Rep GetAccessPreviewResponse x -> GetAccessPreviewResponse)
-> Generic GetAccessPreviewResponse
forall x.
Rep GetAccessPreviewResponse x -> GetAccessPreviewResponse
forall x.
GetAccessPreviewResponse -> Rep GetAccessPreviewResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetAccessPreviewResponse x -> GetAccessPreviewResponse
$cfrom :: forall x.
GetAccessPreviewResponse -> Rep GetAccessPreviewResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetAccessPreviewResponse' 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', 'getAccessPreviewResponse_httpStatus' - The response's http status code.
--
-- 'accessPreview', 'getAccessPreviewResponse_accessPreview' - An object that contains information about the access preview.
newGetAccessPreviewResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'accessPreview'
  AccessPreview ->
  GetAccessPreviewResponse
newGetAccessPreviewResponse :: Int -> AccessPreview -> GetAccessPreviewResponse
newGetAccessPreviewResponse
  Int
pHttpStatus_
  AccessPreview
pAccessPreview_ =
    GetAccessPreviewResponse' :: Int -> AccessPreview -> GetAccessPreviewResponse
GetAccessPreviewResponse'
      { $sel:httpStatus:GetAccessPreviewResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:accessPreview:GetAccessPreviewResponse' :: AccessPreview
accessPreview = AccessPreview
pAccessPreview_
      }

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

-- | An object that contains information about the access preview.
getAccessPreviewResponse_accessPreview :: Lens.Lens' GetAccessPreviewResponse AccessPreview
getAccessPreviewResponse_accessPreview :: (AccessPreview -> f AccessPreview)
-> GetAccessPreviewResponse -> f GetAccessPreviewResponse
getAccessPreviewResponse_accessPreview = (GetAccessPreviewResponse -> AccessPreview)
-> (GetAccessPreviewResponse
    -> AccessPreview -> GetAccessPreviewResponse)
-> Lens
     GetAccessPreviewResponse
     GetAccessPreviewResponse
     AccessPreview
     AccessPreview
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetAccessPreviewResponse' {AccessPreview
accessPreview :: AccessPreview
$sel:accessPreview:GetAccessPreviewResponse' :: GetAccessPreviewResponse -> AccessPreview
accessPreview} -> AccessPreview
accessPreview) (\s :: GetAccessPreviewResponse
s@GetAccessPreviewResponse' {} AccessPreview
a -> GetAccessPreviewResponse
s {$sel:accessPreview:GetAccessPreviewResponse' :: AccessPreview
accessPreview = AccessPreview
a} :: GetAccessPreviewResponse)

instance Prelude.NFData GetAccessPreviewResponse