{-# 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.EKS.RegisterCluster
-- 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)
--
-- Connects a Kubernetes cluster to the Amazon EKS control plane.
--
-- Any Kubernetes cluster can be connected to the Amazon EKS control plane
-- to view current information about the cluster and its nodes.
--
-- Cluster connection requires two steps. First, send a
-- @ RegisterClusterRequest @ to add it to the Amazon EKS control plane.
--
-- Second, a
-- <https://amazon-eks.s3.us-west-2.amazonaws.com/eks-connector/manifests/eks-connector/latest/eks-connector.yaml Manifest>
-- containing the @activationID@ and @activationCode@ must be applied to
-- the Kubernetes cluster through it\'s native provider to provide
-- visibility.
--
-- After the Manifest is updated and applied, then the connected cluster is
-- visible to the Amazon EKS control plane. If the Manifest is not applied
-- within a set amount of time, then the connected cluster will no longer
-- be visible and must be deregistered. See DeregisterCluster.
module Amazonka.EKS.RegisterCluster
  ( -- * Creating a Request
    RegisterCluster (..),
    newRegisterCluster,

    -- * Request Lenses
    registerCluster_clientRequestToken,
    registerCluster_name,
    registerCluster_connectorConfig,

    -- * Destructuring the Response
    RegisterClusterResponse (..),
    newRegisterClusterResponse,

    -- * Response Lenses
    registerClusterResponse_cluster,
    registerClusterResponse_httpStatus,
  )
where

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

-- | /See:/ 'newRegisterCluster' smart constructor.
data RegisterCluster = RegisterCluster'
  { -- | Unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the request.
    RegisterCluster -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | Define a unique name for this cluster within your AWS account.
    RegisterCluster -> Text
name :: Prelude.Text,
    -- | The configuration settings required to connect the Kubernetes cluster to
    -- the Amazon EKS control plane.
    RegisterCluster -> ConnectorConfigRequest
connectorConfig :: ConnectorConfigRequest
  }
  deriving (RegisterCluster -> RegisterCluster -> Bool
(RegisterCluster -> RegisterCluster -> Bool)
-> (RegisterCluster -> RegisterCluster -> Bool)
-> Eq RegisterCluster
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterCluster -> RegisterCluster -> Bool
$c/= :: RegisterCluster -> RegisterCluster -> Bool
== :: RegisterCluster -> RegisterCluster -> Bool
$c== :: RegisterCluster -> RegisterCluster -> Bool
Prelude.Eq, ReadPrec [RegisterCluster]
ReadPrec RegisterCluster
Int -> ReadS RegisterCluster
ReadS [RegisterCluster]
(Int -> ReadS RegisterCluster)
-> ReadS [RegisterCluster]
-> ReadPrec RegisterCluster
-> ReadPrec [RegisterCluster]
-> Read RegisterCluster
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterCluster]
$creadListPrec :: ReadPrec [RegisterCluster]
readPrec :: ReadPrec RegisterCluster
$creadPrec :: ReadPrec RegisterCluster
readList :: ReadS [RegisterCluster]
$creadList :: ReadS [RegisterCluster]
readsPrec :: Int -> ReadS RegisterCluster
$creadsPrec :: Int -> ReadS RegisterCluster
Prelude.Read, Int -> RegisterCluster -> ShowS
[RegisterCluster] -> ShowS
RegisterCluster -> String
(Int -> RegisterCluster -> ShowS)
-> (RegisterCluster -> String)
-> ([RegisterCluster] -> ShowS)
-> Show RegisterCluster
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterCluster] -> ShowS
$cshowList :: [RegisterCluster] -> ShowS
show :: RegisterCluster -> String
$cshow :: RegisterCluster -> String
showsPrec :: Int -> RegisterCluster -> ShowS
$cshowsPrec :: Int -> RegisterCluster -> ShowS
Prelude.Show, (forall x. RegisterCluster -> Rep RegisterCluster x)
-> (forall x. Rep RegisterCluster x -> RegisterCluster)
-> Generic RegisterCluster
forall x. Rep RegisterCluster x -> RegisterCluster
forall x. RegisterCluster -> Rep RegisterCluster x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterCluster x -> RegisterCluster
$cfrom :: forall x. RegisterCluster -> Rep RegisterCluster x
Prelude.Generic)

-- |
-- Create a value of 'RegisterCluster' 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:
--
-- 'clientRequestToken', 'registerCluster_clientRequestToken' - Unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
--
-- 'name', 'registerCluster_name' - Define a unique name for this cluster within your AWS account.
--
-- 'connectorConfig', 'registerCluster_connectorConfig' - The configuration settings required to connect the Kubernetes cluster to
-- the Amazon EKS control plane.
newRegisterCluster ::
  -- | 'name'
  Prelude.Text ->
  -- | 'connectorConfig'
  ConnectorConfigRequest ->
  RegisterCluster
