{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE RecordWildCards    #-}
{-# LANGUAGE TypeFamilies       #-}

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds   #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Network.AWS.EC2.CopyImage
-- Copyright   : (c) 2013-2016 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Initiates the copy of an AMI from the specified source region to the current region. You specify the destination region by using its endpoint when making the request.
--
-- For more information, see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/CopyingAMIs.html Copying AMIs> in the /Amazon Elastic Compute Cloud User Guide/.
module Network.AWS.EC2.CopyImage
    (
    -- * Creating a Request
      copyImage
    , CopyImage
    -- * Request Lenses
    , ciClientToken
    , ciEncrypted
    , ciKMSKeyId
    , ciDescription
    , ciDryRun
    , ciSourceRegion
    , ciSourceImageId
    , ciName

    -- * Destructuring the Response
    , copyImageResponse
    , CopyImageResponse
    -- * Response Lenses
    , coprsImageId
    , coprsResponseStatus
    ) where

import           Network.AWS.EC2.Types
import           Network.AWS.EC2.Types.Product
import           Network.AWS.Lens
import           Network.AWS.Prelude
import           Network.AWS.Request
import           Network.AWS.Response

-- | Contains the parameters for CopyImage.
--
-- /See:/ 'copyImage' smart constructor.
data CopyImage = CopyImage'
    { _ciClientToken   :: !(Maybe Text)
    , _ciEncrypted     :: !(Maybe Bool)
    , _ciKMSKeyId      :: !(Maybe Text)
    , _ciDescription   :: !(Maybe Text)
    , _ciDryRun        :: !(Maybe Bool)
    , _ciSourceRegion  :: !Text
    , _ciSourceImageId :: !Text
    , _ciName          :: !Text
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'CopyImage' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'ciClientToken'
--
-- * 'ciEncrypted'
--
-- * 'ciKMSKeyId'
--
-- * 'ciDescription'
--
-- * 'ciDryRun'
--
-- * 'ciSourceRegion'
--
-- * 'ciSourceImageId'
--
-- * 'ciName'
copyImage
    :: Text -- ^ 'ciSourceRegion'
    -> Text -- ^ 'ciSourceImageId'
    -> Text -- ^ 'ciName'
    -> CopyImage
copyImage pSourceRegion_ pSourceImageId_ pName_ =
    CopyImage'
    { _ciClientToken = Nothing
    , _ciEncrypted = Nothing
    , _ciKMSKeyId = Nothing
    , _ciDescription = Nothing
    , _ciDryRun = Nothing
    , _ciSourceRegion = pSourceRegion_
    , _ciSourceImageId = pSourceImageId_
    , _ciName = pName_
    }

-- | Unique, case-sensitive identifier you provide to ensure idempotency of the request. For more information, see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Run_Instance_Idempotency.html How to Ensure Idempotency> in the /Amazon Elastic Compute Cloud User Guide/.
ciClientToken :: Lens' CopyImage (Maybe Text)
ciClientToken = lens _ciClientToken (\ s a -> s{_ciClientToken = a});

-- | Specifies whether the destination snapshots of the copied image should be encrypted. The default CMK for EBS is used unless a non-default AWS Key Management Service (AWS KMS) CMK is specified with 'KmsKeyId'. For more information, see <http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html Amazon EBS Encryption> in the /Amazon Elastic Compute Cloud User Guide/.
ciEncrypted :: Lens' CopyImage (Maybe Bool)
ciEncrypted = lens _ciEncrypted (\ s a -> s{_ciEncrypted = a});

-- | The full ARN of the AWS Key Management Service (AWS KMS) CMK to use when encrypting the snapshots of an image during a copy operation. This parameter is only required if you want to use a non-default CMK; if this parameter is not specified, the default CMK for EBS is used. The ARN contains the 'arn:aws:kms' namespace, followed by the region of the CMK, the AWS account ID of the CMK owner, the 'key' namespace, and then the CMK ID. For example, arn:aws:kms:/us-east-1/:/012345678910/:key\//abcd1234-a123-456a-a12b-a123b4cd56ef/. The specified CMK must exist in the region that the snapshot is being copied to. If a 'KmsKeyId' is specified, the 'Encrypted' flag must also be set.
ciKMSKeyId :: Lens' CopyImage (Maybe Text)
ciKMSKeyId = lens _ciKMSKeyId (\ s a -> s{_ciKMSKeyId = a});

-- | A description for the new AMI in the destination region.
ciDescription :: Lens' CopyImage (Maybe Text)
ciDescription = lens _ciDescription (\ s a -> s{_ciDescription = a});

-- | Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is 'DryRunOperation'. Otherwise, it is 'UnauthorizedOperation'.
ciDryRun :: Lens' CopyImage (Maybe Bool)
ciDryRun = lens _ciDryRun (\ s a -> s{_ciDryRun = a});

-- | The name of the region that contains the AMI to copy.
ciSourceRegion :: Lens' CopyImage Text
ciSourceRegion = lens _ciSourceRegion (\ s a -> s{_ciSourceRegion = a});

-- | The ID of the AMI to copy.
ciSourceImageId :: Lens' CopyImage Text
ciSourceImageId = lens _ciSourceImageId (\ s a -> s{_ciSourceImageId = a});

-- | The name of the new AMI in the destination region.
ciName :: Lens' CopyImage Text
ciName = lens _ciName (\ s a -> s{_ciName = a});

instance AWSRequest CopyImage where
        type Rs CopyImage = CopyImageResponse
        request = postQuery ec2
        response
          = receiveXML
              (\ s h x ->
                 CopyImageResponse' <$>
                   (x .@? "imageId") <*> (pure (fromEnum s)))

instance Hashable CopyImage

instance NFData CopyImage

instance ToHeaders CopyImage where
        toHeaders = const mempty

instance ToPath CopyImage where
        toPath = const "/"

instance ToQuery CopyImage where
        toQuery CopyImage'{..}
          = mconcat
              ["Action" =: ("CopyImage" :: ByteString),
               "Version" =: ("2016-04-01" :: ByteString),
               "ClientToken" =: _ciClientToken,
               "Encrypted" =: _ciEncrypted,
               "KmsKeyId" =: _ciKMSKeyId,
               "Description" =: _ciDescription,
               "DryRun" =: _ciDryRun,
               "SourceRegion" =: _ciSourceRegion,
               "SourceImageId" =: _ciSourceImageId,
               "Name" =: _ciName]

-- | Contains the output of CopyImage.
--
-- /See:/ 'copyImageResponse' smart constructor.
data CopyImageResponse = CopyImageResponse'
    { _coprsImageId        :: !(Maybe Text)
    , _coprsResponseStatus :: !Int
    } deriving (Eq,Read,Show,Data,Typeable,Generic)

-- | Creates a value of 'CopyImageResponse' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'coprsImageId'
--
-- * 'coprsResponseStatus'
copyImageResponse
    :: Int -- ^ 'coprsResponseStatus'
    -> CopyImageResponse
copyImageResponse pResponseStatus_ =
    CopyImageResponse'
    { _coprsImageId = Nothing
    , _coprsResponseStatus = pResponseStatus_
    }

-- | The ID of the new AMI.
coprsImageId :: Lens' CopyImageResponse (Maybe Text)
coprsImageId = lens _coprsImageId (\ s a -> s{_coprsImageId = a});

-- | The response status code.
coprsResponseStatus :: Lens' CopyImageResponse Int
coprsResponseStatus = lens _coprsResponseStatus (\ s a -> s{_coprsResponseStatus = a});

instance NFData CopyImageResponse