{-# 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.CloseInstancePublicPorts
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Closes ports for a specific Amazon Lightsail instance.
--
-- The @CloseInstancePublicPorts@ action supports tag-based access control
-- via resource tags applied to the resource identified by @instanceName@.
-- 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>.
module Amazonka.Lightsail.CloseInstancePublicPorts
  ( -- * Creating a Request
    CloseInstancePublicPorts (..),
    newCloseInstancePublicPorts,

    -- * Request Lenses
    closeInstancePublicPorts_portInfo,
    closeInstancePublicPorts_instanceName,

    -- * Destructuring the Response
    CloseInstancePublicPortsResponse (..),
    newCloseInstancePublicPortsResponse,

    -- * Response Lenses
    closeInstancePublicPortsResponse_operation,
    closeInstancePublicPortsResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCloseInstancePublicPorts' smart constructor.
data CloseInstancePublicPorts = CloseInstancePublicPorts'
  { -- | An object to describe the ports to close for the specified instance.
    CloseInstancePublicPorts -> PortInfo
portInfo :: PortInfo,
    -- | The name of the instance for which to close ports.
    CloseInstancePublicPorts -> Text
instanceName :: Prelude.Text
  }
  deriving (CloseInstancePublicPorts -> CloseInstancePublicPorts -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CloseInstancePublicPorts -> CloseInstancePublicPorts -> Bool
$c/= :: CloseInstancePublicPorts -> CloseInstancePublicPorts -> Bool
== :: CloseInstancePublicPorts -> CloseInstancePublicPorts -> Bool
$c== :: CloseInstancePublicPorts -> CloseInstancePublicPorts -> Bool
Prelude.Eq, ReadPrec [CloseInstancePublicPorts]
ReadPrec CloseInstancePublicPorts
Int -> ReadS CloseInstancePublicPorts
ReadS [CloseInstancePublicPorts]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CloseInstancePublicPorts]
$creadListPrec :: ReadPrec [CloseInstancePublicPorts]
readPrec :: ReadPrec CloseInstancePublicPorts
$creadPrec :: ReadPrec CloseInstancePublicPorts
readList :: ReadS [CloseInstancePublicPorts]
$creadList :: ReadS [CloseInstancePublicPorts]
readsPrec :: Int -> ReadS CloseInstancePublicPorts
$creadsPrec :: Int -> ReadS CloseInstancePublicPorts
Prelude.Read, Int -> CloseInstancePublicPorts -> ShowS
[CloseInstancePublicPorts] -> ShowS
CloseInstancePublicPorts -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CloseInstancePublicPorts] -> ShowS
$cshowList :: [CloseInstancePublicPorts] -> ShowS
show :: CloseInstancePublicPorts -> String
$cshow :: CloseInstancePublicPorts -> String
showsPrec :: Int -> CloseInstancePublicPorts -> ShowS
$cshowsPrec :: Int -> CloseInstancePublicPorts -> ShowS
Prelude.Show, forall x.
Rep CloseInstancePublicPorts x -> CloseInstancePublicPorts
forall x.
CloseInstancePublicPorts -> Rep CloseInstancePublicPorts x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CloseInstancePublicPorts x -> CloseInstancePublicPorts
$cfrom :: forall x.
CloseInstancePublicPorts -> Rep CloseInstancePublicPorts x
Prelude.Generic)

-- |
-- Create a value of 'CloseInstancePublicPorts' 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:
--
-- 'portInfo', 'closeInstancePublicPorts_portInfo' - An object to describe the ports to close for the specified instance.
--
-- 'instanceName', 'closeInstancePublicPorts_instanceName' - The name of the instance for which to close ports.
newCloseInstancePublicPorts ::
  -- | 'portInfo'
  PortInfo ->
  -- | 'instanceName'
  Prelude.Text ->
  CloseInstancePublicPorts
newCloseInstancePublicPorts :: PortInfo -> Text -> CloseInstancePublicPorts
newCloseInstancePublicPorts PortInfo
pPortInfo_ Text
pInstanceName_ =
  CloseInstancePublicPorts'
    { $sel:portInfo:CloseInstancePublicPorts' :: PortInfo
portInfo = PortInfo
pPortInfo_,
      $sel:instanceName:CloseInstancePublicPorts' :: Text
instanceName = Text
pInstanceName_
    }

