{-# 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.Glacier.SetVaultAccessPolicy
-- 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)
--
-- This operation configures an access policy for a vault and will
-- overwrite an existing policy. To configure a vault access policy, send a
-- PUT request to the @access-policy@ subresource of the vault. An access
-- policy is specific to a vault and is also called a vault subresource.
-- You can set one access policy per vault and the policy can be up to 20
-- KB in size. For more information about vault access policies, see
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/vault-access-policy.html Amazon Glacier Access Control with Vault Access Policies>.
module Amazonka.Glacier.SetVaultAccessPolicy
  ( -- * Creating a Request
    SetVaultAccessPolicy (..),
    newSetVaultAccessPolicy,

    -- * Request Lenses
    setVaultAccessPolicy_policy,
    setVaultAccessPolicy_accountId,
    setVaultAccessPolicy_vaultName,

    -- * Destructuring the Response
    SetVaultAccessPolicyResponse (..),
    newSetVaultAccessPolicyResponse,
  )
where

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

-- | SetVaultAccessPolicy input.
--
-- /See:/ 'newSetVaultAccessPolicy' smart constructor.
data SetVaultAccessPolicy = SetVaultAccessPolicy'
  { -- | The vault access policy as a JSON string.
    SetVaultAccessPolicy -> Maybe VaultAccessPolicy
policy :: Prelude.Maybe VaultAccessPolicy,
    -- | The @AccountId@ value is the AWS account ID of the account that owns the
    -- vault. You can either specify an AWS account ID or optionally a single
    -- \'@-@\' (hyphen), in which case Amazon S3 Glacier uses the AWS account
    -- ID associated with the credentials used to sign the request. If you use
    -- an account ID, do not include any hyphens (\'-\') in the ID.
    SetVaultAccessPolicy -> Text
accountId :: Prelude.Text,
    -- | The name of the vault.
    SetVaultAccessPolicy -> Text
vaultName :: Prelude.Text
  }
  deriving (SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool
(SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool)
-> (SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool)
-> Eq SetVaultAccessPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool
$c/= :: SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool
== :: SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool
$c== :: SetVaultAccessPolicy -> SetVaultAccessPolicy -> Bool
Prelude.Eq, ReadPrec [SetVaultAccessPolicy]
ReadPrec SetVaultAccessPolicy
Int -> ReadS SetVaultAccessPolicy
ReadS [SetVaultAccessPolicy]
(Int -> ReadS SetVaultAccessPolicy)
-> ReadS [SetVaultAccessPolicy]
-> ReadPrec SetVaultAccessPolicy
-> ReadPrec [SetVaultAccessPolicy]
-> Read SetVaultAccessPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetVaultAccessPolicy]
$creadListPrec :: ReadPrec [SetVaultAccessPolicy]
readPrec :: ReadPrec SetVaultAccessPolicy
$creadPrec :: ReadPrec SetVaultAccessPolicy
readList :: ReadS [SetVaultAccessPolicy]
$creadList :: ReadS [SetVaultAccessPolicy]
readsPrec :: Int -> ReadS SetVaultAccessPolicy
$creadsPrec :: Int -> ReadS SetVaultAccessPolicy
Prelude.Read, Int -> SetVaultAccessPolicy -> ShowS
[SetVaultAccessPolicy] -> ShowS
SetVaultAccessPolicy -> String
(Int -> SetVaultAccessPolicy -> ShowS)
-> (SetVaultAccessPolicy -> String)
-> ([SetVaultAccessPolicy] -> ShowS)
-> Show SetVaultAccessPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetVaultAccessPolicy] -> ShowS
$cshowList :: [SetVaultAccessPolicy] -> ShowS
show :: SetVaultAccessPolicy -> String
$cshow :: SetVaultAccessPolicy -> String
showsPrec :: Int -> SetVaultAccessPolicy -> ShowS
$cshowsPrec :: Int -> SetVaultAccessPolicy -> ShowS
Prelude.Show, (forall x. SetVaultAccessPolicy -> Rep SetVaultAccessPolicy x)
-> (forall x. Rep SetVaultAccessPolicy x -> SetVaultAccessPolicy)
-> Generic SetVaultAccessPolicy
forall x. Rep SetVaultAccessPolicy x -> SetVaultAccessPolicy
forall x. SetVaultAccessPolicy -> Rep SetVaultAccessPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetVaultAccessPolicy x -> SetVaultAccessPolicy
$cfrom :: forall x. SetVaultAccessPolicy -> Rep SetVaultAccessPolicy x
Prelude.Generic)

