{-# 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.Glue.GetResourcePolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves a specified resource policy.
module Amazonka.Glue.GetResourcePolicy
  ( -- * Creating a Request
    GetResourcePolicy (..),
    newGetResourcePolicy,

    -- * Request Lenses
    getResourcePolicy_resourceArn,

    -- * Destructuring the Response
    GetResourcePolicyResponse (..),
    newGetResourcePolicyResponse,

    -- * Response Lenses
    getResourcePolicyResponse_createTime,
    getResourcePolicyResponse_policyHash,
    getResourcePolicyResponse_policyInJson,
    getResourcePolicyResponse_updateTime,
    getResourcePolicyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newGetResourcePolicy' smart constructor.
data GetResourcePolicy = GetResourcePolicy'
  { -- | The ARN of the Glue resource for which to retrieve the resource policy.
    -- If not supplied, the Data Catalog resource policy is returned. Use
    -- @GetResourcePolicies@ to view all existing resource policies. For more
    -- information see
    -- <https://docs.aws.amazon.com/glue/latest/dg/glue-specifying-resource-arns.html Specifying Glue Resource ARNs>.
    GetResourcePolicy -> Maybe Text
resourceArn :: Prelude.Maybe Prelude.Text
  }
  deriving (GetResourcePolicy -> GetResourcePolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetResourcePolicy -> GetResourcePolicy -> Bool
$c/= :: GetResourcePolicy -> GetResourcePolicy -> Bool
== :: GetResourcePolicy -> GetResourcePolicy -> Bool
$c== :: GetResourcePolicy -> GetResourcePolicy -> Bool
Prelude.Eq, ReadPrec [GetResourcePolicy]
ReadPrec GetResourcePolicy
Int -> ReadS GetResourcePolicy
ReadS [GetResourcePolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetResourcePolicy]
$creadListPrec :: ReadPrec [GetResourcePolicy]
readPrec :: ReadPrec GetResourcePolicy
$creadPrec :: ReadPrec GetResourcePolicy
readList :: ReadS [GetResourcePolicy]
$creadList :: ReadS [GetResourcePolicy]
readsPrec :: Int -> ReadS GetResourcePolicy
$creadsPrec :: Int -> ReadS GetResourcePolicy
Prelude.Read, Int -> GetResourcePolicy -> ShowS
[GetResourcePolicy] -> ShowS
GetResourcePolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetResourcePolicy] -> ShowS
$cshowList :: [GetResourcePolicy] -> ShowS
show :: GetResourcePolicy -> String
$cshow :: GetResourcePolicy -> String
showsPrec :: Int -> GetResourcePolicy -> ShowS
$cshowsPrec :: Int -> GetResourcePolicy -> ShowS
Prelude.Show, forall x. Rep GetResourcePolicy x -> GetResourcePolicy
forall x. GetResourcePolicy -> Rep GetResourcePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetResourcePolicy x -> GetResourcePolicy
$cfrom :: forall x. GetResourcePolicy -> Rep GetResourcePolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetResourcePolicy' 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:
--
-- 'resourceArn', 'getResourcePolicy_resourceArn' - The ARN of the Glue resource for which to retrieve the resource policy.
-- If not supplied, the Data Catalog resource policy is returned. Use
-- @GetResourcePolicies@ to view all existing resource policies. For more
-- information see
-- <https://docs.aws.amazon.com/glue/latest/dg/glue-specifying-resource-arns.html Specifying Glue Resource ARNs>.
newGetResourcePolicy ::
  GetResourcePolicy
newGetResourcePolicy :: GetResourcePolicy
newGetResourcePolicy =
  GetResourcePolicy' {$sel:resourceArn:GetResourcePolicy' :: Maybe Text
resourceArn = forall a. Maybe a
Prelude.Nothing}

-- | The ARN of the Glue resource for which to retrieve the resource policy.
-- If not supplied, the Data Catalog resource policy is returned. Use
-- @GetResourcePolicies@ to view all existing resource policies. For more
-- information see
-- <https://docs.aws.amazon.com/glue/latest/dg/glue-specifying-resource-arns.html Specifying Glue Resource ARNs>.
getResourcePolicy_resourceArn :: Lens.Lens' GetResourcePolicy (Prelude.Maybe Prelude.Text)
getResourcePolicy_resourceArn :: Lens' GetResourcePolicy (Maybe Text)
getResourcePolicy_resourceArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResourcePolicy' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:GetResourcePolicy' :: GetResourcePolicy -> Maybe Text
resourceArn} -> Maybe Text
resourceArn) (\s :: GetResourcePolicy
s@GetResourcePolicy' {} Maybe Text
a -> GetResourcePolicy
s {$sel:resourceArn:GetResourcePolicy' :: Maybe Text
resourceArn = Maybe Text
a} :: GetResourcePolicy)

