{-# 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.GetCorsPolicy
-- 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)
--
-- Returns the cross-origin resource sharing (CORS) configuration
-- information that is set for the container.
--
-- To use this operation, you must have permission to perform the
-- @MediaStore:GetCorsPolicy@ action. By default, the container owner has
-- this permission and can grant it to others.
module Amazonka.MediaStore.GetCorsPolicy
  ( -- * Creating a Request
    GetCorsPolicy (..),
    newGetCorsPolicy,

    -- * Request Lenses
    getCorsPolicy_containerName,

    -- * Destructuring the Response
    GetCorsPolicyResponse (..),
    newGetCorsPolicyResponse,

    -- * Response Lenses
    getCorsPolicyResponse_httpStatus,
    getCorsPolicyResponse_corsPolicy,
  )
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:/ 'newGetCorsPolicy' smart constructor.
data GetCorsPolicy = GetCorsPolicy'
  { -- | The name of the container that the policy is assigned to.
    GetCorsPolicy -> Text
containerName :: Prelude.Text
  }
  deriving (GetCorsPolicy -> GetCorsPolicy -> Bool
(GetCorsPolicy -> GetCorsPolicy -> Bool)
-> (GetCorsPolicy -> GetCorsPolicy -> Bool) -> Eq GetCorsPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCorsPolicy -> GetCorsPolicy -> Bool
$c/= :: GetCorsPolicy -> GetCorsPolicy -> Bool
== :: GetCorsPolicy -> GetCorsPolicy -> Bool
$c== :: GetCorsPolicy -> GetCorsPolicy -> Bool
Prelude.Eq, ReadPrec [GetCorsPolicy]
ReadPrec GetCorsPolicy
Int -> ReadS GetCorsPolicy
ReadS [GetCorsPolicy]
(Int -> ReadS GetCorsPolicy)
-> ReadS [GetCorsPolicy]
-> ReadPrec GetCorsPolicy
-> ReadPrec [GetCorsPolicy]
-> Read GetCorsPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetCorsPolicy]
$creadListPrec :: ReadPrec [GetCorsPolicy]
readPrec :: ReadPrec GetCorsPolicy
$creadPrec :: ReadPrec GetCorsPolicy
readList :: ReadS [GetCorsPolicy]
$creadList :: ReadS [GetCorsPolicy]
readsPrec :: Int -> ReadS GetCorsPolicy
$creadsPrec :: Int -> ReadS GetCorsPolicy
Prelude.Read, Int -> GetCorsPolicy -> ShowS
[GetCorsPolicy] -> ShowS
GetCorsPolicy -> String
(Int -> GetCorsPolicy -> ShowS)
-> (GetCorsPolicy -> String)
-> ([GetCorsPolicy] -> ShowS)
-> Show GetCorsPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCorsPolicy] -> ShowS
$cshowList :: [GetCorsPolicy] -> ShowS
show :: GetCorsPolicy -> String
$cshow :: GetCorsPolicy -> String
showsPrec :: Int -> GetCorsPolicy -> ShowS
$cshowsPrec :: Int -> GetCorsPolicy -> ShowS
Prelude.Show, (forall x. GetCorsPolicy -> Rep GetCorsPolicy x)
-> (forall x. Rep GetCorsPolicy x -> GetCorsPolicy)
-> Generic GetCorsPolicy
forall x. Rep GetCorsPolicy x -> GetCorsPolicy
forall x. GetCorsPolicy -> Rep GetCorsPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCorsPolicy x -> GetCorsPolicy
$cfrom :: forall x. GetCorsPolicy -> Rep GetCorsPolicy x
Prelude.Generic)

-- |
-- Create a value of 'GetCorsPolicy' 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', 'getCorsPolicy_containerName' - The name of the container that the policy is assigned to.
newGetCorsPolicy ::
  -- | 'containerName'
  Prelude.Text ->
  GetCorsPolicy
newGetCorsPolicy :: Text -> GetCorsPolicy
newGetCorsPolicy Text
pContainerName_ =
  GetCorsPolicy' :: Text -> GetCorsPolicy
GetCorsPolicy' {$sel:containerName:GetCorsPolicy' :: Text
containerName = Text
pContainerName_}

-- | The name of the container that the policy is assigned to.
getCorsPolicy_containerName :: Lens.Lens' GetCorsPolicy Prelude.Text
getCorsPolicy_containerName :: (Text -> f Text) -> GetCorsPolicy -> f GetCorsPolicy
getCorsPolicy_containerName = (GetCorsPolicy -> Text)
-> (GetCorsPolicy -> Text -> GetCorsPolicy)
-> Lens GetCorsPolicy GetCorsPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCorsPolicy' {Text
containerName :: Text
$sel:containerName:GetCorsPolicy' :: GetCorsPolicy -> Text
containerName} -> Text
containerName) (\s :: GetCorsPolicy
s@GetCorsPolicy' {} Text
a -> GetCorsPolicy
s {$sel:containerName:GetCorsPolicy' :: Text
containerName = Text
a} :: GetCorsPolicy)

