{-# 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.EFS.PutLifecycleConfiguration
-- 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)
--
-- Enables lifecycle management by creating a new @LifecycleConfiguration@
-- object. A @LifecycleConfiguration@ object defines when files in an
-- Amazon EFS file system are automatically transitioned to the lower-cost
-- EFS Infrequent Access (IA) storage class. To enable EFS Intelligent
-- Tiering, set the value of @TransitionToPrimaryStorageClass@ to
-- @AFTER_1_ACCESS@. For more information, see
-- <https://docs.aws.amazon.com/efs/latest/ug/lifecycle-management-efs.html EFS Lifecycle Management>.
--
-- Each Amazon EFS file system supports one lifecycle configuration, which
-- applies to all files in the file system. If a @LifecycleConfiguration@
-- object already exists for the specified file system, a
-- @PutLifecycleConfiguration@ call modifies the existing configuration. A
-- @PutLifecycleConfiguration@ call with an empty @LifecyclePolicies@ array
-- in the request body deletes any existing @LifecycleConfiguration@ and
-- turns off lifecycle management for the file system.
--
-- In the request, specify the following:
--
-- -   The ID for the file system for which you are enabling, disabling, or
--     modifying lifecycle management.
--
-- -   A @LifecyclePolicies@ array of @LifecyclePolicy@ objects that define
--     when files are moved to the IA storage class. Amazon EFS requires
--     that each @LifecyclePolicy@ object have only have a single
--     transition, so the @LifecyclePolicies@ array needs to be structured
--     with separate @LifecyclePolicy@ objects. See the example requests in
--     the following section for more information.
--
-- This operation requires permissions for the
-- @elasticfilesystem:PutLifecycleConfiguration@ operation.
--
-- To apply a @LifecycleConfiguration@ object to an encrypted file system,
-- you need the same Key Management Service permissions as when you created
-- the encrypted file system.
module Amazonka.EFS.PutLifecycleConfiguration
  ( -- * Creating a Request
    PutLifecycleConfiguration (..),
    newPutLifecycleConfiguration,

    -- * Request Lenses
    putLifecycleConfiguration_fileSystemId,
    putLifecycleConfiguration_lifecyclePolicies,

    -- * Destructuring the Response
    LifecycleConfigurationDescription (..),
    newLifecycleConfigurationDescription,

    -- * Response Lenses
    lifecycleConfigurationDescription_lifecyclePolicies,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.EFS.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

-- | /See:/ 'newPutLifecycleConfiguration' smart constructor.
data PutLifecycleConfiguration = PutLifecycleConfiguration'
  { -- | The ID of the file system for which you are creating the
    -- @LifecycleConfiguration@ object (String).
    PutLifecycleConfiguration -> Text
fileSystemId :: Prelude.Text,
    -- | An array of @LifecyclePolicy@ objects that define the file system\'s
    -- @LifecycleConfiguration@ object. A @LifecycleConfiguration@ object
    -- informs EFS lifecycle management and intelligent tiering of the
    -- following:
    --
    -- -   When to move files in the file system from primary storage to the IA
    --     storage class.
    --
    -- -   When to move files that are in IA storage to primary storage.
    --
    -- When using the @put-lifecycle-configuration@ CLI command or the
    -- @PutLifecycleConfiguration@ API action, Amazon EFS requires that each
    -- @LifecyclePolicy@ object have only a single transition. This means that
    -- in a request body, @LifecyclePolicies@ needs to be structured as an
    -- array of @LifecyclePolicy@ objects, one object for each transition,
    -- @TransitionToIA@, @TransitionToPrimaryStorageClass@. See the example
    -- requests in the following section for more information.
    PutLifecycleConfiguration -> [LifecyclePolicy]
lifecyclePolicies :: [LifecyclePolicy]
  }
  deriving (PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool
(PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool)
-> (PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool)
-> Eq PutLifecycleConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool
$c/= :: PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool
== :: PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool
$c== :: PutLifecycleConfiguration -> PutLifecycleConfiguration -> Bool
Prelude.Eq, ReadPrec [PutLifecycleConfiguration]
ReadPrec PutLifecycleConfiguration
Int -> ReadS PutLifecycleConfiguration
ReadS [PutLifecycleConfiguration]
(Int -> ReadS PutLifecycleConfiguration)
-> ReadS [PutLifecycleConfiguration]
-> ReadPrec PutLifecycleConfiguration
-> ReadPrec [PutLifecycleConfiguration]
-> Read PutLifecycleConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutLifecycleConfiguration]
$creadListPrec :: ReadPrec [PutLifecycleConfiguration]
readPrec :: ReadPrec PutLifecycleConfiguration
$creadPrec :: ReadPrec PutLifecycleConfiguration
readList :: ReadS [PutLifecycleConfiguration]
$creadList :: ReadS [PutLifecycleConfiguration]
readsPrec :: Int -> ReadS PutLifecycleConfiguration
$creadsPrec :: Int -> ReadS PutLifecycleConfiguration
Prelude.Read, Int -> PutLifecycleConfiguration -> ShowS
[PutLifecycleConfiguration] -> ShowS
PutLifecycleConfiguration -> String
(Int -> PutLifecycleConfiguration -> ShowS)
-> (PutLifecycleConfiguration -> String)
-> ([PutLifecycleConfiguration] -> ShowS)
-> Show PutLifecycleConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutLifecycleConfiguration] -> ShowS
$cshowList :: [PutLifecycleConfiguration] -> ShowS
show :: PutLifecycleConfiguration -> String
$cshow :: PutLifecycleConfiguration -> String
showsPrec :: Int -> PutLifecycleConfiguration -> ShowS
$cshowsPrec :: Int -> PutLifecycleConfiguration -> ShowS
Prelude.Show, (forall x.
 PutLifecycleConfiguration -> Rep PutLifecycleConfiguration x)