instance Core.AWSRequest GetResourcePolicy where
  type
    AWSResponse GetResourcePolicy =
      GetResourcePolicyResponse
  request :: (Service -> Service)
-> GetResourcePolicy -> Request GetResourcePolicy
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 GetResourcePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetResourcePolicy)))
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 ->
          Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe POSIX
-> Int
-> GetResourcePolicyResponse
GetResourcePolicyResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"CreateTime")
            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
"PolicyHash")
            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
"PolicyInJson")
            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
"UpdateTime")
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable GetResourcePolicy where
  hashWithSalt :: Int -> GetResourcePolicy -> Int
hashWithSalt Int
_salt GetResourcePolicy' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:GetResourcePolicy' :: GetResourcePolicy -> Maybe Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
resourceArn

instance Prelude.NFData GetResourcePolicy where
  rnf :: GetResourcePolicy -> ()
rnf GetResourcePolicy' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:GetResourcePolicy' :: GetResourcePolicy -> Maybe Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
resourceArn

instance Data.ToHeaders GetResourcePolicy where
  toHeaders :: GetResourcePolicy -> 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
"AWSGlue.GetResourcePolicy" :: 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 GetResourcePolicy where
  toJSON :: GetResourcePolicy -> Value
toJSON GetResourcePolicy' {Maybe Text
resourceArn :: Maybe Text
$sel:resourceArn:GetResourcePolicy' :: GetResourcePolicy -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"ResourceArn" 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 Text
resourceArn]
      )

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

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

-- | /See:/ 'newGetResourcePolicyResponse' smart constructor.
data GetResourcePolicyResponse = GetResourcePolicyResponse'
  { -- | The date and time at which the policy was created.
    GetResourcePolicyResponse -> Maybe POSIX
createTime :: Prelude.Maybe Data.POSIX,
    -- | Contains the hash value associated with this policy.
    GetResourcePolicyResponse -> Maybe Text
policyHash :: Prelude.Maybe Prelude.Text,
    -- | Contains the requested policy document, in JSON format.
    GetResourcePolicyResponse -> Maybe Text
policyInJson :: Prelude.Maybe Prelude.Text,
    -- | The date and time at which the policy was last updated.
    GetResourcePolicyResponse -> Maybe POSIX
updateTime :: Prelude.Maybe Data.POSIX,
    -- | The response's http status code.
    GetResourcePolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetResourcePolicyResponse -> GetResourcePolicyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetResourcePolicyResponse -> GetResourcePolicyResponse -> Bool
$c/= :: GetResourcePolicyResponse -> GetResourcePolicyResponse -> Bool
== :: GetResourcePolicyResponse -> GetResourcePolicyResponse -> Bool
$c== :: GetResourcePolicyResponse -> GetResourcePolicyResponse -> Bool
Prelude.Eq, ReadPrec [GetResourcePolicyResponse]
ReadPrec GetResourcePolicyResponse
Int -> ReadS GetResourcePolicyResponse
ReadS [GetResourcePolicyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetResourcePolicyResponse]
$creadListPrec :: ReadPrec [GetResourcePolicyResponse]
readPrec :: ReadPrec GetResourcePolicyResponse
$creadPrec :: ReadPrec GetResourcePolicyResponse
readList :: ReadS [GetResourcePolicyResponse]
$creadList :: ReadS [GetResourcePolicyResponse]
readsPrec :: Int -> ReadS GetResourcePolicyResponse
$creadsPrec :: Int -> ReadS GetResourcePolicyResponse
Prelude.Read, Int -> GetResourcePolicyResponse -> ShowS
[GetResourcePolicyResponse] -> ShowS
GetResourcePolicyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetResourcePolicyResponse] -> ShowS
$cshowList :: [GetResourcePolicyResponse] -> ShowS
show :: GetResourcePolicyResponse -> String
$cshow :: GetResourcePolicyResponse -> String
showsPrec :: Int -> GetResourcePolicyResponse -> ShowS
$cshowsPrec :: Int -> GetResourcePolicyResponse -> ShowS
Prelude.Show, forall x.
Rep GetResourcePolicyResponse x -> GetResourcePolicyResponse
forall x.
GetResourcePolicyResponse -> Rep GetResourcePolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep GetResourcePolicyResponse x -> GetResourcePolicyResponse
$cfrom :: forall x.
GetResourcePolicyResponse -> Rep GetResourcePolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetResourcePolicyResponse' 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:
--
-- 'createTime', 'getResourcePolicyResponse_createTime' - The date and time at which the policy was created.
--
-- 'policyHash', 'getResourcePolicyResponse_policyHash' - Contains the hash value associated with this policy.
--
-- 'policyInJson', 'getResourcePolicyResponse_policyInJson' - Contains the requested policy document, in JSON format.
--
-- 'updateTime', 'getResourcePolicyResponse_updateTime' - The date and time at which the policy was last updated.
--
-- 'httpStatus', 'getResourcePolicyResponse_httpStatus' - The response's http status code.
newGetResourcePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetResourcePolicyResponse
newGetResourcePolicyResponse :: Int -> GetResourcePolicyResponse
newGetResourcePolicyResponse Int
pHttpStatus_ =
  GetResourcePolicyResponse'
    { $sel:createTime:GetResourcePolicyResponse' :: Maybe POSIX
createTime =
        forall a. Maybe a
Prelude.Nothing,
      $sel:policyHash:GetResourcePolicyResponse' :: Maybe Text
policyHash = forall a. Maybe a
Prelude.Nothing,
      $sel:policyInJson:GetResourcePolicyResponse' :: Maybe Text
policyInJson = forall a. Maybe a
Prelude.Nothing,
      $sel:updateTime:GetResourcePolicyResponse' :: Maybe POSIX
updateTime = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetResourcePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The date and time at which the policy was created.
getResourcePolicyResponse_createTime :: Lens.Lens' GetResourcePolicyResponse (Prelude.Maybe Prelude.UTCTime)
getResourcePolicyResponse_createTime :: Lens' GetResourcePolicyResponse (Maybe UTCTime)
getResourcePolicyResponse_createTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResourcePolicyResponse' {Maybe POSIX
createTime :: Maybe POSIX
$sel:createTime:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe POSIX
createTime} -> Maybe POSIX
createTime) (\s :: GetResourcePolicyResponse
s@GetResourcePolicyResponse' {} Maybe POSIX
a -> GetResourcePolicyResponse
s {$sel:createTime:GetResourcePolicyResponse' :: Maybe POSIX
createTime = Maybe POSIX
a} :: GetResourcePolicyResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | Contains the hash value associated with this policy.
getResourcePolicyResponse_policyHash :: Lens.Lens' GetResourcePolicyResponse (Prelude.Maybe Prelude.Text)
getResourcePolicyResponse_policyHash :: Lens' GetResourcePolicyResponse (Maybe Text)
getResourcePolicyResponse_policyHash = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResourcePolicyResponse' {Maybe Text
policyHash :: Maybe Text
$sel:policyHash:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe Text
policyHash} -> Maybe Text
policyHash) (\s :: GetResourcePolicyResponse
s@GetResourcePolicyResponse' {} Maybe Text
a -> GetResourcePolicyResponse
s {$sel:policyHash:GetResourcePolicyResponse' :: Maybe Text
policyHash = Maybe Text
a} :: GetResourcePolicyResponse)

-- | Contains the requested policy document, in JSON format.
getResourcePolicyResponse_policyInJson :: Lens.Lens' GetResourcePolicyResponse (Prelude.Maybe Prelude.Text)
getResourcePolicyResponse_policyInJson :: Lens' GetResourcePolicyResponse (Maybe Text)
getResourcePolicyResponse_policyInJson = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResourcePolicyResponse' {Maybe Text
policyInJson :: Maybe Text
$sel:policyInJson:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe Text
policyInJson} -> Maybe Text
policyInJson) (\s :: GetResourcePolicyResponse
s@GetResourcePolicyResponse' {} Maybe Text
a -> GetResourcePolicyResponse
s {$sel:policyInJson:GetResourcePolicyResponse' :: Maybe Text
policyInJson = Maybe Text
a} :: GetResourcePolicyResponse)

-- | The date and time at which the policy was last updated.
getResourcePolicyResponse_updateTime :: Lens.Lens' GetResourcePolicyResponse (Prelude.Maybe Prelude.UTCTime)
getResourcePolicyResponse_updateTime :: Lens' GetResourcePolicyResponse (Maybe UTCTime)
getResourcePolicyResponse_updateTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetResourcePolicyResponse' {Maybe POSIX
updateTime :: Maybe POSIX
$sel:updateTime:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe POSIX
updateTime} -> Maybe POSIX
updateTime) (\s :: GetResourcePolicyResponse
s@GetResourcePolicyResponse' {} Maybe POSIX
a -> GetResourcePolicyResponse
s {$sel:updateTime:GetResourcePolicyResponse' :: Maybe POSIX
updateTime = Maybe POSIX
a} :: GetResourcePolicyResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

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

instance Prelude.NFData GetResourcePolicyResponse where
  rnf :: GetResourcePolicyResponse -> ()
rnf GetResourcePolicyResponse' {Int
Maybe Text
Maybe POSIX
httpStatus :: Int
updateTime :: Maybe POSIX
policyInJson :: Maybe Text
policyHash :: Maybe Text
createTime :: Maybe POSIX
$sel:httpStatus:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Int
$sel:updateTime:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe POSIX
$sel:policyInJson:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe Text
$sel:policyHash:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe Text
$sel:createTime:GetResourcePolicyResponse' :: GetResourcePolicyResponse -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyHash
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
policyInJson
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
updateTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus