{-# 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.AppRunner.CreateConnection
-- 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)
--
-- Create an App Runner connection resource. App Runner requires a
-- connection resource when you create App Runner services that access
-- private repositories from certain third-party providers. You can share a
-- connection across multiple services.
--
-- A connection resource is needed to access GitHub repositories. GitHub
-- requires a user interface approval process through the App Runner
-- console before you can use the connection.
module Amazonka.AppRunner.CreateConnection
  ( -- * Creating a Request
    CreateConnection (..),
    newCreateConnection,

    -- * Request Lenses
    createConnection_tags,
    createConnection_connectionName,
    createConnection_providerType,

    -- * Destructuring the Response
    CreateConnectionResponse (..),
    newCreateConnectionResponse,

    -- * Response Lenses
    createConnectionResponse_httpStatus,
    createConnectionResponse_connection,
  )
where

import Amazonka.AppRunner.Types
import qualified Amazonka.Core as Core
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:/ 'newCreateConnection' smart constructor.
data CreateConnection = CreateConnection'
  { -- | A list of metadata items that you can associate with your connection
    -- resource. A tag is a key-value pair.
    CreateConnection -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | A name for the new connection. It must be unique across all App Runner
    -- connections for the Amazon Web Services account in the Amazon Web
    -- Services Region.
    CreateConnection -> Text
connectionName :: Prelude.Text,
    -- | The source repository provider.
    CreateConnection -> ProviderType
providerType :: ProviderType
  }
  deriving (CreateConnection -> CreateConnection -> Bool
(CreateConnection -> CreateConnection -> Bool)
-> (CreateConnection -> CreateConnection -> Bool)
-> Eq CreateConnection
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConnection -> CreateConnection -> Bool
$c/= :: CreateConnection -> CreateConnection -> Bool
== :: CreateConnection -> CreateConnection -> Bool
$c== :: CreateConnection -> CreateConnection -> Bool
Prelude.Eq, ReadPrec [CreateConnection]
ReadPrec CreateConnection
Int -> ReadS CreateConnection
ReadS [CreateConnection]
(Int -> ReadS CreateConnection)
-> ReadS [CreateConnection]
-> ReadPrec CreateConnection
-> ReadPrec [CreateConnection]
-> Read CreateConnection
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConnection]
$creadListPrec :: ReadPrec [CreateConnection]
readPrec :: ReadPrec CreateConnection
$creadPrec :: ReadPrec CreateConnection
readList :: ReadS [CreateConnection]
$creadList :: ReadS [CreateConnection]
readsPrec :: Int -> ReadS CreateConnection
$creadsPrec :: Int -> ReadS CreateConnection
Prelude.Read, Int -> CreateConnection -> ShowS
[CreateConnection] -> ShowS
CreateConnection -> String
(Int -> CreateConnection -> ShowS)
-> (CreateConnection -> String)
-> ([CreateConnection] -> ShowS)
-> Show CreateConnection
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConnection] -> ShowS
$cshowList :: [CreateConnection] -> ShowS
show :: CreateConnection -> String
$cshow :: CreateConnection -> String
showsPrec :: Int -> CreateConnection -> ShowS
$cshowsPrec :: Int -> CreateConnection -> ShowS
Prelude.Show, (forall x. CreateConnection -> Rep CreateConnection x)
-> (forall x. Rep CreateConnection x -> CreateConnection)
-> Generic CreateConnection
forall x. Rep CreateConnection x -> CreateConnection
forall x. CreateConnection -> Rep CreateConnection x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateConnection x -> CreateConnection
$cfrom :: forall x. CreateConnection -> Rep CreateConnection x
Prelude.Generic)

-- |
-- Create a value of 'CreateConnection' 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:
--
-- 'tags', 'createConnection_tags' - A list of metadata items that you can associate with your connection
-- resource. A tag is a key-value pair.
--
-- 'connectionName', 'createConnection_connectionName' - A name for the new connection. It must be unique across all App Runner
-- connections for the Amazon Web Services account in the Amazon Web
-- Services Region.
--
-- 'providerType', 'createConnection_providerType' - The source repository provider.
newCreateConnection ::
  -- | 'connectionName'
  Prelude.Text ->
  -- | 'providerType'
  ProviderType ->
  CreateConnection
newCreateConnection :: Text -> ProviderType -> CreateConnection
newCreateConnection Text
pConnectionName_ ProviderType
pProviderType_ =
  CreateConnection' :: Maybe [Tag] -> Text -> ProviderType -> CreateConnection
