{-# 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.CodeDeploy.RegisterOnPremisesInstance
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Registers an on-premises instance.
--
-- Only one IAM ARN (an IAM session ARN or IAM user ARN) is supported in
-- the request. You cannot use both.
module Amazonka.CodeDeploy.RegisterOnPremisesInstance
  ( -- * Creating a Request
    RegisterOnPremisesInstance (..),
    newRegisterOnPremisesInstance,

    -- * Request Lenses
    registerOnPremisesInstance_iamSessionArn,
    registerOnPremisesInstance_iamUserArn,
    registerOnPremisesInstance_instanceName,

    -- * Destructuring the Response
    RegisterOnPremisesInstanceResponse (..),
    newRegisterOnPremisesInstanceResponse,
  )
where

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

-- | Represents the input of the register on-premises instance operation.
--
-- /See:/ 'newRegisterOnPremisesInstance' smart constructor.
data RegisterOnPremisesInstance = RegisterOnPremisesInstance'
  { -- | The ARN of the IAM session to associate with the on-premises instance.
    RegisterOnPremisesInstance -> Maybe Text
iamSessionArn :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the IAM user to associate with the on-premises instance.
    RegisterOnPremisesInstance -> Maybe Text
iamUserArn :: Prelude.Maybe Prelude.Text,
    -- | The name of the on-premises instance to register.
    RegisterOnPremisesInstance -> Text
instanceName :: Prelude.Text
  }
  deriving (RegisterOnPremisesInstance -> RegisterOnPremisesInstance -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterOnPremisesInstance -> RegisterOnPremisesInstance -> Bool
$c/= :: RegisterOnPremisesInstance -> RegisterOnPremisesInstance -> Bool
== :: RegisterOnPremisesInstance -> RegisterOnPremisesInstance -> Bool
$c== :: RegisterOnPremisesInstance -> RegisterOnPremisesInstance -> Bool
Prelude.Eq, ReadPrec [RegisterOnPremisesInstance]
ReadPrec RegisterOnPremisesInstance
Int -> ReadS RegisterOnPremisesInstance
ReadS [RegisterOnPremisesInstance]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterOnPremisesInstance]
$creadListPrec :: ReadPrec [RegisterOnPremisesInstance]
readPrec :: ReadPrec RegisterOnPremisesInstance
$creadPrec :: ReadPrec RegisterOnPremisesInstance
readList :: ReadS [RegisterOnPremisesInstance]
$creadList :: ReadS [RegisterOnPremisesInstance]
readsPrec :: Int -> ReadS RegisterOnPremisesInstance
$creadsPrec :: Int -> ReadS RegisterOnPremisesInstance
Prelude.Read, Int -> RegisterOnPremisesInstance -> ShowS
[RegisterOnPremisesInstance] -> ShowS
RegisterOnPremisesInstance -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterOnPremisesInstance] -> ShowS
$cshowList :: [RegisterOnPremisesInstance] -> ShowS
show :: RegisterOnPremisesInstance -> String
$cshow :: RegisterOnPremisesInstance -> String
showsPrec :: Int -> RegisterOnPremisesInstance -> ShowS
$cshowsPrec :: Int -> RegisterOnPremisesInstance -> ShowS
Prelude.Show, forall x.
Rep RegisterOnPremisesInstance x -> RegisterOnPremisesInstance
forall x.
RegisterOnPremisesInstance -> Rep RegisterOnPremisesInstance x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegisterOnPremisesInstance x -> RegisterOnPremisesInstance
$cfrom :: forall x.
RegisterOnPremisesInstance -> Rep RegisterOnPremisesInstance x
Prelude.Generic)

-- |
-- Create a value of 'RegisterOnPremisesInstance' 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:
--
-- 'iamSessionArn', 'registerOnPremisesInstance_iamSessionArn' - The ARN of the IAM session to associate with the on-premises instance.
--
-- 'iamUserArn', 'registerOnPremisesInstance_iamUserArn' - The ARN of the IAM user to associate with the on-premises instance.
--
-- 'instanceName', 'registerOnPremisesInstance_instanceName' - The name of the on-premises instance to register.
newRegisterOnPremisesInstance ::
  -- | 'instanceName'
  Prelude.Text ->
  RegisterOnPremisesInstance
