{-# 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.Backup.PutBackupVaultAccessPolicy
-- 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)
--
-- Sets a resource-based policy that is used to manage access permissions
-- on the target backup vault. Requires a backup vault name and an access
-- policy document in JSON format.
module Amazonka.Backup.PutBackupVaultAccessPolicy
  ( -- * Creating a Request
    PutBackupVaultAccessPolicy (..),
    newPutBackupVaultAccessPolicy,

    -- * Request Lenses
    putBackupVaultAccessPolicy_policy,
    putBackupVaultAccessPolicy_backupVaultName,

    -- * Destructuring the Response
    PutBackupVaultAccessPolicyResponse (..),
    newPutBackupVaultAccessPolicyResponse,
  )
where

import Amazonka.Backup.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newPutBackupVaultAccessPolicy' smart constructor.
data PutBackupVaultAccessPolicy = PutBackupVaultAccessPolicy'
  { -- | The backup vault access policy document in JSON format.
    PutBackupVaultAccessPolicy -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The name of a logical container where backups are stored. Backup vaults
    -- are identified by names that are unique to the account used to create
    -- them and the Amazon Web Services Region where they are created. They
    -- consist of lowercase letters, numbers, and hyphens.
    PutBackupVaultAccessPolicy -> Text
backupVaultName :: Prelude.Text
  }
  deriving (PutBackupVaultAccessPolicy -> PutBackupVaultAccessPolicy -> Bool
(PutBackupVaultAccessPolicy -> PutBackupVaultAccessPolicy -> Bool)
-> (PutBackupVaultAccessPolicy
    -> PutBackupVaultAccessPolicy -> Bool)
-> Eq PutBackupVaultAccessPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutBackupVaultAccessPolicy -> PutBackupVaultAccessPolicy -> Bool
$c/= :: PutBackupVaultAccessPolicy -> PutBackupVaultAccessPolicy -> Bool
== :: PutBackupVaultAccessPolicy -> PutBackupVaultAccessPolicy -> Bool
$c== :: PutBackupVaultAccessPolicy -> PutBackupVaultAccessPolicy -> Bool
Prelude.Eq, ReadPrec [PutBackupVaultAccessPolicy]
ReadPrec PutBackupVaultAccessPolicy
Int -> ReadS PutBackupVaultAccessPolicy
ReadS [PutBackupVaultAccessPolicy]
(Int -> ReadS PutBackupVaultAccessPolicy)
-> ReadS [PutBackupVaultAccessPolicy]
-> ReadPrec PutBackupVaultAccessPolicy
-> ReadPrec [PutBackupVaultAccessPolicy]
-> Read PutBackupVaultAccessPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutBackupVaultAccessPolicy]
$creadListPrec :: ReadPrec [PutBackupVaultAccessPolicy]
readPrec :: ReadPrec PutBackupVaultAccessPolicy
$creadPrec :: ReadPrec PutBackupVaultAccessPolicy
readList :: ReadS [PutBackupVaultAccessPolicy]
$creadList :: ReadS [PutBackupVaultAccessPolicy]
readsPrec :: Int -> ReadS PutBackupVaultAccessPolicy
$creadsPrec :: Int -> ReadS PutBackupVaultAccessPolicy
Prelude.Read, Int -> PutBackupVaultAccessPolicy -> ShowS
[PutBackupVaultAccessPolicy] -> ShowS
PutBackupVaultAccessPolicy -> String
(Int -> PutBackupVaultAccessPolicy -> ShowS)
-> (PutBackupVaultAccessPolicy -> String)
-> ([PutBackupVaultAccessPolicy] -> ShowS)
-> Show PutBackupVaultAccessPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutBackupVaultAccessPolicy] -> ShowS
$cshowList :: [PutBackupVaultAccessPolicy] -> ShowS
show :: PutBackupVaultAccessPolicy -> String
$cshow :: PutBackupVaultAccessPolicy -> String
showsPrec :: Int -> PutBackupVaultAccessPolicy -> ShowS
$cshowsPrec :: Int -> PutBackupVaultAccessPolicy -> ShowS
Prelude.Show, (forall x.
 PutBackupVaultAccessPolicy -> Rep PutBackupVaultAccessPolicy x)