CreateConnection'
    { $sel:tags:CreateConnection' :: Maybe [Tag]
tags = Maybe [Tag]
forall a. Maybe a
Prelude.Nothing,
      $sel:connectionName:CreateConnection' :: Text
connectionName = Text
pConnectionName_,
      $sel:providerType:CreateConnection' :: ProviderType
providerType = ProviderType
pProviderType_
    }

-- | A list of metadata items that you can associate with your connection
-- resource. A tag is a key-value pair.
createConnection_tags :: Lens.Lens' CreateConnection (Prelude.Maybe [Tag])
createConnection_tags :: (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateConnection -> f CreateConnection
createConnection_tags = (CreateConnection -> Maybe [Tag])
-> (CreateConnection -> Maybe [Tag] -> CreateConnection)
-> Lens
     CreateConnection CreateConnection (Maybe [Tag]) (Maybe [Tag])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateConnection' :: CreateConnection -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateConnection
s@CreateConnection' {} Maybe [Tag]
a -> CreateConnection
s {$sel:tags:CreateConnection' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateConnection) ((Maybe [Tag] -> f (Maybe [Tag]))
 -> CreateConnection -> f CreateConnection)
-> ((Maybe [Tag] -> f (Maybe [Tag]))
    -> Maybe [Tag] -> f (Maybe [Tag]))
-> (Maybe [Tag] -> f (Maybe [Tag]))
-> CreateConnection
-> f CreateConnection
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Tag] [Tag] [Tag] [Tag]
-> Iso (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag]) (Maybe [Tag])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Tag] [Tag] [Tag] [Tag]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A name for the new connection. It must be unique across all App Runner
-- connections for the Amazon Web Services account in the Amazon Web
-- Services Region.
createConnection_connectionName :: Lens.Lens' CreateConnection Prelude.Text
createConnection_connectionName :: (Text -> f Text) -> CreateConnection -> f CreateConnection
createConnection_connectionName = (CreateConnection -> Text)
-> (CreateConnection -> Text -> CreateConnection)
-> Lens CreateConnection CreateConnection Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {Text
connectionName :: Text
$sel:connectionName:CreateConnection' :: CreateConnection -> Text
connectionName} -> Text
connectionName) (\s :: CreateConnection
s@CreateConnection' {} Text
a -> CreateConnection
s {$sel:connectionName:CreateConnection' :: Text
connectionName = Text
a} :: CreateConnection)

-- | The source repository provider.
createConnection_providerType :: Lens.Lens' CreateConnection ProviderType
createConnection_providerType :: (ProviderType -> f ProviderType)
-> CreateConnection -> f CreateConnection
createConnection_providerType = (CreateConnection -> ProviderType)
-> (CreateConnection -> ProviderType -> CreateConnection)
-> Lens CreateConnection CreateConnection ProviderType ProviderType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnection' {ProviderType
providerType :: ProviderType
$sel:providerType:CreateConnection' :: CreateConnection -> ProviderType
providerType} -> ProviderType
providerType) (\s :: CreateConnection
s@CreateConnection' {} ProviderType
a -> CreateConnection
s {$sel:providerType:CreateConnection' :: ProviderType
providerType = ProviderType
a} :: CreateConnection)

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

instance Prelude.Hashable CreateConnection

instance Prelude.NFData CreateConnection

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

instance Core.ToJSON CreateConnection where
  toJSON :: CreateConnection -> Value
toJSON CreateConnection' {Maybe [Tag]
Text
ProviderType
providerType :: ProviderType
connectionName :: Text
tags :: Maybe [Tag]
$sel:providerType:CreateConnection' :: CreateConnection -> ProviderType
$sel:connectionName:CreateConnection' :: CreateConnection -> Text
$sel:tags:CreateConnection' :: CreateConnection -> Maybe [Tag]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Tags" Text -> [Tag] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Tag] -> Pair) -> Maybe [Tag] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Tag]
tags,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ConnectionName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
connectionName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ProviderType" Text -> ProviderType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ProviderType
providerType)
          ]
      )

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

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