newRegisterOnPremisesInstance :: Text -> RegisterOnPremisesInstance
newRegisterOnPremisesInstance Text
pInstanceName_ =
  RegisterOnPremisesInstance'
    { $sel:iamSessionArn:RegisterOnPremisesInstance' :: Maybe Text
iamSessionArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:iamUserArn:RegisterOnPremisesInstance' :: Maybe Text
iamUserArn = forall a. Maybe a
Prelude.Nothing,
      $sel:instanceName:RegisterOnPremisesInstance' :: Text
instanceName = Text
pInstanceName_
    }

-- | The ARN of the IAM session to associate with the on-premises instance.
registerOnPremisesInstance_iamSessionArn :: Lens.Lens' RegisterOnPremisesInstance (Prelude.Maybe Prelude.Text)
registerOnPremisesInstance_iamSessionArn :: Lens' RegisterOnPremisesInstance (Maybe Text)
registerOnPremisesInstance_iamSessionArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterOnPremisesInstance' {Maybe Text
iamSessionArn :: Maybe Text
$sel:iamSessionArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
iamSessionArn} -> Maybe Text
iamSessionArn) (\s :: RegisterOnPremisesInstance
s@RegisterOnPremisesInstance' {} Maybe Text
a -> RegisterOnPremisesInstance
s {$sel:iamSessionArn:RegisterOnPremisesInstance' :: Maybe Text
iamSessionArn = Maybe Text
a} :: RegisterOnPremisesInstance)

-- | The ARN of the IAM user to associate with the on-premises instance.
registerOnPremisesInstance_iamUserArn :: Lens.Lens' RegisterOnPremisesInstance (Prelude.Maybe Prelude.Text)
registerOnPremisesInstance_iamUserArn :: Lens' RegisterOnPremisesInstance (Maybe Text)
registerOnPremisesInstance_iamUserArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterOnPremisesInstance' {Maybe Text
iamUserArn :: Maybe Text
$sel:iamUserArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
iamUserArn} -> Maybe Text
iamUserArn) (\s :: RegisterOnPremisesInstance
s@RegisterOnPremisesInstance' {} Maybe Text
a -> RegisterOnPremisesInstance
s {$sel:iamUserArn:RegisterOnPremisesInstance' :: Maybe Text
iamUserArn = Maybe Text
a} :: RegisterOnPremisesInstance)

-- | The name of the on-premises instance to register.
registerOnPremisesInstance_instanceName :: Lens.Lens' RegisterOnPremisesInstance Prelude.Text
registerOnPremisesInstance_instanceName :: Lens' RegisterOnPremisesInstance Text
registerOnPremisesInstance_instanceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterOnPremisesInstance' {Text
instanceName :: Text
$sel:instanceName:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Text
instanceName} -> Text
instanceName) (\s :: RegisterOnPremisesInstance
s@RegisterOnPremisesInstance' {} Text
a -> RegisterOnPremisesInstance
s {$sel:instanceName:RegisterOnPremisesInstance' :: Text
instanceName = Text
a} :: RegisterOnPremisesInstance)

instance Core.AWSRequest RegisterOnPremisesInstance where
  type
    AWSResponse RegisterOnPremisesInstance =
      RegisterOnPremisesInstanceResponse
  request :: (Service -> Service)
-> RegisterOnPremisesInstance -> Request RegisterOnPremisesInstance
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 RegisterOnPremisesInstance
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse RegisterOnPremisesInstance)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull
      RegisterOnPremisesInstanceResponse
RegisterOnPremisesInstanceResponse'

instance Prelude.Hashable RegisterOnPremisesInstance where
  hashWithSalt :: Int -> RegisterOnPremisesInstance -> Int
hashWithSalt Int
_salt RegisterOnPremisesInstance' {Maybe Text
Text
instanceName :: Text
iamUserArn :: Maybe Text
iamSessionArn :: Maybe Text
$sel:instanceName:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Text
$sel:iamUserArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
$sel:iamSessionArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
iamSessionArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
iamUserArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
instanceName

instance Prelude.NFData RegisterOnPremisesInstance where
  rnf :: RegisterOnPremisesInstance -> ()
rnf RegisterOnPremisesInstance' {Maybe Text
Text
instanceName :: Text
iamUserArn :: Maybe Text
iamSessionArn :: Maybe Text
$sel:instanceName:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Text
$sel:iamUserArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
$sel:iamSessionArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
iamSessionArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
iamUserArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
instanceName

instance Data.ToHeaders RegisterOnPremisesInstance where
  toHeaders :: RegisterOnPremisesInstance -> [Header]
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 -> [Header]
Data.=# ( ByteString
"CodeDeploy_20141006.RegisterOnPremisesInstance" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> [Header]
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON RegisterOnPremisesInstance where
  toJSON :: RegisterOnPremisesInstance -> Value
toJSON RegisterOnPremisesInstance' {Maybe Text
Text
instanceName :: Text
iamUserArn :: Maybe Text
iamSessionArn :: Maybe Text
$sel:instanceName:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Text
$sel:iamUserArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
$sel:iamSessionArn:RegisterOnPremisesInstance' :: RegisterOnPremisesInstance -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"iamSessionArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
iamSessionArn,
            (Key
"iamUserArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
iamUserArn,
            forall a. a -> Maybe a
Prelude.Just (Key
"instanceName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
instanceName)
          ]
      )

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

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

-- | /See:/ 'newRegisterOnPremisesInstanceResponse' smart constructor.
data RegisterOnPremisesInstanceResponse = RegisterOnPremisesInstanceResponse'
  {
  }
  deriving (RegisterOnPremisesInstanceResponse
-> RegisterOnPremisesInstanceResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterOnPremisesInstanceResponse
-> RegisterOnPremisesInstanceResponse -> Bool
$c/= :: RegisterOnPremisesInstanceResponse
-> RegisterOnPremisesInstanceResponse -> Bool
== :: RegisterOnPremisesInstanceResponse
-> RegisterOnPremisesInstanceResponse -> Bool
$c== :: RegisterOnPremisesInstanceResponse
-> RegisterOnPremisesInstanceResponse -> Bool
Prelude.Eq, ReadPrec [RegisterOnPremisesInstanceResponse]
ReadPrec RegisterOnPremisesInstanceResponse
Int -> ReadS RegisterOnPremisesInstanceResponse
ReadS [RegisterOnPremisesInstanceResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterOnPremisesInstanceResponse]
$creadListPrec :: ReadPrec [RegisterOnPremisesInstanceResponse]
readPrec :: ReadPrec RegisterOnPremisesInstanceResponse
$creadPrec :: ReadPrec RegisterOnPremisesInstanceResponse
readList :: ReadS [RegisterOnPremisesInstanceResponse]
$creadList :: ReadS [RegisterOnPremisesInstanceResponse]
readsPrec :: Int -> ReadS RegisterOnPremisesInstanceResponse
$creadsPrec :: Int -> ReadS RegisterOnPremisesInstanceResponse
Prelude.Read, Int -> RegisterOnPremisesInstanceResponse -> ShowS
[RegisterOnPremisesInstanceResponse] -> ShowS
RegisterOnPremisesInstanceResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterOnPremisesInstanceResponse] -> ShowS
$cshowList :: [RegisterOnPremisesInstanceResponse] -> ShowS
show :: RegisterOnPremisesInstanceResponse -> String
$cshow :: RegisterOnPremisesInstanceResponse -> String
showsPrec :: Int -> RegisterOnPremisesInstanceResponse -> ShowS
$cshowsPrec :: Int -> RegisterOnPremisesInstanceResponse -> ShowS
Prelude.Show, forall x.
Rep RegisterOnPremisesInstanceResponse x
-> RegisterOnPremisesInstanceResponse
forall x.
RegisterOnPremisesInstanceResponse
-> Rep RegisterOnPremisesInstanceResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RegisterOnPremisesInstanceResponse x
-> RegisterOnPremisesInstanceResponse
$cfrom :: forall x.
RegisterOnPremisesInstanceResponse
-> Rep RegisterOnPremisesInstanceResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterOnPremisesInstanceResponse' 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.
newRegisterOnPremisesInstanceResponse ::
  RegisterOnPremisesInstanceResponse
newRegisterOnPremisesInstanceResponse :: RegisterOnPremisesInstanceResponse
newRegisterOnPremisesInstanceResponse =
  RegisterOnPremisesInstanceResponse
RegisterOnPremisesInstanceResponse'

instance
  Prelude.NFData
    RegisterOnPremisesInstanceResponse
  where
  rnf :: RegisterOnPremisesInstanceResponse -> ()
rnf RegisterOnPremisesInstanceResponse
_ = ()