-> (forall x.
    Rep PutBackupVaultAccessPolicy x -> PutBackupVaultAccessPolicy)
-> Generic PutBackupVaultAccessPolicy
forall x.
Rep PutBackupVaultAccessPolicy x -> PutBackupVaultAccessPolicy
forall x.
PutBackupVaultAccessPolicy -> Rep PutBackupVaultAccessPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutBackupVaultAccessPolicy x -> PutBackupVaultAccessPolicy
$cfrom :: forall x.
PutBackupVaultAccessPolicy -> Rep PutBackupVaultAccessPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutBackupVaultAccessPolicy' 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:
--
-- 'policy', 'putBackupVaultAccessPolicy_policy' - The backup vault access policy document in JSON format.
--
-- 'backupVaultName', 'putBackupVaultAccessPolicy_backupVaultName' - The name of a logical container where backups are stored. Backup vaults
-- are identified by names that are unique to the account used to create
-- them and the Amazon Web Services Region where they are created. They
-- consist of lowercase letters, numbers, and hyphens.
newPutBackupVaultAccessPolicy ::
  -- | 'backupVaultName'
  Prelude.Text ->
  PutBackupVaultAccessPolicy
newPutBackupVaultAccessPolicy :: Text -> PutBackupVaultAccessPolicy
newPutBackupVaultAccessPolicy Text
pBackupVaultName_ =
  PutBackupVaultAccessPolicy' :: Maybe Text -> Text -> PutBackupVaultAccessPolicy
PutBackupVaultAccessPolicy'
    { $sel:policy:PutBackupVaultAccessPolicy' :: Maybe Text
policy =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:backupVaultName:PutBackupVaultAccessPolicy' :: Text
backupVaultName = Text
pBackupVaultName_
    }

-- | The backup vault access policy document in JSON format.
putBackupVaultAccessPolicy_policy :: Lens.Lens' PutBackupVaultAccessPolicy (Prelude.Maybe Prelude.Text)
putBackupVaultAccessPolicy_policy :: (Maybe Text -> f (Maybe Text))
-> PutBackupVaultAccessPolicy -> f PutBackupVaultAccessPolicy
putBackupVaultAccessPolicy_policy = (PutBackupVaultAccessPolicy -> Maybe Text)
-> (PutBackupVaultAccessPolicy
    -> Maybe Text -> PutBackupVaultAccessPolicy)
-> Lens
     PutBackupVaultAccessPolicy
     PutBackupVaultAccessPolicy
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutBackupVaultAccessPolicy' {Maybe Text
policy :: Maybe Text
$sel:policy:PutBackupVaultAccessPolicy' :: PutBackupVaultAccessPolicy -> Maybe Text
policy} -> Maybe Text
policy) (\s :: PutBackupVaultAccessPolicy
s@PutBackupVaultAccessPolicy' {} Maybe Text
a -> PutBackupVaultAccessPolicy
s {$sel:policy:PutBackupVaultAccessPolicy' :: Maybe Text
policy = Maybe Text
a} :: PutBackupVaultAccessPolicy)

-- | The name of a logical container where backups are stored. Backup vaults
-- are identified by names that are unique to the account used to create
-- them and the Amazon Web Services Region where they are created. They
-- consist of lowercase letters, numbers, and hyphens.
putBackupVaultAccessPolicy_backupVaultName :: Lens.Lens' PutBackupVaultAccessPolicy Prelude.Text
putBackupVaultAccessPolicy_backupVaultName :: (Text -> f Text)
-> PutBackupVaultAccessPolicy -> f PutBackupVaultAccessPolicy
putBackupVaultAccessPolicy_backupVaultName = (PutBackupVaultAccessPolicy -> Text)
-> (PutBackupVaultAccessPolicy
    -> Text -> PutBackupVaultAccessPolicy)
