{-# 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.OpenInstancePublicPorts
-- 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)
--
-- Opens ports for a specific Amazon Lightsail instance, and specifies the
-- IP addresses allowed to connect to the instance through the ports, and
-- the protocol.
--
-- The @OpenInstancePublicPorts@ 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.OpenInstancePublicPorts
  ( -- * Creating a Request
    OpenInstancePublicPorts (..),
    newOpenInstancePublicPorts,

    -- * Request Lenses
    openInstancePublicPorts_portInfo,
    openInstancePublicPorts_instanceName,

    -- * Destructuring the Response
    OpenInstancePublicPortsResponse (..),
    newOpenInstancePublicPortsResponse,

    -- * Response Lenses
    openInstancePublicPortsResponse_operation,
    openInstancePublicPortsResponse_httpStatus,
  )
where

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

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

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

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

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

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

instance Prelude.NFData OpenInstancePublicPorts

instance Core.ToHeaders OpenInstancePublicPorts where
  toHeaders :: OpenInstancePublicPorts -> ResponseHeaders
toHeaders =
    ResponseHeaders -> OpenInstancePublicPorts -> 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
"Lightsail_20161128.OpenInstancePublicPorts" ::
                          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 OpenInstancePublicPorts where
  toJSON :: OpenInstancePublicPorts -> Value
toJSON OpenInstancePublicPorts' {Text
PortInfo
instanceName :: Text
portInfo :: PortInfo
$sel:instanceName:OpenInstancePublicPorts' :: OpenInstancePublicPorts -> Text
$sel:portInfo:OpenInstancePublicPorts' :: OpenInstancePublicPorts -> PortInfo
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"portInfo" Text -> PortInfo -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PortInfo
portInfo),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"instanceName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
instanceName)
          ]
      )

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

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

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

-- |
-- Create a value of 'OpenInstancePublicPortsResponse' 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', 'openInstancePublicPortsResponse_operation' - An array of objects that describe 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', 'openInstancePublicPortsResponse_httpStatus' - The response's http status code.
newOpenInstancePublicPortsResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  OpenInstancePublicPortsResponse
newOpenInstancePublicPortsResponse :: Int -> OpenInstancePublicPortsResponse
newOpenInstancePublicPortsResponse Int
pHttpStatus_ =
  OpenInstancePublicPortsResponse' :: Maybe Operation -> Int -> OpenInstancePublicPortsResponse
OpenInstancePublicPortsResponse'
    { $sel:operation:OpenInstancePublicPortsResponse' :: Maybe Operation
operation =
        Maybe Operation
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:OpenInstancePublicPortsResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

instance
  Prelude.NFData
    OpenInstancePublicPortsResponse