{-# 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.SetDataRetrievalPolicy
-- 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 sets and then enacts a data retrieval policy in the
-- region specified in the PUT request. You can set one policy per region
-- for an AWS account. The policy is enacted within a few minutes of a
-- successful PUT operation.
--
-- The set policy operation does not affect retrieval jobs that were in
-- progress before the policy was enacted. For more information about data
-- retrieval policies, see
-- <https://docs.aws.amazon.com/amazonglacier/latest/dev/data-retrieval-policy.html Amazon Glacier Data Retrieval Policies>.
module Amazonka.Glacier.SetDataRetrievalPolicy
  ( -- * Creating a Request
    SetDataRetrievalPolicy (..),
    newSetDataRetrievalPolicy,

    -- * Request Lenses
    setDataRetrievalPolicy_policy,
    setDataRetrievalPolicy_accountId,

    -- * Destructuring the Response
    SetDataRetrievalPolicyResponse (..),
    newSetDataRetrievalPolicyResponse,
  )
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

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

-- |
-- Create a value of 'SetDataRetrievalPolicy' 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', 'setDataRetrievalPolicy_policy' - The data retrieval policy in JSON format.
--
-- 'accountId', 'setDataRetrievalPolicy_accountId' - The @AccountId@ value is the AWS account ID. This value must match the
-- AWS account ID associated with the credentials used to sign the request.
-- You can either specify an AWS account ID or optionally a single \'@-@\'
-- (hyphen), in which case Amazon Glacier uses the AWS account ID
-- associated with the credentials used to sign the request. If you specify
-- your account ID, do not include any hyphens (\'-\') in the ID.
newSetDataRetrievalPolicy ::
  -- | 'accountId'
  Prelude.Text ->
  SetDataRetrievalPolicy
newSetDataRetrievalPolicy :: Text -> SetDataRetrievalPolicy
newSetDataRetrievalPolicy Text
pAccountId_ =
  SetDataRetrievalPolicy' :: Maybe DataRetrievalPolicy -> Text -> SetDataRetrievalPolicy
SetDataRetrievalPolicy'
    { $sel:policy:SetDataRetrievalPolicy' :: Maybe DataRetrievalPolicy
policy = Maybe DataRetrievalPolicy
forall a. Maybe a
Prelude.Nothing,
      $sel:accountId:SetDataRetrievalPolicy' :: Text
accountId = Text
pAccountId_
    }

-- | The data retrieval policy in JSON format.
setDataRetrievalPolicy_policy :: Lens.Lens' SetDataRetrievalPolicy (Prelude.Maybe DataRetrievalPolicy)
setDataRetrievalPolicy_policy :: (Maybe DataRetrievalPolicy -> f (Maybe DataRetrievalPolicy))
-> SetDataRetrievalPolicy -> f SetDataRetrievalPolicy
setDataRetrievalPolicy_policy = (SetDataRetrievalPolicy -> Maybe DataRetrievalPolicy)
-> (SetDataRetrievalPolicy
    -> Maybe DataRetrievalPolicy -> SetDataRetrievalPolicy)
-> Lens
     SetDataRetrievalPolicy
     SetDataRetrievalPolicy
     (Maybe DataRetrievalPolicy)
     (Maybe DataRetrievalPolicy)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDataRetrievalPolicy' {Maybe DataRetrievalPolicy
policy :: Maybe DataRetrievalPolicy
$sel:policy:SetDataRetrievalPolicy' :: SetDataRetrievalPolicy -> Maybe DataRetrievalPolicy
policy} -> Maybe DataRetrievalPolicy
policy) (\s :: SetDataRetrievalPolicy
s@SetDataRetrievalPolicy' {} Maybe DataRetrievalPolicy
a -> SetDataRetrievalPolicy
s {$sel:policy:SetDataRetrievalPolicy' :: Maybe DataRetrievalPolicy
policy = Maybe DataRetrievalPolicy
a} :: SetDataRetrievalPolicy)

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

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

instance Prelude.Hashable SetDataRetrievalPolicy

instance Prelude.NFData SetDataRetrievalPolicy

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

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

instance Core.ToPath SetDataRetrievalPolicy where
  toPath :: SetDataRetrievalPolicy -> ByteString
toPath SetDataRetrievalPolicy' {Maybe DataRetrievalPolicy
Text
accountId :: Text
policy :: Maybe DataRetrievalPolicy
$sel:accountId:SetDataRetrievalPolicy' :: SetDataRetrievalPolicy -> Text
$sel:policy:SetDataRetrievalPolicy' :: SetDataRetrievalPolicy -> Maybe DataRetrievalPolicy
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
accountId,
        ByteString
"/policies/data-retrieval"
      ]

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

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

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

instance
  Prelude.NFData
    SetDataRetrievalPolicyResponse