-- | /See:/ 'newCreateConnectionResponse' smart constructor.
data CreateConnectionResponse = CreateConnectionResponse'
  { -- | The response's http status code.
    CreateConnectionResponse -> Int
httpStatus :: Prelude.Int,
    -- | A description of the App Runner connection that\'s created by this
    -- request.
    CreateConnectionResponse -> Connection
connection :: Connection
  }
  deriving (CreateConnectionResponse -> CreateConnectionResponse -> Bool
(CreateConnectionResponse -> CreateConnectionResponse -> Bool)
-> (CreateConnectionResponse -> CreateConnectionResponse -> Bool)
-> Eq CreateConnectionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
$c/= :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
== :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
$c== :: CreateConnectionResponse -> CreateConnectionResponse -> Bool
Prelude.Eq, ReadPrec [CreateConnectionResponse]
ReadPrec CreateConnectionResponse
Int -> ReadS CreateConnectionResponse
ReadS [CreateConnectionResponse]
(Int -> ReadS CreateConnectionResponse)
-> ReadS [CreateConnectionResponse]
-> ReadPrec CreateConnectionResponse
-> ReadPrec [CreateConnectionResponse]
-> Read CreateConnectionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateConnectionResponse]
$creadListPrec :: ReadPrec [CreateConnectionResponse]
readPrec :: ReadPrec CreateConnectionResponse
$creadPrec :: ReadPrec CreateConnectionResponse
readList :: ReadS [CreateConnectionResponse]
$creadList :: ReadS [CreateConnectionResponse]
readsPrec :: Int -> ReadS CreateConnectionResponse
$creadsPrec :: Int -> ReadS CreateConnectionResponse
Prelude.Read, Int -> CreateConnectionResponse -> ShowS
[CreateConnectionResponse] -> ShowS
CreateConnectionResponse -> String
(Int -> CreateConnectionResponse -> ShowS)
-> (CreateConnectionResponse -> String)
-> ([CreateConnectionResponse] -> ShowS)
-> Show CreateConnectionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateConnectionResponse] -> ShowS
$cshowList :: [CreateConnectionResponse] -> ShowS
show :: CreateConnectionResponse -> String
$cshow :: CreateConnectionResponse -> String
showsPrec :: Int -> CreateConnectionResponse -> ShowS
$cshowsPrec :: Int -> CreateConnectionResponse -> ShowS
Prelude.Show, (forall x.
 CreateConnectionResponse -> Rep CreateConnectionResponse x)
-> (forall x.
    Rep CreateConnectionResponse x -> CreateConnectionResponse)
-> Generic CreateConnectionResponse
forall x.
Rep CreateConnectionResponse x -> CreateConnectionResponse
forall x.
CreateConnectionResponse -> Rep CreateConnectionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateConnectionResponse x -> CreateConnectionResponse
$cfrom :: forall x.
CreateConnectionResponse -> Rep CreateConnectionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateConnectionResponse' 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:
--
-- 'httpStatus', 'createConnectionResponse_httpStatus' - The response's http status code.
--
-- 'connection', 'createConnectionResponse_connection' - A description of the App Runner connection that\'s created by this
-- request.
newCreateConnectionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'connection'
  Connection ->
  CreateConnectionResponse
newCreateConnectionResponse :: Int -> Connection -> CreateConnectionResponse
newCreateConnectionResponse Int
pHttpStatus_ Connection
pConnection_ =
  CreateConnectionResponse' :: Int -> Connection -> CreateConnectionResponse
CreateConnectionResponse'
    { $sel:httpStatus:CreateConnectionResponse' :: Int
httpStatus =
        Int
pHttpStatus_,
      $sel:connection:CreateConnectionResponse' :: Connection
connection = Connection
pConnection_
    }

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

-- | A description of the App Runner connection that\'s created by this
-- request.
createConnectionResponse_connection :: Lens.Lens' CreateConnectionResponse Connection
createConnectionResponse_connection :: (Connection -> f Connection)
-> CreateConnectionResponse -> f CreateConnectionResponse
createConnectionResponse_connection = (CreateConnectionResponse -> Connection)
-> (CreateConnectionResponse
    -> Connection -> CreateConnectionResponse)
-> Lens
     CreateConnectionResponse
     CreateConnectionResponse
     Connection
     Connection
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateConnectionResponse' {Connection
connection :: Connection
$sel:connection:CreateConnectionResponse' :: CreateConnectionResponse -> Connection
connection} -> Connection
connection) (\s :: CreateConnectionResponse
s@CreateConnectionResponse' {} Connection
a -> CreateConnectionResponse
s {$sel:connection:CreateConnectionResponse' :: Connection
connection = Connection
a} :: CreateConnectionResponse)

instance Prelude.NFData CreateConnectionResponse