-> (forall x.
    Rep PutLifecycleConfiguration x -> PutLifecycleConfiguration)
-> Generic PutLifecycleConfiguration
forall x.
Rep PutLifecycleConfiguration x -> PutLifecycleConfiguration
forall x.
PutLifecycleConfiguration -> Rep PutLifecycleConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutLifecycleConfiguration x -> PutLifecycleConfiguration
$cfrom :: forall x.
PutLifecycleConfiguration -> Rep PutLifecycleConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'PutLifecycleConfiguration' 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:
--
-- 'fileSystemId', 'putLifecycleConfiguration_fileSystemId' - The ID of the file system for which you are creating the
-- @LifecycleConfiguration@ object (String).
--
-- 'lifecyclePolicies', 'putLifecycleConfiguration_lifecyclePolicies' - An array of @LifecyclePolicy@ objects that define the file system\'s
-- @LifecycleConfiguration@ object. A @LifecycleConfiguration@ object
-- informs EFS lifecycle management and intelligent tiering of the
-- following:
--
-- -   When to move files in the file system from primary storage to the IA
--     storage class.
--
-- -   When to move files that are in IA storage to primary storage.
--
-- When using the @put-lifecycle-configuration@ CLI command or the
-- @PutLifecycleConfiguration@ API action, Amazon EFS requires that each
-- @LifecyclePolicy@ object have only a single transition. This means that
-- in a request body, @LifecyclePolicies@ needs to be structured as an
-- array of @LifecyclePolicy@ objects, one object for each transition,
-- @TransitionToIA@, @TransitionToPrimaryStorageClass@. See the example
-- requests in the following section for more information.
newPutLifecycleConfiguration ::
  -- | 'fileSystemId'
  Prelude.Text ->
  PutLifecycleConfiguration
newPutLifecycleConfiguration :: Text -> PutLifecycleConfiguration
newPutLifecycleConfiguration Text
pFileSystemId_ =
  PutLifecycleConfiguration' :: Text -> [LifecyclePolicy] -> PutLifecycleConfiguration
PutLifecycleConfiguration'
    { $sel:fileSystemId:PutLifecycleConfiguration' :: Text
fileSystemId =
        Text
pFileSystemId_,
      $sel:lifecyclePolicies:PutLifecycleConfiguration' :: [LifecyclePolicy]
lifecyclePolicies = [LifecyclePolicy]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The ID of the file system for which you are creating the
-- @LifecycleConfiguration@ object (String).
putLifecycleConfiguration_fileSystemId :: Lens.Lens' PutLifecycleConfiguration Prelude.Text
putLifecycleConfiguration_fileSystemId :: (Text -> f Text)
-> PutLifecycleConfiguration -> f PutLifecycleConfiguration
putLifecycleConfiguration_fileSystemId = (PutLifecycleConfiguration -> Text)
-> (PutLifecycleConfiguration -> Text -> PutLifecycleConfiguration)
-> Lens
     PutLifecycleConfiguration PutLifecycleConfiguration Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLifecycleConfiguration' {Text
fileSystemId :: Text
$sel:fileSystemId:PutLifecycleConfiguration' :: PutLifecycleConfiguration -> Text
fileSystemId} -> Text
fileSystemId) (\s :: PutLifecycleConfiguration
s@PutLifecycleConfiguration' {} Text
a -> PutLifecycleConfiguration
s {$sel:fileSystemId:PutLifecycleConfiguration' :: Text
fileSystemId = Text
a} :: PutLifecycleConfiguration)

