{-# 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.OpsWorks.RegisterVolume
-- 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)
--
-- Registers an Amazon EBS volume with a specified stack. A volume can be
-- registered with only one stack at a time. If the volume is already
-- registered, you must first deregister it by calling DeregisterVolume.
-- For more information, see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/resources.html Resource Management>.
--
-- __Required Permissions__: To use this action, an IAM user must have a
-- Manage permissions level for the stack, or an attached policy that
-- explicitly grants permissions. For more information on user permissions,
-- see
-- <https://docs.aws.amazon.com/opsworks/latest/userguide/opsworks-security-users.html Managing User Permissions>.
module Amazonka.OpsWorks.RegisterVolume
  ( -- * Creating a Request
    RegisterVolume (..),
    newRegisterVolume,

    -- * Request Lenses
    registerVolume_ec2VolumeId,
    registerVolume_stackId,

    -- * Destructuring the Response
    RegisterVolumeResponse (..),
    newRegisterVolumeResponse,

    -- * Response Lenses
    registerVolumeResponse_volumeId,
    registerVolumeResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.OpsWorks.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newRegisterVolume' smart constructor.
data RegisterVolume = RegisterVolume'
  { -- | The Amazon EBS volume ID.
    RegisterVolume -> Maybe Text
ec2VolumeId :: Prelude.Maybe Prelude.Text,
    -- | The stack ID.
    RegisterVolume -> Text
stackId :: Prelude.Text
  }
  deriving (RegisterVolume -> RegisterVolume -> Bool
(RegisterVolume -> RegisterVolume -> Bool)
-> (RegisterVolume -> RegisterVolume -> Bool) -> Eq RegisterVolume
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterVolume -> RegisterVolume -> Bool
$c/= :: RegisterVolume -> RegisterVolume -> Bool
== :: RegisterVolume -> RegisterVolume -> Bool
$c== :: RegisterVolume -> RegisterVolume -> Bool
Prelude.Eq, ReadPrec [RegisterVolume]
ReadPrec RegisterVolume
Int -> ReadS RegisterVolume
ReadS [RegisterVolume]
(Int -> ReadS RegisterVolume)
-> ReadS [RegisterVolume]
-> ReadPrec RegisterVolume
-> ReadPrec [RegisterVolume]
-> Read RegisterVolume
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterVolume]
$creadListPrec :: ReadPrec [RegisterVolume]
readPrec :: ReadPrec RegisterVolume
$creadPrec :: ReadPrec RegisterVolume
readList :: ReadS [RegisterVolume]
$creadList :: ReadS [RegisterVolume]
readsPrec :: Int -> ReadS RegisterVolume
$creadsPrec :: Int -> ReadS RegisterVolume
Prelude.Read, Int -> RegisterVolume -> ShowS
[RegisterVolume] -> ShowS
RegisterVolume -> String
(Int -> RegisterVolume -> ShowS)
-> (RegisterVolume -> String)
-> ([RegisterVolume] -> ShowS)
-> Show RegisterVolume
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterVolume] -> ShowS
$cshowList :: [RegisterVolume] -> ShowS
show :: RegisterVolume -> String
$cshow :: RegisterVolume -> String
showsPrec :: Int -> RegisterVolume -> ShowS
$cshowsPrec :: Int -> RegisterVolume -> ShowS
Prelude.Show, (forall x. RegisterVolume -> Rep RegisterVolume x)
-> (forall x. Rep RegisterVolume x -> RegisterVolume)
-> Generic RegisterVolume
forall x. Rep RegisterVolume x -> RegisterVolume
forall x. RegisterVolume -> Rep RegisterVolume x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterVolume x -> RegisterVolume
$cfrom :: forall x. RegisterVolume -> Rep RegisterVolume x
Prelude.Generic)

-- |
-- Create a value of 'RegisterVolume' 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:
--
-- 'ec2VolumeId', 'registerVolume_ec2VolumeId' - The Amazon EBS volume ID.
--
-- 'stackId', 'registerVolume_stackId' - The stack ID.
newRegisterVolume ::
  -- | 'stackId'
  Prelude.Text ->
  RegisterVolume
newRegisterVolume :: Text -> RegisterVolume
newRegisterVolume Text
pStackId_ =
  RegisterVolume' :: Maybe Text -> Text -> RegisterVolume
