{-# 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.PutContainerPolicy
-- 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)
--
-- Creates an access policy for the specified container to restrict the
-- users and clients that can access it. 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>.
--
-- For this release of the REST API, you can create only one policy for a
-- container. If you enter @PutContainerPolicy@ twice, the second command
-- modifies the existing policy.
module Amazonka.MediaStore.PutContainerPolicy
  ( -- * Creating a Request
    PutContainerPolicy (..),
    newPutContainerPolicy,

    -- * Request Lenses
    putContainerPolicy_containerName,
    putContainerPolicy_policy,

    -- * Destructuring the Response
    PutContainerPolicyResponse (..),
    newPutContainerPolicyResponse,

    -- * Response Lenses
    putContainerPolicyResponse_httpStatus,
  )
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:/ 'newPutContainerPolicy' smart constructor.
data PutContainerPolicy = PutContainerPolicy'
  { -- | The name of the container.
    PutContainerPolicy -> Text
containerName :: Prelude.Text,
    -- | The contents of the policy, which includes the following:
    --
    -- -   One @Version@ tag
    --
    -- -   One @Statement@ tag that contains the standard tags for the policy.
    PutContainerPolicy -> Text
policy :: Prelude.Text
  }
  deriving (PutContainerPolicy -> PutContainerPolicy -> Bool
(PutContainerPolicy -> PutContainerPolicy -> Bool)
-> (PutContainerPolicy -> PutContainerPolicy -> Bool)
-> Eq PutContainerPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutContainerPolicy -> PutContainerPolicy -> Bool
$c/= :: PutContainerPolicy -> PutContainerPolicy -> Bool
== :: PutContainerPolicy -> PutContainerPolicy -> Bool
$c== :: PutContainerPolicy -> PutContainerPolicy -> Bool
Prelude.Eq, ReadPrec [PutContainerPolicy]
ReadPrec PutContainerPolicy
Int -> ReadS PutContainerPolicy
ReadS [PutContainerPolicy]
(Int -> ReadS PutContainerPolicy)
-> ReadS [PutContainerPolicy]
-> ReadPrec PutContainerPolicy
-> ReadPrec [PutContainerPolicy]
-> Read PutContainerPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutContainerPolicy]
$creadListPrec :: ReadPrec [PutContainerPolicy]
readPrec :: ReadPrec PutContainerPolicy
$creadPrec :: ReadPrec PutContainerPolicy
readList :: ReadS [PutContainerPolicy]
$creadList :: ReadS [PutContainerPolicy]
readsPrec :: Int -> ReadS PutContainerPolicy
$creadsPrec :: Int -> ReadS PutContainerPolicy
Prelude.Read, Int -> PutContainerPolicy -> ShowS
[PutContainerPolicy] -> ShowS
PutContainerPolicy -> String
(Int -> PutContainerPolicy -> ShowS)
-> (PutContainerPolicy -> String)
-> ([PutContainerPolicy] -> ShowS)
-> Show PutContainerPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutContainerPolicy] -> ShowS
$cshowList :: [PutContainerPolicy] -> ShowS
show :: PutContainerPolicy -> String
$cshow :: PutContainerPolicy -> String
showsPrec :: Int -> PutContainerPolicy -> ShowS
$cshowsPrec :: Int -> PutContainerPolicy -> ShowS
Prelude.Show, (forall x. PutContainerPolicy -> Rep PutContainerPolicy x)
-> (forall x. Rep PutContainerPolicy x -> PutContainerPolicy)
-> Generic PutContainerPolicy
forall x. Rep PutContainerPolicy x -> PutContainerPolicy
forall x. PutContainerPolicy -> Rep PutContainerPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutContainerPolicy x -> PutContainerPolicy
$cfrom :: forall x. PutContainerPolicy -> Rep PutContainerPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutContainerPolicy' 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', 'putContainerPolicy_containerName' - The name of the container.
--
-- 'policy', 'putContainerPolicy_policy' - The contents of the policy, which includes the following:
--
-- -   One @Version@ tag
--
-- -   One @Statement@ tag that contains the standard tags for the policy.
newPutContainerPolicy ::
  -- | 'containerName'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  PutContainerPolicy
newPutContainerPolicy :: Text -> Text -> PutContainerPolicy
newPutContainerPolicy Text
pContainerName_ Text
pPolicy_ =
  PutContainerPolicy' :: Text -> Text -> PutContainerPolicy
PutContainerPolicy'
    { $sel:containerName:PutContainerPolicy' :: Text
containerName =
        Text
pContainerName_,
      $sel:policy:PutContainerPolicy' :: Text
policy = Text
pPolicy_
    }

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

-- | The contents of the policy, which includes the following:
--
-- -   One @Version@ tag
--
-- -   One @Statement@ tag that contains the standard tags for the policy.
putContainerPolicy_policy :: Lens.Lens' PutContainerPolicy Prelude.Text
putContainerPolicy_policy :: (Text -> f Text) -> PutContainerPolicy -> f PutContainerPolicy
putContainerPolicy_policy = (PutContainerPolicy -> Text)
-> (PutContainerPolicy -> Text -> PutContainerPolicy)
-> Lens PutContainerPolicy PutContainerPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutContainerPolicy' {Text
policy :: Text
$sel:policy:PutContainerPolicy' :: PutContainerPolicy -> Text
policy} -> Text
policy) (\s :: PutContainerPolicy
s@PutContainerPolicy' {} Text
a -> PutContainerPolicy
s {$sel:policy:PutContainerPolicy' :: Text
policy = Text
a} :: PutContainerPolicy)

instance Core.AWSRequest PutContainerPolicy where
  type
    AWSResponse PutContainerPolicy =
      PutContainerPolicyResponse
  request :: PutContainerPolicy -> Request PutContainerPolicy
request = Service -> PutContainerPolicy -> Request PutContainerPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutContainerPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutContainerPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse PutContainerPolicy))
-> Logger
-> Service
-> Proxy PutContainerPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutContainerPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> PutContainerPolicyResponse
PutContainerPolicyResponse'
            (Int -> PutContainerPolicyResponse)
-> Either String Int -> Either String PutContainerPolicyResponse
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))
      )

instance Prelude.Hashable PutContainerPolicy

instance Prelude.NFData PutContainerPolicy

instance Core.ToHeaders PutContainerPolicy where
  toHeaders :: PutContainerPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutContainerPolicy -> 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.PutContainerPolicy" ::
                          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 PutContainerPolicy where
  toJSON :: PutContainerPolicy -> Value
toJSON PutContainerPolicy' {Text
policy :: Text
containerName :: Text
$sel:policy:PutContainerPolicy' :: PutContainerPolicy -> Text
$sel:containerName:PutContainerPolicy' :: PutContainerPolicy -> 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),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Policy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policy)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutContainerPolicyResponse' 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', 'putContainerPolicyResponse_httpStatus' - The response's http status code.
newPutContainerPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutContainerPolicyResponse
newPutContainerPolicyResponse :: Int -> PutContainerPolicyResponse
newPutContainerPolicyResponse Int
pHttpStatus_ =
  PutContainerPolicyResponse' :: Int -> PutContainerPolicyResponse
PutContainerPolicyResponse'
    { $sel:httpStatus:PutContainerPolicyResponse' :: Int
httpStatus =
        Int
pHttpStatus_
    }

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

instance Prelude.NFData PutContainerPolicyResponse