{-# 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-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 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.Lens as Lens
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
(GetContainerPolicy -> GetContainerPolicy -> Bool)
-> (GetContainerPolicy -> GetContainerPolicy -> Bool)
-> Eq GetContainerPolicy
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]
(Int -> ReadS GetContainerPolicy)
-> ReadS [GetContainerPolicy]
-> ReadPrec GetContainerPolicy
-> ReadPrec [GetContainerPolicy]
-> Read 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
(Int -> GetContainerPolicy -> ShowS)
-> (GetContainerPolicy -> String)
-> ([GetContainerPolicy] -> ShowS)
-> Show GetContainerPolicy
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. GetContainerPolicy -> Rep GetContainerPolicy x)
-> (forall x. Rep GetContainerPolicy x -> GetContainerPolicy)
-> Generic GetContainerPolicy
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' :: Text -> GetContainerPolicy
GetContainerPolicy'
    { $sel:containerName:GetContainerPolicy' :: Text
containerName =
        Text
pContainerName_
    }

-- | The name of the container.
getContainerPolicy_containerName :: Lens.Lens' GetContainerPolicy Prelude.Text
getContainerPolicy_containerName :: (Text -> f Text) -> GetContainerPolicy -> f GetContainerPolicy
getContainerPolicy_containerName = (GetContainerPolicy -> Text)
-> (GetContainerPolicy -> Text -> GetContainerPolicy)
-> Lens GetContainerPolicy GetContainerPolicy Text Text
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 :: GetContainerPolicy -> Request GetContainerPolicy
request = Service -> GetContainerPolicy -> Request GetContainerPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetContainerPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetContainerPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetContainerPolicy))
-> Logger
-> Service
-> Proxy GetContainerPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse GetContainerPolicy)))
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 -> Text -> GetContainerPolicyResponse
GetContainerPolicyResponse'
            (Int -> Text -> GetContainerPolicyResponse)
-> Either String Int
-> Either String (Text -> GetContainerPolicyResponse)
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 (Text -> GetContainerPolicyResponse)
-> Either String Text -> Either String GetContainerPolicyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"Policy")
      )

instance Prelude.Hashable GetContainerPolicy

instance Prelude.NFData GetContainerPolicy

instance Core.ToHeaders GetContainerPolicy where
  toHeaders :: GetContainerPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetContainerPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"MediaStore_20170901.GetContainerPolicy" ::
                          Prelude.ByteString
                      ),
            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.ToJSON GetContainerPolicy where
  toJSON :: GetContainerPolicy -> Value
toJSON GetContainerPolicy' {Text
containerName :: Text
$sel:containerName:GetContainerPolicy' :: GetContainerPolicy -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ContainerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
containerName)
          ]
      )

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

instance Core.ToQuery GetContainerPolicy where
  toQuery :: GetContainerPolicy -> QueryString
toQuery = QueryString -> GetContainerPolicy -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(GetContainerPolicyResponse -> GetContainerPolicyResponse -> Bool)
-> (GetContainerPolicyResponse
    -> GetContainerPolicyResponse -> Bool)
-> Eq GetContainerPolicyResponse
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]
(Int -> ReadS GetContainerPolicyResponse)
-> ReadS [GetContainerPolicyResponse]
-> ReadPrec GetContainerPolicyResponse
-> ReadPrec [GetContainerPolicyResponse]
-> Read 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
(Int -> GetContainerPolicyResponse -> ShowS)
-> (GetContainerPolicyResponse -> String)
-> ([GetContainerPolicyResponse] -> ShowS)
-> Show GetContainerPolicyResponse
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.
 GetContainerPolicyResponse -> Rep GetContainerPolicyResponse x)
-> (forall x.
    Rep GetContainerPolicyResponse x -> GetContainerPolicyResponse)
-> Generic GetContainerPolicyResponse
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' :: Int -> Text -> GetContainerPolicyResponse
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 :: (Int -> f Int)
-> GetContainerPolicyResponse -> f GetContainerPolicyResponse
getContainerPolicyResponse_httpStatus = (GetContainerPolicyResponse -> Int)
-> (GetContainerPolicyResponse
    -> Int -> GetContainerPolicyResponse)
-> Lens
     GetContainerPolicyResponse GetContainerPolicyResponse Int Int
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 :: (Text -> f Text)
-> GetContainerPolicyResponse -> f GetContainerPolicyResponse
getContainerPolicyResponse_policy = (GetContainerPolicyResponse -> Text)
-> (GetContainerPolicyResponse
    -> Text -> GetContainerPolicyResponse)
-> Lens
     GetContainerPolicyResponse GetContainerPolicyResponse Text Text
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