instance Core.AWSRequest GetCorsPolicy where
  type
    AWSResponse GetCorsPolicy =
      GetCorsPolicyResponse
  request :: GetCorsPolicy -> Request GetCorsPolicy
request = Service -> GetCorsPolicy -> Request GetCorsPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetCorsPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCorsPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetCorsPolicy))
-> Logger
-> Service
-> Proxy GetCorsPolicy
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetCorsPolicy)))
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 -> NonEmpty CorsRule -> GetCorsPolicyResponse
GetCorsPolicyResponse'
            (Int -> NonEmpty CorsRule -> GetCorsPolicyResponse)
-> Either String Int
-> Either String (NonEmpty CorsRule -> GetCorsPolicyResponse)
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 (NonEmpty CorsRule -> GetCorsPolicyResponse)
-> Either String (NonEmpty CorsRule)
-> Either String GetCorsPolicyResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (NonEmpty CorsRule)
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"CorsPolicy")
      )

instance Prelude.Hashable GetCorsPolicy

instance Prelude.NFData GetCorsPolicy

instance Core.ToHeaders GetCorsPolicy where
  toHeaders :: GetCorsPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetCorsPolicy -> 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.GetCorsPolicy" ::
                          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 GetCorsPolicy where
  toJSON :: GetCorsPolicy -> Value
toJSON GetCorsPolicy' {Text
containerName :: Text
$sel:containerName:GetCorsPolicy' :: GetCorsPolicy -> 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 GetCorsPolicy where
  toPath :: GetCorsPolicy -> ByteString
toPath = ByteString -> GetCorsPolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'GetCorsPolicyResponse' 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', 'getCorsPolicyResponse_httpStatus' - The response's http status code.
--
-- 'corsPolicy', 'getCorsPolicyResponse_corsPolicy' - The CORS policy assigned to the container.
newGetCorsPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'corsPolicy'
  Prelude.NonEmpty CorsRule ->
  GetCorsPolicyResponse
newGetCorsPolicyResponse :: Int -> NonEmpty CorsRule -> GetCorsPolicyResponse
newGetCorsPolicyResponse Int
pHttpStatus_ NonEmpty CorsRule
pCorsPolicy_ =
  GetCorsPolicyResponse' :: Int -> NonEmpty CorsRule -> GetCorsPolicyResponse
GetCorsPolicyResponse'
    { $sel:httpStatus:GetCorsPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:corsPolicy:GetCorsPolicyResponse' :: NonEmpty CorsRule
corsPolicy = Tagged (NonEmpty CorsRule) (Identity (NonEmpty CorsRule))
-> Tagged (NonEmpty CorsRule) (Identity (NonEmpty CorsRule))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty CorsRule) (Identity (NonEmpty CorsRule))
 -> Tagged (NonEmpty CorsRule) (Identity (NonEmpty CorsRule)))
-> NonEmpty CorsRule -> NonEmpty CorsRule
forall t b. AReview t b -> b -> t
Lens.# NonEmpty CorsRule
pCorsPolicy_
    }

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

-- | The CORS policy assigned to the container.
getCorsPolicyResponse_corsPolicy :: Lens.Lens' GetCorsPolicyResponse (Prelude.NonEmpty CorsRule)
getCorsPolicyResponse_corsPolicy :: (NonEmpty CorsRule -> f (NonEmpty CorsRule))
-> GetCorsPolicyResponse -> f GetCorsPolicyResponse
getCorsPolicyResponse_corsPolicy = (GetCorsPolicyResponse -> NonEmpty CorsRule)
-> (GetCorsPolicyResponse
    -> NonEmpty CorsRule -> GetCorsPolicyResponse)
-> Lens
     GetCorsPolicyResponse
     GetCorsPolicyResponse
     (NonEmpty CorsRule)
     (NonEmpty CorsRule)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCorsPolicyResponse' {NonEmpty CorsRule
corsPolicy :: NonEmpty CorsRule
$sel:corsPolicy:GetCorsPolicyResponse' :: GetCorsPolicyResponse -> NonEmpty CorsRule
corsPolicy} -> NonEmpty CorsRule
corsPolicy) (\s :: GetCorsPolicyResponse
s@GetCorsPolicyResponse' {} NonEmpty CorsRule
a -> GetCorsPolicyResponse
s {$sel:corsPolicy:GetCorsPolicyResponse' :: NonEmpty CorsRule
corsPolicy = NonEmpty CorsRule
a} :: GetCorsPolicyResponse) ((NonEmpty CorsRule -> f (NonEmpty CorsRule))
 -> GetCorsPolicyResponse -> f GetCorsPolicyResponse)
-> ((NonEmpty CorsRule -> f (NonEmpty CorsRule))
    -> NonEmpty CorsRule -> f (NonEmpty CorsRule))
-> (NonEmpty CorsRule -> f (NonEmpty CorsRule))
-> GetCorsPolicyResponse
-> f GetCorsPolicyResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty CorsRule -> f (NonEmpty CorsRule))
-> NonEmpty CorsRule -> f (NonEmpty CorsRule)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Prelude.NFData GetCorsPolicyResponse