-- | An object to describe the ports to close for the specified instance.
closeInstancePublicPorts_portInfo :: Lens.Lens' CloseInstancePublicPorts PortInfo
closeInstancePublicPorts_portInfo :: Lens' CloseInstancePublicPorts PortInfo
closeInstancePublicPorts_portInfo = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloseInstancePublicPorts' {PortInfo
portInfo :: PortInfo
$sel:portInfo:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> PortInfo
portInfo} -> PortInfo
portInfo) (\s :: CloseInstancePublicPorts
s@CloseInstancePublicPorts' {} PortInfo
a -> CloseInstancePublicPorts
s {$sel:portInfo:CloseInstancePublicPorts' :: PortInfo
portInfo = PortInfo
a} :: CloseInstancePublicPorts)

-- | The name of the instance for which to close ports.
closeInstancePublicPorts_instanceName :: Lens.Lens' CloseInstancePublicPorts Prelude.Text
closeInstancePublicPorts_instanceName :: Lens' CloseInstancePublicPorts Text
closeInstancePublicPorts_instanceName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloseInstancePublicPorts' {Text
instanceName :: Text
$sel:instanceName:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> Text
instanceName} -> Text
instanceName) (\s :: CloseInstancePublicPorts
s@CloseInstancePublicPorts' {} Text
a -> CloseInstancePublicPorts
s {$sel:instanceName:CloseInstancePublicPorts' :: Text
instanceName = Text
a} :: CloseInstancePublicPorts)

instance Core.AWSRequest CloseInstancePublicPorts where
  type
    AWSResponse CloseInstancePublicPorts =
      CloseInstancePublicPortsResponse
  request :: (Service -> Service)
-> CloseInstancePublicPorts -> Request CloseInstancePublicPorts
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 CloseInstancePublicPorts
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CloseInstancePublicPorts)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Operation -> Int -> CloseInstancePublicPortsResponse
CloseInstancePublicPortsResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"operation")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CloseInstancePublicPorts where
  hashWithSalt :: Int -> CloseInstancePublicPorts -> Int