-> Lens
     PutBackupVaultAccessPolicy PutBackupVaultAccessPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutBackupVaultAccessPolicy' {Text
backupVaultName :: Text
$sel:backupVaultName:PutBackupVaultAccessPolicy' :: PutBackupVaultAccessPolicy -> Text
backupVaultName} -> Text
backupVaultName) (\s :: PutBackupVaultAccessPolicy
s@PutBackupVaultAccessPolicy' {} Text
a -> PutBackupVaultAccessPolicy
s {$sel:backupVaultName:PutBackupVaultAccessPolicy' :: Text
backupVaultName = Text
a} :: PutBackupVaultAccessPolicy)

instance Core.AWSRequest PutBackupVaultAccessPolicy where
  type
    AWSResponse PutBackupVaultAccessPolicy =
      PutBackupVaultAccessPolicyResponse
  request :: PutBackupVaultAccessPolicy -> Request PutBackupVaultAccessPolicy
request = Service
-> PutBackupVaultAccessPolicy -> Request PutBackupVaultAccessPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutBackupVaultAccessPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutBackupVaultAccessPolicy)))
response =
    AWSResponse PutBackupVaultAccessPolicy
-> Logger
-> Service
-> Proxy PutBackupVaultAccessPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutBackupVaultAccessPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      AWSResponse PutBackupVaultAccessPolicy
PutBackupVaultAccessPolicyResponse
PutBackupVaultAccessPolicyResponse'

instance Prelude.Hashable PutBackupVaultAccessPolicy

instance Prelude.NFData PutBackupVaultAccessPolicy

instance Core.ToHeaders PutBackupVaultAccessPolicy where
  toHeaders :: PutBackupVaultAccessPolicy -> [Header]
toHeaders =
    [Header] -> PutBackupVaultAccessPolicy -> [Header]
forall a b. a -> b -> a
Prelude.const
      ( [[Header]] -> [Header]
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> [Header]
forall a. ToHeader a => HeaderName -> a -> [Header]
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON PutBackupVaultAccessPolicy where
  toJSON :: PutBackupVaultAccessPolicy -> Value
toJSON PutBackupVaultAccessPolicy' {Maybe Text
Text
backupVaultName :: Text
policy :: Maybe Text
$sel:backupVaultName:PutBackupVaultAccessPolicy' :: PutBackupVaultAccessPolicy -> Text
$sel:policy:PutBackupVaultAccessPolicy' :: PutBackupVaultAccessPolicy -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Policy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
policy]
      )

instance Core.ToPath PutBackupVaultAccessPolicy where
  toPath :: PutBackupVaultAccessPolicy -> ByteString
toPath PutBackupVaultAccessPolicy' {Maybe Text
Text
backupVaultName :: Text
policy :: Maybe Text
$sel:backupVaultName:PutBackupVaultAccessPolicy' :: PutBackupVaultAccessPolicy -> Text
$sel:policy:PutBackupVaultAccessPolicy' :: PutBackupVaultAccessPolicy -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/backup-vaults/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
backupVaultName,
        ByteString
"/access-policy"
      ]

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

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

-- |
-- Create a value of 'PutBackupVaultAccessPolicyResponse' 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.
newPutBackupVaultAccessPolicyResponse ::
  PutBackupVaultAccessPolicyResponse
newPutBackupVaultAccessPolicyResponse :: PutBackupVaultAccessPolicyResponse
newPutBackupVaultAccessPolicyResponse =
  PutBackupVaultAccessPolicyResponse
PutBackupVaultAccessPolicyResponse'

instance
  Prelude.NFData
    PutBackupVaultAccessPolicyResponse