newRegisterCluster :: Text -> ConnectorConfigRequest -> RegisterCluster
newRegisterCluster Text
pName_ ConnectorConfigRequest
pConnectorConfig_ =
  RegisterCluster' :: Maybe Text -> Text -> ConnectorConfigRequest -> RegisterCluster
RegisterCluster'
    { $sel:clientRequestToken:RegisterCluster' :: Maybe Text
clientRequestToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:RegisterCluster' :: Text
name = Text
pName_,
      $sel:connectorConfig:RegisterCluster' :: ConnectorConfigRequest
connectorConfig = ConnectorConfigRequest
pConnectorConfig_
    }

-- | Unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
registerCluster_clientRequestToken :: Lens.Lens' RegisterCluster (Prelude.Maybe Prelude.Text)
registerCluster_clientRequestToken :: (Maybe Text -> f (Maybe Text))
-> RegisterCluster -> f RegisterCluster
registerCluster_clientRequestToken = (RegisterCluster -> Maybe Text)
-> (RegisterCluster -> Maybe Text -> RegisterCluster)
-> Lens RegisterCluster RegisterCluster (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterCluster' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:RegisterCluster' :: RegisterCluster -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: RegisterCluster
s@RegisterCluster' {} Maybe Text
a -> RegisterCluster
s {$sel:clientRequestToken:RegisterCluster' :: Maybe Text
clientRequestToken = Maybe Text
a} :: RegisterCluster)

-- | Define a unique name for this cluster within your AWS account.
registerCluster_name :: Lens.Lens' RegisterCluster Prelude.Text
registerCluster_name :: (Text -> f Text) -> RegisterCluster -> f RegisterCluster
registerCluster_name = (RegisterCluster -> Text)
-> (RegisterCluster -> Text -> RegisterCluster)
-> Lens RegisterCluster RegisterCluster Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterCluster' {Text
name :: Text
$sel:name:RegisterCluster' :: RegisterCluster -> Text
name} -> Text
name) (\s :: RegisterCluster
s@RegisterCluster' {} Text
a -> RegisterCluster
s {$sel:name:RegisterCluster' :: Text
name = Text
a} :: RegisterCluster)

-- | The configuration settings required to connect the Kubernetes cluster to
-- the Amazon EKS control plane.
registerCluster_connectorConfig :: Lens.Lens' RegisterCluster ConnectorConfigRequest
registerCluster_connectorConfig :: (ConnectorConfigRequest -> f ConnectorConfigRequest)
-> RegisterCluster -> f RegisterCluster
registerCluster_connectorConfig = (RegisterCluster -> ConnectorConfigRequest)
-> (RegisterCluster -> ConnectorConfigRequest -> RegisterCluster)
-> Lens
     RegisterCluster
     RegisterCluster
     ConnectorConfigRequest
     ConnectorConfigRequest
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterCluster' {ConnectorConfigRequest
connectorConfig :: ConnectorConfigRequest
$sel:connectorConfig:RegisterCluster' :: RegisterCluster -> ConnectorConfigRequest
connectorConfig} -> ConnectorConfigRequest
connectorConfig) (\s :: RegisterCluster
s@RegisterCluster' {} ConnectorConfigRequest
a -> RegisterCluster
s {$sel:connectorConfig:RegisterCluster' :: ConnectorConfigRequest
connectorConfig = ConnectorConfigRequest
a} :: RegisterCluster)

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

instance Prelude.NFData RegisterCluster

instance Core.ToHeaders RegisterCluster where
  toHeaders :: RegisterCluster -> ResponseHeaders
toHeaders =
    ResponseHeaders -> RegisterCluster -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 RegisterCluster where
  toJSON :: RegisterCluster -> Value
toJSON RegisterCluster' {Maybe Text
Text
ConnectorConfigRequest
connectorConfig :: ConnectorConfigRequest
name :: Text
clientRequestToken :: Maybe Text
$sel:connectorConfig:RegisterCluster' :: RegisterCluster -> ConnectorConfigRequest
$sel:name:RegisterCluster' :: RegisterCluster -> Text
$sel:clientRequestToken:RegisterCluster' :: RegisterCluster -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"clientRequestToken" 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
clientRequestToken,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"connectorConfig" Text -> ConnectorConfigRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ConnectorConfigRequest
connectorConfig)
          ]
      )

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

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

-- | /See:/ 'newRegisterClusterResponse' smart constructor.
data RegisterClusterResponse = RegisterClusterResponse'
  { RegisterClusterResponse -> Maybe Cluster
cluster :: Prelude.Maybe Cluster,
    -- | The response's http status code.
    RegisterClusterResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (RegisterClusterResponse -> RegisterClusterResponse -> Bool
(RegisterClusterResponse -> RegisterClusterResponse -> Bool)
-> (RegisterClusterResponse -> RegisterClusterResponse -> Bool)
-> Eq RegisterClusterResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RegisterClusterResponse -> RegisterClusterResponse -> Bool
$c/= :: RegisterClusterResponse -> RegisterClusterResponse -> Bool
== :: RegisterClusterResponse -> RegisterClusterResponse -> Bool
$c== :: RegisterClusterResponse -> RegisterClusterResponse -> Bool
Prelude.Eq, ReadPrec [RegisterClusterResponse]
ReadPrec RegisterClusterResponse
Int -> ReadS RegisterClusterResponse
ReadS [RegisterClusterResponse]
(Int -> ReadS RegisterClusterResponse)
-> ReadS [RegisterClusterResponse]
-> ReadPrec RegisterClusterResponse
-> ReadPrec [RegisterClusterResponse]
-> Read RegisterClusterResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RegisterClusterResponse]
$creadListPrec :: ReadPrec [RegisterClusterResponse]
readPrec :: ReadPrec RegisterClusterResponse
$creadPrec :: ReadPrec RegisterClusterResponse
readList :: ReadS [RegisterClusterResponse]
$creadList :: ReadS [RegisterClusterResponse]
readsPrec :: Int -> ReadS RegisterClusterResponse
$creadsPrec :: Int -> ReadS RegisterClusterResponse
Prelude.Read, Int -> RegisterClusterResponse -> ShowS
[RegisterClusterResponse] -> ShowS
RegisterClusterResponse -> String
(Int -> RegisterClusterResponse -> ShowS)
-> (RegisterClusterResponse -> String)
-> ([RegisterClusterResponse] -> ShowS)
-> Show RegisterClusterResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RegisterClusterResponse] -> ShowS
$cshowList :: [RegisterClusterResponse] -> ShowS
show :: RegisterClusterResponse -> String
$cshow :: RegisterClusterResponse -> String
showsPrec :: Int -> RegisterClusterResponse -> ShowS
$cshowsPrec :: Int -> RegisterClusterResponse -> ShowS
Prelude.Show, (forall x.
 RegisterClusterResponse -> Rep RegisterClusterResponse x)
-> (forall x.
    Rep RegisterClusterResponse x -> RegisterClusterResponse)
-> Generic RegisterClusterResponse
forall x. Rep RegisterClusterResponse x -> RegisterClusterResponse
forall x. RegisterClusterResponse -> Rep RegisterClusterResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RegisterClusterResponse x -> RegisterClusterResponse
$cfrom :: forall x. RegisterClusterResponse -> Rep RegisterClusterResponse x
Prelude.Generic)

-- |
-- Create a value of 'RegisterClusterResponse' 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:
--
-- 'cluster', 'registerClusterResponse_cluster' - Undocumented member.
--
-- 'httpStatus', 'registerClusterResponse_httpStatus' - The response's http status code.
newRegisterClusterResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  RegisterClusterResponse
newRegisterClusterResponse :: Int -> RegisterClusterResponse
newRegisterClusterResponse Int
pHttpStatus_ =
  RegisterClusterResponse' :: Maybe Cluster -> Int -> RegisterClusterResponse
RegisterClusterResponse'
    { $sel:cluster:RegisterClusterResponse' :: Maybe Cluster
cluster = Maybe Cluster
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:RegisterClusterResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Undocumented member.
registerClusterResponse_cluster :: Lens.Lens' RegisterClusterResponse (Prelude.Maybe Cluster)
registerClusterResponse_cluster :: (Maybe Cluster -> f (Maybe Cluster))
-> RegisterClusterResponse -> f RegisterClusterResponse
registerClusterResponse_cluster = (RegisterClusterResponse -> Maybe Cluster)
-> (RegisterClusterResponse
    -> Maybe Cluster -> RegisterClusterResponse)
-> Lens
     RegisterClusterResponse
     RegisterClusterResponse
     (Maybe Cluster)
     (Maybe Cluster)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RegisterClusterResponse' {Maybe Cluster
cluster :: Maybe Cluster
$sel:cluster:RegisterClusterResponse' :: RegisterClusterResponse -> Maybe Cluster
cluster} -> Maybe Cluster
cluster) (\s :: RegisterClusterResponse
s@RegisterClusterResponse' {} Maybe Cluster
a -> RegisterClusterResponse
s {$sel:cluster:RegisterClusterResponse' :: Maybe Cluster
cluster = Maybe Cluster
a} :: RegisterClusterResponse)

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

instance Prelude.NFData RegisterClusterResponse