-- |
-- Create a value of 'SetVaultAccessPolicy' 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', 'setVaultAccessPolicy_policy' - The vault access policy as a JSON string.
--
-- 'accountId', 'setVaultAccessPolicy_accountId' - The @AccountId@ value is the AWS account ID of the account that owns the
-- vault. You can either specify an AWS account ID or optionally a single
-- \'@-@\' (hyphen), in which case Amazon S3 Glacier uses the AWS account
-- ID associated with the credentials used to sign the request. If you use
-- an account ID, do not include any hyphens (\'-\') in the ID.
--
-- 'vaultName', 'setVaultAccessPolicy_vaultName' - The name of the vault.
newSetVaultAccessPolicy ::
  -- | 'accountId'
  Prelude.Text ->
  -- | 'vaultName'
  Prelude.Text ->
  SetVaultAccessPolicy
newSetVaultAccessPolicy :: Text -> Text -> SetVaultAccessPolicy
newSetVaultAccessPolicy Text
pAccountId_ Text
pVaultName_ =
  SetVaultAccessPolicy' :: Maybe VaultAccessPolicy -> Text -> Text -> SetVaultAccessPolicy
SetVaultAccessPolicy'
    { $sel:policy:SetVaultAccessPolicy' :: Maybe VaultAccessPolicy
policy = Maybe VaultAccessPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:accountId:SetVaultAccessPolicy' :: Text
accountId = Text
pAccountId_,
      $sel:vaultName:SetVaultAccessPolicy' :: Text
vaultName = Text
pVaultName_
    }

-- | The vault access policy as a JSON string.
setVaultAccessPolicy_policy :: Lens.Lens' SetVaultAccessPolicy (Prelude.Maybe VaultAccessPolicy)
setVaultAccessPolicy_policy :: (Maybe VaultAccessPolicy -> f (Maybe VaultAccessPolicy))
-> SetVaultAccessPolicy -> f SetVaultAccessPolicy
setVaultAccessPolicy_policy = (SetVaultAccessPolicy -> Maybe VaultAccessPolicy)
-> (SetVaultAccessPolicy
    -> Maybe VaultAccessPolicy -> SetVaultAccessPolicy)
-> Lens
     SetVaultAccessPolicy
     SetVaultAccessPolicy
     (Maybe VaultAccessPolicy)
     (Maybe VaultAccessPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetVaultAccessPolicy' {Maybe VaultAccessPolicy
policy :: Maybe VaultAccessPolicy
$sel:policy:SetVaultAccessPolicy' :: SetVaultAccessPolicy -> Maybe VaultAccessPolicy
policy} -> Maybe VaultAccessPolicy
policy) (\s :: SetVaultAccessPolicy
s@SetVaultAccessPolicy' {} Maybe VaultAccessPolicy
a -> SetVaultAccessPolicy
s {$sel:policy:SetVaultAccessPolicy' :: Maybe VaultAccessPolicy
policy = Maybe VaultAccessPolicy
a} :: SetVaultAccessPolicy)

-- | The @AccountId@ value is the AWS account ID of the account that owns the
-- vault. You can either specify an AWS account ID or optionally a single
-- \'@-@\' (hyphen), in which case Amazon S3 Glacier uses the AWS account
-- ID associated with the credentials used to sign the request. If you use
-- an account ID, do not include any hyphens (\'-\') in the ID.
setVaultAccessPolicy_accountId :: Lens.Lens' SetVaultAccessPolicy Prelude.Text
setVaultAccessPolicy_accountId :: (Text -> f Text) -> SetVaultAccessPolicy -> f SetVaultAccessPolicy
setVaultAccessPolicy_accountId = (SetVaultAccessPolicy -> Text)
-> (SetVaultAccessPolicy -> Text -> SetVaultAccessPolicy)
-> Lens SetVaultAccessPolicy SetVaultAccessPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetVaultAccessPolicy' {Text
accountId :: Text
$sel:accountId:SetVaultAccessPolicy' :: SetVaultAccessPolicy -> Text
accountId} -> Text
accountId) (\s :: SetVaultAccessPolicy
s@SetVaultAccessPolicy' {} Text
a -> SetVaultAccessPolicy
s {$sel:accountId:SetVaultAccessPolicy' :: Text
accountId = Text
a} :: SetVaultAccessPolicy)

-- | The name of the vault.
setVaultAccessPolicy_vaultName :: Lens.Lens' SetVaultAccessPolicy Prelude.Text
setVaultAccessPolicy_vaultName :: (Text -> f Text) -> SetVaultAccessPolicy -> f SetVaultAccessPolicy
setVaultAccessPolicy_vaultName = (SetVaultAccessPolicy -> Text)
-> (SetVaultAccessPolicy -> Text -> SetVaultAccessPolicy)
-> Lens SetVaultAccessPolicy SetVaultAccessPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetVaultAccessPolicy' {Text
vaultName :: Text
$sel:vaultName:SetVaultAccessPolicy' :: SetVaultAccessPolicy -> Text
vaultName} -> Text
vaultName) (\s :: SetVaultAccessPolicy
s@SetVaultAccessPolicy' {} Text
a -> SetVaultAccessPolicy
s {$sel:vaultName:SetVaultAccessPolicy' :: Text
vaultName = Text
a} :: SetVaultAccessPolicy)

instance Core.AWSRequest SetVaultAccessPolicy where
  type
    AWSResponse SetVaultAccessPolicy =
      SetVaultAccessPolicyResponse
  request :: SetVaultAccessPolicy -> Request SetVaultAccessPolicy
request =
    ByteString
-> Request SetVaultAccessPolicy -> Request SetVaultAccessPolicy
forall a. ByteString -> Request a -> Request a
Request.glacierVersionHeader (Service -> ByteString
Core._serviceVersion Service
defaultService)
      (Request SetVaultAccessPolicy -> Request SetVaultAccessPolicy)
-> (SetVaultAccessPolicy -> Request SetVaultAccessPolicy)
-> SetVaultAccessPolicy
-> Request SetVaultAccessPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. Service -> SetVaultAccessPolicy -> Request SetVaultAccessPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy SetVaultAccessPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SetVaultAccessPolicy)))
response =
    AWSResponse SetVaultAccessPolicy
-> Logger
-> Service
-> Proxy SetVaultAccessPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse SetVaultAccessPolicy)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse SetVaultAccessPolicy
SetVaultAccessPolicyResponse
SetVaultAccessPolicyResponse'

instance Prelude.Hashable SetVaultAccessPolicy

instance Prelude.NFData SetVaultAccessPolicy

instance Core.ToHeaders SetVaultAccessPolicy where
  toHeaders :: SetVaultAccessPolicy -> [Header]
toHeaders = [Header] -> SetVaultAccessPolicy -> [Header]
forall a b. a -> b -> a
Prelude.const [Header]
forall a. Monoid a => a
Prelude.mempty

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

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

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

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

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

instance Prelude.NFData SetVaultAccessPolicyResponse