{-# 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-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)
--
-- 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.Lens as Lens
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
(ExportSnapshot -> ExportSnapshot -> Bool)
-> (ExportSnapshot -> ExportSnapshot -> Bool) -> Eq ExportSnapshot
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]
(Int -> ReadS ExportSnapshot)
-> ReadS [ExportSnapshot]
-> ReadPrec ExportSnapshot
-> ReadPrec [ExportSnapshot]
-> Read 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
(Int -> ExportSnapshot -> ShowS)
-> (ExportSnapshot -> String)
-> ([ExportSnapshot] -> ShowS)
-> Show ExportSnapshot
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. ExportSnapshot -> Rep ExportSnapshot x)
-> (forall x. Rep ExportSnapshot x -> ExportSnapshot)
-> Generic ExportSnapshot
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' :: Text -> ExportSnapshot
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 :: (Text -> f Text) -> ExportSnapshot -> f ExportSnapshot
exportSnapshot_sourceSnapshotName = (ExportSnapshot -> Text)
-> (ExportSnapshot -> Text -> ExportSnapshot)
-> Lens ExportSnapshot ExportSnapshot Text Text
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 :: ExportSnapshot -> Request ExportSnapshot
request = Service -> ExportSnapshot -> Request ExportSnapshot
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ExportSnapshot
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExportSnapshot)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ExportSnapshot))
-> Logger
-> Service
-> Proxy ExportSnapshot
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExportSnapshot)))
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 ->
          Maybe [Operation] -> Int -> ExportSnapshotResponse
ExportSnapshotResponse'
            (Maybe [Operation] -> Int -> ExportSnapshotResponse)
-> Either String (Maybe [Operation])
-> Either String (Int -> ExportSnapshotResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Operation]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"operations" Either String (Maybe (Maybe [Operation]))
-> Maybe [Operation] -> Either String (Maybe [Operation])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Operation]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Int -> ExportSnapshotResponse)
-> Either String Int -> Either String ExportSnapshotResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ExportSnapshot

instance Prelude.NFData ExportSnapshot

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

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

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

instance Core.ToQuery ExportSnapshot where
  toQuery :: ExportSnapshot -> QueryString
toQuery = QueryString -> ExportSnapshot -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(ExportSnapshotResponse -> ExportSnapshotResponse -> Bool)
-> (ExportSnapshotResponse -> ExportSnapshotResponse -> Bool)
-> Eq ExportSnapshotResponse
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]
(Int -> ReadS ExportSnapshotResponse)
-> ReadS [ExportSnapshotResponse]
-> ReadPrec ExportSnapshotResponse
-> ReadPrec [ExportSnapshotResponse]
-> Read 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
(Int -> ExportSnapshotResponse -> ShowS)
-> (ExportSnapshotResponse -> String)
-> ([ExportSnapshotResponse] -> ShowS)
-> Show ExportSnapshotResponse
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. ExportSnapshotResponse -> Rep ExportSnapshotResponse x)
-> (forall x.
    Rep ExportSnapshotResponse x -> ExportSnapshotResponse)
-> Generic ExportSnapshotResponse
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' :: Maybe [Operation] -> Int -> ExportSnapshotResponse
ExportSnapshotResponse'
    { $sel:operations:ExportSnapshotResponse' :: Maybe [Operation]
operations =
        Maybe [Operation]
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 :: (Maybe [Operation] -> f (Maybe [Operation]))
-> ExportSnapshotResponse -> f ExportSnapshotResponse
exportSnapshotResponse_operations = (ExportSnapshotResponse -> Maybe [Operation])
-> (ExportSnapshotResponse
    -> Maybe [Operation] -> ExportSnapshotResponse)
-> Lens
     ExportSnapshotResponse
     ExportSnapshotResponse
     (Maybe [Operation])
     (Maybe [Operation])
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) ((Maybe [Operation] -> f (Maybe [Operation]))
 -> ExportSnapshotResponse -> f ExportSnapshotResponse)
-> ((Maybe [Operation] -> f (Maybe [Operation]))
    -> Maybe [Operation] -> f (Maybe [Operation]))
-> (Maybe [Operation] -> f (Maybe [Operation]))
-> ExportSnapshotResponse
-> f ExportSnapshotResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Operation] [Operation] [Operation] [Operation]
-> Iso
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
     (Maybe [Operation])
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 AnIso [Operation] [Operation] [Operation] [Operation]
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 :: (Int -> f Int)
-> ExportSnapshotResponse -> f ExportSnapshotResponse
exportSnapshotResponse_httpStatus = (ExportSnapshotResponse -> Int)
-> (ExportSnapshotResponse -> Int -> ExportSnapshotResponse)
-> Lens ExportSnapshotResponse ExportSnapshotResponse Int Int
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