hashWithSalt Int
_salt CloseInstancePublicPorts' {Text
PortInfo
instanceName :: Text
portInfo :: PortInfo
$sel:instanceName:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> Text
$sel:portInfo:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> PortInfo
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` PortInfo
portInfo
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
instanceName

instance Prelude.NFData CloseInstancePublicPorts where
  rnf :: CloseInstancePublicPorts -> ()
rnf CloseInstancePublicPorts' {Text
PortInfo
instanceName :: Text
portInfo :: PortInfo
$sel:instanceName:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> Text
$sel:portInfo:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> PortInfo
..} =
    forall a. NFData a => a -> ()
Prelude.rnf PortInfo
portInfo
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
instanceName

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

instance Data.ToJSON CloseInstancePublicPorts where
  toJSON :: CloseInstancePublicPorts -> Value
toJSON CloseInstancePublicPorts' {Text
PortInfo
instanceName :: Text
portInfo :: PortInfo
$sel:instanceName:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> Text
$sel:portInfo:CloseInstancePublicPorts' :: CloseInstancePublicPorts -> PortInfo
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"portInfo" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= PortInfo
portInfo),
            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 CloseInstancePublicPorts where
  toPath :: CloseInstancePublicPorts -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

-- | /See:/ 'newCloseInstancePublicPortsResponse' smart constructor.
data CloseInstancePublicPortsResponse = CloseInstancePublicPortsResponse'
  { -- | An object that describes the result of the action, such as the status of
    -- the request, the timestamp of the request, and the resources affected by
    -- the request.
    CloseInstancePublicPortsResponse -> Maybe Operation
operation :: Prelude.Maybe Operation,
    -- | The response's http status code.
    CloseInstancePublicPortsResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CloseInstancePublicPortsResponse
-> CloseInstancePublicPortsResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CloseInstancePublicPortsResponse
-> CloseInstancePublicPortsResponse -> Bool
$c/= :: CloseInstancePublicPortsResponse
-> CloseInstancePublicPortsResponse -> Bool
== :: CloseInstancePublicPortsResponse
-> CloseInstancePublicPortsResponse -> Bool
$c== :: CloseInstancePublicPortsResponse
-> CloseInstancePublicPortsResponse -> Bool
Prelude.Eq, ReadPrec [CloseInstancePublicPortsResponse]
ReadPrec CloseInstancePublicPortsResponse
Int -> ReadS CloseInstancePublicPortsResponse
ReadS [CloseInstancePublicPortsResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CloseInstancePublicPortsResponse]
$creadListPrec :: ReadPrec [CloseInstancePublicPortsResponse]
readPrec :: ReadPrec CloseInstancePublicPortsResponse
$creadPrec :: ReadPrec CloseInstancePublicPortsResponse
readList :: ReadS [CloseInstancePublicPortsResponse]
$creadList :: ReadS [CloseInstancePublicPortsResponse]
readsPrec :: Int -> ReadS CloseInstancePublicPortsResponse
$creadsPrec :: Int -> ReadS CloseInstancePublicPortsResponse
Prelude.Read, Int -> CloseInstancePublicPortsResponse -> ShowS
[CloseInstancePublicPortsResponse] -> ShowS
CloseInstancePublicPortsResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CloseInstancePublicPortsResponse] -> ShowS
$cshowList :: [CloseInstancePublicPortsResponse] -> ShowS
show :: CloseInstancePublicPortsResponse -> String
$cshow :: CloseInstancePublicPortsResponse -> String
showsPrec :: Int -> CloseInstancePublicPortsResponse -> ShowS
$cshowsPrec :: Int -> CloseInstancePublicPortsResponse -> ShowS
Prelude.Show, forall x.
Rep CloseInstancePublicPortsResponse x
-> CloseInstancePublicPortsResponse
forall x.
CloseInstancePublicPortsResponse
-> Rep CloseInstancePublicPortsResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CloseInstancePublicPortsResponse x
-> CloseInstancePublicPortsResponse
$cfrom :: forall x.
CloseInstancePublicPortsResponse
-> Rep CloseInstancePublicPortsResponse x
Prelude.Generic)

-- |
-- Create a value of 'CloseInstancePublicPortsResponse' 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:
--
-- 'operation', 'closeInstancePublicPortsResponse_operation' - An object that describes 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', 'closeInstancePublicPortsResponse_httpStatus' - The response's http status code.
newCloseInstancePublicPortsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CloseInstancePublicPortsResponse
newCloseInstancePublicPortsResponse :: Int -> CloseInstancePublicPortsResponse
newCloseInstancePublicPortsResponse Int
pHttpStatus_ =
  CloseInstancePublicPortsResponse'
    { $sel:operation:CloseInstancePublicPortsResponse' :: Maybe Operation
operation =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CloseInstancePublicPortsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | An object that describes the result of the action, such as the status of
-- the request, the timestamp of the request, and the resources affected by
-- the request.
closeInstancePublicPortsResponse_operation :: Lens.Lens' CloseInstancePublicPortsResponse (Prelude.Maybe Operation)
closeInstancePublicPortsResponse_operation :: Lens' CloseInstancePublicPortsResponse (Maybe Operation)
closeInstancePublicPortsResponse_operation = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CloseInstancePublicPortsResponse' {Maybe Operation
operation :: Maybe Operation
$sel:operation:CloseInstancePublicPortsResponse' :: CloseInstancePublicPortsResponse -> Maybe Operation
operation} -> Maybe Operation
operation) (\s :: CloseInstancePublicPortsResponse
s@CloseInstancePublicPortsResponse' {} Maybe Operation
a -> CloseInstancePublicPortsResponse
s {$sel:operation:CloseInstancePublicPortsResponse' :: Maybe Operation
operation = Maybe Operation
a} :: CloseInstancePublicPortsResponse)

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

instance
  Prelude.NFData
    CloseInstancePublicPortsResponse
  where
  rnf :: CloseInstancePublicPortsResponse -> ()
rnf CloseInstancePublicPortsResponse' {Int
Maybe Operation
httpStatus :: Int
operation :: Maybe Operation
$sel:httpStatus:CloseInstancePublicPortsResponse' :: CloseInstancePublicPortsResponse -> Int
$sel:operation:CloseInstancePublicPortsResponse' :: CloseInstancePublicPortsResponse -> Maybe Operation
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Operation
operation
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus