{-# 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.Lightsail.ExportSnapshot
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Exports an Amazon Lightsail instance or block storage disk snapshot to
-- Amazon Elastic Compute Cloud (Amazon EC2). This operation results in an
-- export snapshot record that can be used with the
-- @create cloud formation stack@ operation to create new Amazon EC2
-- instances.
--
-- Exported instance snapshots appear in Amazon EC2 as Amazon Machine
-- Images (AMIs), and the instance system disk appears as an Amazon Elastic
-- Block Store (Amazon EBS) volume. Exported disk snapshots appear in
-- Amazon EC2 as Amazon EBS volumes. Snapshots are exported to the same
-- Amazon Web Services Region in Amazon EC2 as the source Lightsail
-- snapshot.
--
-- The @export snapshot@ operation supports tag-based access control via
-- resource tags applied to the resource identified by
-- @source snapshot name@. For more information, see the
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-controlling-access-using-tags Amazon Lightsail Developer Guide>.
--
-- Use the @get instance snapshots@ or @get disk snapshots@ operations to
-- get a list of snapshots that you can export to Amazon EC2.
module Amazonka.Lightsail.ExportSnapshot
  ( -- * Creating a Request
    ExportSnapshot (..),
    newExportSnapshot,

    -- * Request Lenses
    exportSnapshot_sourceSnapshotName,

    -- * Destructuring the Response
    ExportSnapshotResponse (..),
    newExportSnapshotResponse,

    -- * Response Lenses
    exportSnapshotResponse_operations,
    exportSnapshotResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newExportSnapshot' smart constructor.
data ExportSnapshot = ExportSnapshot'
  { -- | The name of the instance or disk snapshot to be exported to Amazon EC2.
    ExportSnapshot -> Text
sourceSnapshotName :: Prelude.Text
  }
  deriving (ExportSnapshot -> ExportSnapshot -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExportSnapshot -> ExportSnapshot -> Bool
$c/= :: ExportSnapshot -> ExportSnapshot -> Bool
== :: ExportSnapshot -> ExportSnapshot -> Bool
$c== :: ExportSnapshot -> ExportSnapshot -> Bool
Prelude.Eq, ReadPrec [ExportSnapshot]
ReadPrec ExportSnapshot
Int -> ReadS ExportSnapshot
ReadS [ExportSnapshot]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExportSnapshot]
$creadListPrec :: ReadPrec [ExportSnapshot]
readPrec :: ReadPrec ExportSnapshot
$creadPrec :: ReadPrec ExportSnapshot
readList :: ReadS [ExportSnapshot]
$creadList :: ReadS [ExportSnapshot]
readsPrec :: Int -> ReadS ExportSnapshot
$creadsPrec :: Int -> ReadS ExportSnapshot
Prelude.Read, Int -> ExportSnapshot -> ShowS
[ExportSnapshot] -> ShowS
ExportSnapshot -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExportSnapshot] -> ShowS
$cshowList :: [ExportSnapshot] -> ShowS
show :: ExportSnapshot -> String
$cshow :: ExportSnapshot -> String
showsPrec :: Int -> ExportSnapshot -> ShowS
$cshowsPrec :: Int -> ExportSnapshot -> ShowS
Prelude.Show, forall x. Rep ExportSnapshot x -> ExportSnapshot
forall x. ExportSnapshot -> Rep ExportSnapshot x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExportSnapshot x -> ExportSnapshot
$cfrom :: forall x. ExportSnapshot -> Rep ExportSnapshot x
Prelude.Generic)

-- |
-- Create a value of 'ExportSnapshot' 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:
--
-- 'sourceSnapshotName', 'exportSnapshot_sourceSnapshotName' - The name of the instance or disk snapshot to be exported to Amazon EC2.
newExportSnapshot ::
  -- | 'sourceSnapshotName'
  Prelude.Text ->
  ExportSnapshot
newExportSnapshot :: Text -> ExportSnapshot
newExportSnapshot Text
pSourceSnapshotName_ =
  ExportSnapshot'
    { $sel:sourceSnapshotName:ExportSnapshot' :: Text
sourceSnapshotName =
        Text
pSourceSnapshotName_
    }

-- | The name of the instance or disk snapshot to be exported to Amazon EC2.
exportSnapshot_sourceSnapshotName :: Lens.Lens' ExportSnapshot Prelude.Text
exportSnapshot_sourceSnapshotName :: Lens' ExportSnapshot Text
exportSnapshot_sourceSnapshotName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExportSnapshot' {Text
sourceSnapshotName :: Text
$sel:sourceSnapshotName:ExportSnapshot' :: ExportSnapshot -> Text
sourceSnapshotName} -> Text
sourceSnapshotName) (\s :: ExportSnapshot
s@ExportSnapshot' {} Text
a -> ExportSnapshot
s {$sel:sourceSnapshotName:ExportSnapshot' :: Text
sourceSnapshotName = Text
a} :: ExportSnapshot)

instance Core.AWSRequest ExportSnapshot where
  type
    AWSResponse ExportSnapshot =
      ExportSnapshotResponse
  request :: (Service -> Service) -> ExportSnapshot -> Request ExportSnapshot
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy ExportSnapshot
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExportSnapshot)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe [Operation] -> Int -> ExportSnapshotResponse
ExportSnapshotResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operations" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ExportSnapshot where
  hashWithSalt :: Int -> ExportSnapshot -> Int