RegisterVolume'
    { $sel:ec2VolumeId:RegisterVolume' :: Maybe Text
ec2VolumeId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:stackId:RegisterVolume' :: Text
stackId = Text
pStackId_
    }

-- | The Amazon EBS volume ID.
registerVolume_ec2VolumeId :: Lens.Lens' RegisterVolume (Prelude.Maybe Prelude.Text)
registerVolume_ec2VolumeId :: (Maybe Text -> f (Maybe Text))
-> RegisterVolume -> f RegisterVolume
registerVolume_ec2VolumeId = (RegisterVolume -> Maybe Text)
-> (RegisterVolume -> Maybe Text -> RegisterVolume)
-> Lens RegisterVolume RegisterVolume (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterVolume' {Maybe Text
ec2VolumeId :: Maybe Text
$sel:ec2VolumeId:RegisterVolume' :: RegisterVolume -> Maybe Text
ec2VolumeId} -> Maybe Text
ec2VolumeId) (\s :: RegisterVolume
s@RegisterVolume' {} Maybe Text
a -> RegisterVolume
s {$sel:ec2VolumeId:RegisterVolume' :: Maybe Text
ec2VolumeId = Maybe Text
a} :: RegisterVolume)

-- | The stack ID.
registerVolume_stackId :: Lens.Lens' RegisterVolume Prelude.Text
registerVolume_stackId :: (Text -> f Text) -> RegisterVolume -> f RegisterVolume
registerVolume_stackId = (RegisterVolume -> Text)
-> (RegisterVolume -> Text -> RegisterVolume)
-> Lens RegisterVolume RegisterVolume Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterVolume' {Text
stackId :: Text
$sel:stackId:RegisterVolume' :: RegisterVolume -> Text
stackId} -> Text
stackId) (\s :: RegisterVolume
s@RegisterVolume' {} Text
a -> RegisterVolume
s {$sel:stackId:RegisterVolume' :: Text
stackId = Text
a} :: RegisterVolume)

instance Core.AWSRequest RegisterVolume where
  type
    AWSResponse RegisterVolume =
      RegisterVolumeResponse
  request :: RegisterVolume -> Request RegisterVolume
request = Service -> RegisterVolume -> Request RegisterVolume
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy RegisterVolume
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterVolume)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse RegisterVolume))
-> Logger
-> Service
-> Proxy RegisterVolume
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse RegisterVolume)))
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 Text -> Int -> RegisterVolumeResponse
RegisterVolumeResponse'
            (Maybe Text -> Int -> RegisterVolumeResponse)
-> Either String (Maybe Text)
-> Either String (Int -> RegisterVolumeResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"VolumeId")
            Either String (Int -> RegisterVolumeResponse)
-> Either String Int -> Either String RegisterVolumeResponse
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 RegisterVolume

instance Prelude.NFData RegisterVolume

instance Core.ToHeaders RegisterVolume where
  toHeaders :: RegisterVolume -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterVolume -> 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
"OpsWorks_20130218.RegisterVolume" ::
                          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 RegisterVolume where
  toJSON :: RegisterVolume -> Value
toJSON RegisterVolume' {Maybe Text
Text
stackId :: Text
ec2VolumeId :: Maybe Text
$sel:stackId:RegisterVolume' :: RegisterVolume -> Text
$sel:ec2VolumeId:RegisterVolume' :: RegisterVolume -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Ec2VolumeId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
ec2VolumeId,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"StackId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
stackId)
          ]
      )

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

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

-- | Contains the response to a @RegisterVolume@ request.
--
-- /See:/ 'newRegisterVolumeResponse' smart constructor.
data RegisterVolumeResponse = RegisterVolumeResponse'
  { -- | The volume ID.
    RegisterVolumeResponse -> Maybe Text
volumeId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    RegisterVolumeResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterVolumeResponse -> RegisterVolumeResponse -> Bool
(RegisterVolumeResponse -> RegisterVolumeResponse -> Bool)
-> (RegisterVolumeResponse -> RegisterVolumeResponse -> Bool)
-> Eq RegisterVolumeResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterVolumeResponse -> RegisterVolumeResponse -> Bool
$c/= :: RegisterVolumeResponse -> RegisterVolumeResponse -> Bool
== :: RegisterVolumeResponse -> RegisterVolumeResponse -> Bool
$c== :: RegisterVolumeResponse -> RegisterVolumeResponse -> Bool
Prelude.Eq, ReadPrec [RegisterVolumeResponse]
ReadPrec RegisterVolumeResponse
Int -> ReadS RegisterVolumeResponse
ReadS [RegisterVolumeResponse]
(Int -> ReadS RegisterVolumeResponse)
-> ReadS [RegisterVolumeResponse]
-> ReadPrec RegisterVolumeResponse
-> ReadPrec [RegisterVolumeResponse]
-> Read RegisterVolumeResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterVolumeResponse]
$creadListPrec :: ReadPrec [RegisterVolumeResponse]
readPrec :: ReadPrec RegisterVolumeResponse
$creadPrec :: ReadPrec RegisterVolumeResponse
readList :: ReadS [RegisterVolumeResponse]
$creadList :: ReadS [RegisterVolumeResponse]
readsPrec :: Int -> ReadS RegisterVolumeResponse
$creadsPrec :: Int -> ReadS RegisterVolumeResponse
Prelude.Read, Int -> RegisterVolumeResponse -> ShowS
[RegisterVolumeResponse] -> ShowS
RegisterVolumeResponse -> String
(Int -> RegisterVolumeResponse -> ShowS)
-> (RegisterVolumeResponse -> String)
-> ([RegisterVolumeResponse] -> ShowS)
-> Show RegisterVolumeResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterVolumeResponse] -> ShowS
$cshowList :: [RegisterVolumeResponse] -> ShowS
show :: RegisterVolumeResponse -> String
$cshow :: RegisterVolumeResponse -> String
showsPrec :: Int -> RegisterVolumeResponse -> ShowS
$cshowsPrec :: Int -> RegisterVolumeResponse -> ShowS
Prelude.Show, (forall x. RegisterVolumeResponse -> Rep RegisterVolumeResponse x)
-> (forall x.
    Rep RegisterVolumeResponse x -> RegisterVolumeResponse)
-> Generic RegisterVolumeResponse
forall x. Rep RegisterVolumeResponse x -> RegisterVolumeResponse
forall x. RegisterVolumeResponse -> Rep RegisterVolumeResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterVolumeResponse x -> RegisterVolumeResponse
$cfrom :: forall x. RegisterVolumeResponse -> Rep RegisterVolumeResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterVolumeResponse' 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:
--
-- 'volumeId', 'registerVolumeResponse_volumeId' - The volume ID.
--
-- 'httpStatus', 'registerVolumeResponse_httpStatus' - The response's http status code.
newRegisterVolumeResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterVolumeResponse
newRegisterVolumeResponse :: Int -> RegisterVolumeResponse
newRegisterVolumeResponse Int
pHttpStatus_ =
  RegisterVolumeResponse' :: Maybe Text -> Int -> RegisterVolumeResponse
RegisterVolumeResponse'
    { $sel:volumeId:RegisterVolumeResponse' :: Maybe Text
volumeId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterVolumeResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The volume ID.
registerVolumeResponse_volumeId :: Lens.Lens' RegisterVolumeResponse (Prelude.Maybe Prelude.Text)
registerVolumeResponse_volumeId :: (Maybe Text -> f (Maybe Text))
-> RegisterVolumeResponse -> f RegisterVolumeResponse
registerVolumeResponse_volumeId = (RegisterVolumeResponse -> Maybe Text)
-> (RegisterVolumeResponse -> Maybe Text -> RegisterVolumeResponse)
-> Lens
     RegisterVolumeResponse
     RegisterVolumeResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterVolumeResponse' {Maybe Text
volumeId :: Maybe Text
$sel:volumeId:RegisterVolumeResponse' :: RegisterVolumeResponse -> Maybe Text
volumeId} -> Maybe Text
volumeId) (\s :: RegisterVolumeResponse
s@RegisterVolumeResponse' {} Maybe Text
a -> RegisterVolumeResponse
s {$sel:volumeId:RegisterVolumeResponse' :: Maybe Text
volumeId = Maybe Text
a} :: RegisterVolumeResponse)

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

instance Prelude.NFData RegisterVolumeResponse