-- | An array of @LifecyclePolicy@ objects that define the file system\'s
-- @LifecycleConfiguration@ object. A @LifecycleConfiguration@ object
-- informs EFS lifecycle management and intelligent tiering of the
-- following:
--
-- -   When to move files in the file system from primary storage to the IA
--     storage class.
--
-- -   When to move files that are in IA storage to primary storage.
--
-- When using the @put-lifecycle-configuration@ CLI command or the
-- @PutLifecycleConfiguration@ API action, Amazon EFS requires that each
-- @LifecyclePolicy@ object have only a single transition. This means that
-- in a request body, @LifecyclePolicies@ needs to be structured as an
-- array of @LifecyclePolicy@ objects, one object for each transition,
-- @TransitionToIA@, @TransitionToPrimaryStorageClass@. See the example
-- requests in the following section for more information.
putLifecycleConfiguration_lifecyclePolicies :: Lens.Lens' PutLifecycleConfiguration [LifecyclePolicy]
putLifecycleConfiguration_lifecyclePolicies :: ([LifecyclePolicy] -> f [LifecyclePolicy])
-> PutLifecycleConfiguration -> f PutLifecycleConfiguration
putLifecycleConfiguration_lifecyclePolicies = (PutLifecycleConfiguration -> [LifecyclePolicy])
-> (PutLifecycleConfiguration
    -> [LifecyclePolicy] -> PutLifecycleConfiguration)
-> Lens
     PutLifecycleConfiguration
     PutLifecycleConfiguration
     [LifecyclePolicy]
     [LifecyclePolicy]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutLifecycleConfiguration' {[LifecyclePolicy]
lifecyclePolicies :: [LifecyclePolicy]
$sel:lifecyclePolicies:PutLifecycleConfiguration' :: PutLifecycleConfiguration -> [LifecyclePolicy]
lifecyclePolicies} -> [LifecyclePolicy]
lifecyclePolicies) (\s :: PutLifecycleConfiguration
s@PutLifecycleConfiguration' {} [LifecyclePolicy]
a -> PutLifecycleConfiguration
s {$sel:lifecyclePolicies:PutLifecycleConfiguration' :: [LifecyclePolicy]
lifecyclePolicies = [LifecyclePolicy]
a} :: PutLifecycleConfiguration) (([LifecyclePolicy] -> f [LifecyclePolicy])
 -> PutLifecycleConfiguration -> f PutLifecycleConfiguration)
-> (([LifecyclePolicy] -> f [LifecyclePolicy])
    -> [LifecyclePolicy] -> f [LifecyclePolicy])
-> ([LifecyclePolicy] -> f [LifecyclePolicy])
-> PutLifecycleConfiguration
-> f PutLifecycleConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([LifecyclePolicy] -> f [LifecyclePolicy])
-> [LifecyclePolicy] -> f [LifecyclePolicy]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest PutLifecycleConfiguration where
  type
    AWSResponse PutLifecycleConfiguration =
      LifecycleConfigurationDescription
  request :: PutLifecycleConfiguration -> Request PutLifecycleConfiguration
request = Service
-> PutLifecycleConfiguration -> Request PutLifecycleConfiguration
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutLifecycleConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLifecycleConfiguration)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutLifecycleConfiguration))
-> Logger
-> Service
-> Proxy PutLifecycleConfiguration
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutLifecycleConfiguration)))
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 -> Object -> Either String LifecycleConfigurationDescription
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable PutLifecycleConfiguration

instance Prelude.NFData PutLifecycleConfiguration

instance Core.ToHeaders PutLifecycleConfiguration where
  toHeaders :: PutLifecycleConfiguration -> ResponseHeaders
toHeaders = ResponseHeaders -> PutLifecycleConfiguration -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON PutLifecycleConfiguration where
  toJSON :: PutLifecycleConfiguration -> Value
toJSON PutLifecycleConfiguration' {[LifecyclePolicy]
Text
lifecyclePolicies :: [LifecyclePolicy]
fileSystemId :: Text
$sel:lifecyclePolicies:PutLifecycleConfiguration' :: PutLifecycleConfiguration -> [LifecyclePolicy]
$sel:fileSystemId:PutLifecycleConfiguration' :: PutLifecycleConfiguration -> 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
"LifecyclePolicies" Text -> [LifecyclePolicy] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [LifecyclePolicy]
lifecyclePolicies)
          ]
      )

instance Core.ToPath PutLifecycleConfiguration where
  toPath :: PutLifecycleConfiguration -> ByteString
toPath PutLifecycleConfiguration' {[LifecyclePolicy]
Text
lifecyclePolicies :: [LifecyclePolicy]
fileSystemId :: Text
$sel:lifecyclePolicies:PutLifecycleConfiguration' :: PutLifecycleConfiguration -> [LifecyclePolicy]
$sel:fileSystemId:PutLifecycleConfiguration' :: PutLifecycleConfiguration -> Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/2015-02-01/file-systems/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
fileSystemId,
        ByteString
"/lifecycle-configuration"
      ]

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