hashWithSalt Int
_salt ExportSnapshot' {Text
sourceSnapshotName :: Text
$sel:sourceSnapshotName:ExportSnapshot' :: ExportSnapshot -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
sourceSnapshotName

instance Prelude.NFData ExportSnapshot where
  rnf :: ExportSnapshot -> ()
rnf ExportSnapshot' {Text
sourceSnapshotName :: Text
$sel:sourceSnapshotName:ExportSnapshot' :: ExportSnapshot -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
sourceSnapshotName

instance Data.ToHeaders ExportSnapshot where
  toHeaders :: ExportSnapshot -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"Lightsail_20161128.ExportSnapshot" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON ExportSnapshot where
  toJSON :: ExportSnapshot -> Value
toJSON ExportSnapshot' {Text
sourceSnapshotName :: Text
$sel:sourceSnapshotName:ExportSnapshot' :: ExportSnapshot -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just
              (Key
"sourceSnapshotName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
sourceSnapshotName)
          ]
      )

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

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

-- | /See:/ 'newExportSnapshotResponse' smart constructor.
data ExportSnapshotResponse = ExportSnapshotResponse'
  { -- | An array of objects that describe the result of the action, such as the
    -- status of the request, the timestamp of the request, and the resources
    -- affected by the request.
    ExportSnapshotResponse -> Maybe [Operation]
operations :: Prelude.Maybe [Operation],
    -- | The response's http status code.
    ExportSnapshotResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ExportSnapshotResponse -> ExportSnapshotResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExportSnapshotResponse -> ExportSnapshotResponse -> Bool
$c/= :: ExportSnapshotResponse -> ExportSnapshotResponse -> Bool
== :: ExportSnapshotResponse -> ExportSnapshotResponse -> Bool
$c== :: ExportSnapshotResponse -> ExportSnapshotResponse -> Bool
Prelude.Eq, ReadPrec [ExportSnapshotResponse]
ReadPrec ExportSnapshotResponse
Int -> ReadS ExportSnapshotResponse
ReadS [ExportSnapshotResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExportSnapshotResponse]
$creadListPrec :: ReadPrec [ExportSnapshotResponse]
readPrec :: ReadPrec ExportSnapshotResponse
$creadPrec :: ReadPrec ExportSnapshotResponse
readList :: ReadS [ExportSnapshotResponse]
$creadList :: ReadS [ExportSnapshotResponse]
readsPrec :: Int -> ReadS ExportSnapshotResponse
$creadsPrec :: Int -> ReadS ExportSnapshotResponse
Prelude.Read, Int -> ExportSnapshotResponse -> ShowS
[ExportSnapshotResponse] -> ShowS
ExportSnapshotResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExportSnapshotResponse] -> ShowS
$cshowList :: [ExportSnapshotResponse] -> ShowS
show :: ExportSnapshotResponse -> String
$cshow :: ExportSnapshotResponse -> String
showsPrec :: Int -> ExportSnapshotResponse -> ShowS
$cshowsPrec :: Int -> ExportSnapshotResponse -> ShowS
Prelude.Show, forall x. Rep ExportSnapshotResponse x -> ExportSnapshotResponse
forall x. ExportSnapshotResponse -> Rep ExportSnapshotResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExportSnapshotResponse x -> ExportSnapshotResponse
$cfrom :: forall x. ExportSnapshotResponse -> Rep ExportSnapshotResponse x
Prelude.Generic)

-- |
-- Create a value of 'ExportSnapshotResponse' 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:
--
-- 'operations', 'exportSnapshotResponse_operations' - An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
--
-- 'httpStatus', 'exportSnapshotResponse_httpStatus' - The response's http status code.
newExportSnapshotResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ExportSnapshotResponse
newExportSnapshotResponse :: Int -> ExportSnapshotResponse
newExportSnapshotResponse Int
pHttpStatus_ =
  ExportSnapshotResponse'
    { $sel:operations:ExportSnapshotResponse' :: Maybe [Operation]
operations =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ExportSnapshotResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An array of objects that describe the result of the action, such as the
-- status of the request, the timestamp of the request, and the resources
-- affected by the request.
exportSnapshotResponse_operations :: Lens.Lens' ExportSnapshotResponse (Prelude.Maybe [Operation])
exportSnapshotResponse_operations :: Lens' ExportSnapshotResponse (Maybe [Operation])
exportSnapshotResponse_operations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExportSnapshotResponse' {Maybe [Operation]
operations :: Maybe [Operation]
$sel:operations:ExportSnapshotResponse' :: ExportSnapshotResponse -> Maybe [Operation]
operations} -> Maybe [Operation]
operations) (\s :: ExportSnapshotResponse
s@ExportSnapshotResponse' {} Maybe [Operation]
a -> ExportSnapshotResponse
s {$sel:operations:ExportSnapshotResponse' :: Maybe [Operation]
operations = Maybe [Operation]
a} :: ExportSnapshotResponse) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData ExportSnapshotResponse where
  rnf :: ExportSnapshotResponse -> ()
rnf ExportSnapshotResponse' {Int
Maybe [Operation]
httpStatus :: Int
operations :: Maybe [Operation]
$sel:httpStatus:ExportSnapshotResponse' :: ExportSnapshotResponse -> Int
$sel:operations:ExportSnapshotResponse' :: ExportSnapshotResponse -> Maybe [Operation]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Operation]
operations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus