{-# 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.MediaStore.GetContainerPolicy
-- 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 the access policy for the specified container. For information
-- about the data that is included in an access policy, see the
-- <https://aws.amazon.com/documentation/iam/ AWS Identity and Access Management User Guide>.
module Amazonka.MediaStore.GetContainerPolicy
  ( -- * Creating a Request
    GetContainerPolicy (..),
    newGetContainerPolicy,

    -- * Request Lenses
    getContainerPolicy_containerName,

    -- * Destructuring the Response
    GetContainerPolicyResponse (..),
    newGetContainerPolicyResponse,

    -- * Response Lenses
    getContainerPolicyResponse_httpStatus,
    getContainerPolicyResponse_policy,
  )
where

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

-- | /See:/ 'newGetContainerPolicy' smart constructor.
data GetContainerPolicy = GetContainerPolicy'
  { -- | The name of the container.
    GetContainerPolicy -> Text
containerName :: Prelude.Text
  }
  deriving (GetContainerPolicy -> GetContainerPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetContainerPolicy -> GetContainerPolicy -> Bool
$c/= :: GetContainerPolicy -> GetContainerPolicy -> Bool
== :: GetContainerPolicy -> GetContainerPolicy -> Bool
$c== :: GetContainerPolicy -> GetContainerPolicy -> Bool
Prelude.Eq, ReadPrec [GetContainerPolicy]
ReadPrec GetContainerPolicy
Int -> ReadS GetContainerPolicy
ReadS [GetContainerPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetContainerPolicy]
$creadListPrec :: ReadPrec [GetContainerPolicy]
readPrec :: ReadPrec GetContainerPolicy
$creadPrec :: ReadPrec GetContainerPolicy
readList :: ReadS [GetContainerPolicy]
$creadList :: ReadS [GetContainerPolicy]
readsPrec :: Int -> ReadS GetContainerPolicy
$creadsPrec :: Int -> ReadS GetContainerPolicy
Prelude.Read, Int -> GetContainerPolicy -> ShowS
[GetContainerPolicy] -> ShowS
GetContainerPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetContainerPolicy] -> ShowS
$cshowList :: [GetContainerPolicy] -> ShowS
show :: GetContainerPolicy -> String
$cshow :: GetContainerPolicy -> String
showsPrec :: Int -> GetContainerPolicy -> ShowS
$cshowsPrec :: Int -> GetContainerPolicy -> ShowS
Prelude.Show, forall x. Rep GetContainerPolicy x -> GetContainerPolicy
forall x. GetContainerPolicy -> Rep GetContainerPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetContainerPolicy x -> GetContainerPolicy
$cfrom :: forall x. GetContainerPolicy -> Rep GetContainerPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetContainerPolicy' 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:
--
-- 'containerName', 'getContainerPolicy_containerName' - The name of the container.
newGetContainerPolicy ::
  -- | 'containerName'
  Prelude.Text ->
  GetContainerPolicy
newGetContainerPolicy :: Text -> GetContainerPolicy
newGetContainerPolicy Text
pContainerName_ =
  GetContainerPolicy'
    { $sel:containerName:GetContainerPolicy' :: Text
containerName =
        Text
pContainerName_
    }

-- | The name of the container.
getContainerPolicy_containerName :: Lens.Lens' GetContainerPolicy Prelude.Text
getContainerPolicy_containerName :: Lens' GetContainerPolicy Text
getContainerPolicy_containerName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContainerPolicy' {Text
containerName :: Text
$sel:containerName:GetContainerPolicy' :: GetContainerPolicy -> Text
containerName} -> Text
containerName) (\s :: GetContainerPolicy
s@GetContainerPolicy' {} Text
a -> GetContainerPolicy
s {$sel:containerName:GetContainerPolicy' :: Text
containerName = Text
a} :: GetContainerPolicy)

instance Core.AWSRequest GetContainerPolicy where
  type
    AWSResponse GetContainerPolicy =
      GetContainerPolicyResponse
  request :: (Service -> Service)
-> GetContainerPolicy -> Request GetContainerPolicy
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 GetContainerPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetContainerPolicy)))
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 -> Text -> GetContainerPolicyResponse
GetContainerPolicyResponse'
            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 a
Data..:> Key
"Policy")
      )

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

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

instance Data.ToHeaders GetContainerPolicy where
  toHeaders :: GetContainerPolicy -> 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
"MediaStore_20170901.GetContainerPolicy" ::
                          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 GetContainerPolicy where
  toJSON :: GetContainerPolicy -> Value
toJSON GetContainerPolicy' {Text
containerName :: Text
$sel:containerName:GetContainerPolicy' :: GetContainerPolicy -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"ContainerName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
containerName)
          ]
      )

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

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

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

-- |
-- Create a value of 'GetContainerPolicyResponse' 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', 'getContainerPolicyResponse_httpStatus' - The response's http status code.
--
-- 'policy', 'getContainerPolicyResponse_policy' - The contents of the access policy.
newGetContainerPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'policy'
  Prelude.Text ->
  GetContainerPolicyResponse
newGetContainerPolicyResponse :: Int -> Text -> GetContainerPolicyResponse
newGetContainerPolicyResponse Int
pHttpStatus_ Text
pPolicy_ =
  GetContainerPolicyResponse'
    { $sel:httpStatus:GetContainerPolicyResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:policy:GetContainerPolicyResponse' :: Text
policy = Text
pPolicy_
    }

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

-- | The contents of the access policy.
getContainerPolicyResponse_policy :: Lens.Lens' GetContainerPolicyResponse Prelude.Text
getContainerPolicyResponse_policy :: Lens' GetContainerPolicyResponse Text
getContainerPolicyResponse_policy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetContainerPolicyResponse' {Text
policy :: Text
$sel:policy:GetContainerPolicyResponse' :: GetContainerPolicyResponse -> Text
policy} -> Text
policy) (\s :: GetContainerPolicyResponse
s@GetContainerPolicyResponse' {} Text
a -> GetContainerPolicyResponse
s {$sel:policy:GetContainerPolicyResponse' :: Text
policy = Text
a} :: GetContainerPolicyResponse)

instance Prelude.NFData GetContainerPolicyResponse where
  rnf :: GetContainerPolicyResponse -> ()
rnf GetContainerPolicyResponse' {Int
Text
policy :: Text
httpStatus :: Int
$sel:policy:GetContainerPolicyResponse' :: GetContainerPolicyResponse -> Text
$sel:httpStatus:GetContainerPolicyResponse' :: GetContainerPolicyResponse -> 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 Text
policy