{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.SourceConfiguration
-- 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)
module Amazonka.AppRunner.Types.SourceConfiguration where

import Amazonka.AppRunner.Types.AuthenticationConfiguration
import Amazonka.AppRunner.Types.CodeRepository
import Amazonka.AppRunner.Types.ImageRepository
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the source deployed to an App Runner service. It can be a code
-- or an image repository.
--
-- /See:/ 'newSourceConfiguration' smart constructor.
data SourceConfiguration = SourceConfiguration'
  { -- | The description of a source image repository.
    --
    -- You must provide either this member or @CodeRepository@ (but not both).
    SourceConfiguration -> Maybe ImageRepository
imageRepository :: Prelude.Maybe ImageRepository,
    -- | The description of a source code repository.
    --
    -- You must provide either this member or @ImageRepository@ (but not both).
    SourceConfiguration -> Maybe CodeRepository
codeRepository :: Prelude.Maybe CodeRepository,
    -- | If @true@, continuous integration from the source repository is enabled
    -- for the App Runner service. Each repository change (including any source
    -- code commit or new image version) starts a deployment.
    --
    -- Default: App Runner sets to @false@ for a source image that uses an ECR
    -- Public repository or an ECR repository that\'s in an Amazon Web Services
    -- account other than the one that the service is in. App Runner sets to
    -- @true@ in all other cases (which currently include a source code
    -- repository or a source image using a same-account ECR repository).
    SourceConfiguration -> Maybe Bool
autoDeploymentsEnabled :: Prelude.Maybe Prelude.Bool,
    -- | Describes the resources that are needed to authenticate access to some
    -- source repositories.
    SourceConfiguration -> Maybe AuthenticationConfiguration
authenticationConfiguration :: Prelude.Maybe AuthenticationConfiguration
  }
  deriving (SourceConfiguration -> SourceConfiguration -> Bool
(SourceConfiguration -> SourceConfiguration -> Bool)
-> (SourceConfiguration -> SourceConfiguration -> Bool)
-> Eq SourceConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceConfiguration -> SourceConfiguration -> Bool
$c/= :: SourceConfiguration -> SourceConfiguration -> Bool
== :: SourceConfiguration -> SourceConfiguration -> Bool
$c== :: SourceConfiguration -> SourceConfiguration -> Bool
Prelude.Eq, Int -> SourceConfiguration -> ShowS
[SourceConfiguration] -> ShowS
SourceConfiguration -> String
(Int -> SourceConfiguration -> ShowS)
-> (SourceConfiguration -> String)
-> ([SourceConfiguration] -> ShowS)
-> Show SourceConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceConfiguration] -> ShowS
$cshowList :: [SourceConfiguration] -> ShowS
show :: SourceConfiguration -> String
$cshow :: SourceConfiguration -> String
showsPrec :: Int -> SourceConfiguration -> ShowS
$cshowsPrec :: Int -> SourceConfiguration -> ShowS
Prelude.Show, (forall x. SourceConfiguration -> Rep SourceConfiguration x)
-> (forall x. Rep SourceConfiguration x -> SourceConfiguration)
-> Generic SourceConfiguration
forall x. Rep SourceConfiguration x -> SourceConfiguration
forall x. SourceConfiguration -> Rep SourceConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceConfiguration x -> SourceConfiguration
$cfrom :: forall x. SourceConfiguration -> Rep SourceConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'SourceConfiguration' 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:
--
-- 'imageRepository', 'sourceConfiguration_imageRepository' - The description of a source image repository.
--
-- You must provide either this member or @CodeRepository@ (but not both).
--
-- 'codeRepository', 'sourceConfiguration_codeRepository' - The description of a source code repository.
--
-- You must provide either this member or @ImageRepository@ (but not both).
--
-- 'autoDeploymentsEnabled', 'sourceConfiguration_autoDeploymentsEnabled' - If @true@, continuous integration from the source repository is enabled
-- for the App Runner service. Each repository change (including any source
-- code commit or new image version) starts a deployment.
--
-- Default: App Runner sets to @false@ for a source image that uses an ECR
-- Public repository or an ECR repository that\'s in an Amazon Web Services
-- account other than the one that the service is in. App Runner sets to
-- @true@ in all other cases (which currently include a source code
-- repository or a source image using a same-account ECR repository).
--
-- 'authenticationConfiguration', 'sourceConfiguration_authenticationConfiguration' - Describes the resources that are needed to authenticate access to some
-- source repositories.
newSourceConfiguration ::
  SourceConfiguration
newSourceConfiguration :: SourceConfiguration
newSourceConfiguration =
  SourceConfiguration' :: Maybe ImageRepository
-> Maybe CodeRepository
-> Maybe Bool
-> Maybe AuthenticationConfiguration
-> SourceConfiguration
SourceConfiguration'
    { $sel:imageRepository:SourceConfiguration' :: Maybe ImageRepository
imageRepository =
        Maybe ImageRepository
forall a. Maybe a
Prelude.Nothing,
      $sel:codeRepository:SourceConfiguration' :: Maybe CodeRepository
codeRepository = Maybe CodeRepository
forall a. Maybe a
Prelude.Nothing,
      $sel:autoDeploymentsEnabled:SourceConfiguration' :: Maybe Bool
autoDeploymentsEnabled = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:authenticationConfiguration:SourceConfiguration' :: Maybe AuthenticationConfiguration
authenticationConfiguration = Maybe AuthenticationConfiguration
forall a. Maybe a
Prelude.Nothing
    }

-- | The description of a source image repository.
--
-- You must provide either this member or @CodeRepository@ (but not both).
sourceConfiguration_imageRepository :: Lens.Lens' SourceConfiguration (Prelude.Maybe ImageRepository)
sourceConfiguration_imageRepository :: (Maybe ImageRepository -> f (Maybe ImageRepository))
-> SourceConfiguration -> f SourceConfiguration
sourceConfiguration_imageRepository = (SourceConfiguration -> Maybe ImageRepository)
-> (SourceConfiguration
    -> Maybe ImageRepository -> SourceConfiguration)
-> Lens
     SourceConfiguration
     SourceConfiguration
     (Maybe ImageRepository)
     (Maybe ImageRepository)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceConfiguration' {Maybe ImageRepository
imageRepository :: Maybe ImageRepository
$sel:imageRepository:SourceConfiguration' :: SourceConfiguration -> Maybe ImageRepository
imageRepository} -> Maybe ImageRepository
imageRepository) (\s :: SourceConfiguration
s@SourceConfiguration' {} Maybe ImageRepository
a -> SourceConfiguration
s {$sel:imageRepository:SourceConfiguration' :: Maybe ImageRepository
imageRepository = Maybe ImageRepository
a} :: SourceConfiguration)

-- | The description of a source code repository.
--
-- You must provide either this member or @ImageRepository@ (but not both).
sourceConfiguration_codeRepository :: Lens.Lens' SourceConfiguration (Prelude.Maybe CodeRepository)
sourceConfiguration_codeRepository :: (Maybe CodeRepository -> f (Maybe CodeRepository))
-> SourceConfiguration -> f SourceConfiguration
sourceConfiguration_codeRepository = (SourceConfiguration -> Maybe CodeRepository)
-> (SourceConfiguration
    -> Maybe CodeRepository -> SourceConfiguration)
-> Lens
     SourceConfiguration
     SourceConfiguration
     (Maybe CodeRepository)
     (Maybe CodeRepository)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceConfiguration' {Maybe CodeRepository
codeRepository :: Maybe CodeRepository
$sel:codeRepository:SourceConfiguration' :: SourceConfiguration -> Maybe CodeRepository
codeRepository} -> Maybe CodeRepository
codeRepository) (\s :: SourceConfiguration
s@SourceConfiguration' {} Maybe CodeRepository
a -> SourceConfiguration
s {$sel:codeRepository:SourceConfiguration' :: Maybe CodeRepository
codeRepository = Maybe CodeRepository
a} :: SourceConfiguration)

-- | If @true@, continuous integration from the source repository is enabled
-- for the App Runner service. Each repository change (including any source
-- code commit or new image version) starts a deployment.
--
-- Default: App Runner sets to @false@ for a source image that uses an ECR
-- Public repository or an ECR repository that\'s in an Amazon Web Services
-- account other than the one that the service is in. App Runner sets to
-- @true@ in all other cases (which currently include a source code
-- repository or a source image using a same-account ECR repository).
sourceConfiguration_autoDeploymentsEnabled :: Lens.Lens' SourceConfiguration (Prelude.Maybe Prelude.Bool)
sourceConfiguration_autoDeploymentsEnabled :: (Maybe Bool -> f (Maybe Bool))
-> SourceConfiguration -> f SourceConfiguration
sourceConfiguration_autoDeploymentsEnabled = (SourceConfiguration -> Maybe Bool)
-> (SourceConfiguration -> Maybe Bool -> SourceConfiguration)
-> Lens
     SourceConfiguration SourceConfiguration (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceConfiguration' {Maybe Bool
autoDeploymentsEnabled :: Maybe Bool
$sel:autoDeploymentsEnabled:SourceConfiguration' :: SourceConfiguration -> Maybe Bool
autoDeploymentsEnabled} -> Maybe Bool
autoDeploymentsEnabled) (\s :: SourceConfiguration
s@SourceConfiguration' {} Maybe Bool
a -> SourceConfiguration
s {$sel:autoDeploymentsEnabled:SourceConfiguration' :: Maybe Bool
autoDeploymentsEnabled = Maybe Bool
a} :: SourceConfiguration)

-- | Describes the resources that are needed to authenticate access to some
-- source repositories.
sourceConfiguration_authenticationConfiguration :: Lens.Lens' SourceConfiguration (Prelude.Maybe AuthenticationConfiguration)
sourceConfiguration_authenticationConfiguration :: (Maybe AuthenticationConfiguration
 -> f (Maybe AuthenticationConfiguration))
-> SourceConfiguration -> f SourceConfiguration
sourceConfiguration_authenticationConfiguration = (SourceConfiguration -> Maybe AuthenticationConfiguration)
-> (SourceConfiguration
    -> Maybe AuthenticationConfiguration -> SourceConfiguration)
-> Lens
     SourceConfiguration
     SourceConfiguration
     (Maybe AuthenticationConfiguration)
     (Maybe AuthenticationConfiguration)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceConfiguration' {Maybe AuthenticationConfiguration
authenticationConfiguration :: Maybe AuthenticationConfiguration
$sel:authenticationConfiguration:SourceConfiguration' :: SourceConfiguration -> Maybe AuthenticationConfiguration
authenticationConfiguration} -> Maybe AuthenticationConfiguration
authenticationConfiguration) (\s :: SourceConfiguration
s@SourceConfiguration' {} Maybe AuthenticationConfiguration
a -> SourceConfiguration
s {$sel:authenticationConfiguration:SourceConfiguration' :: Maybe AuthenticationConfiguration
authenticationConfiguration = Maybe AuthenticationConfiguration
a} :: SourceConfiguration)

instance Core.FromJSON SourceConfiguration where
  parseJSON :: Value -> Parser SourceConfiguration
parseJSON =
    String
-> (Object -> Parser SourceConfiguration)
-> Value
-> Parser SourceConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SourceConfiguration"
      ( \Object
x ->
          Maybe ImageRepository
-> Maybe CodeRepository
-> Maybe Bool
-> Maybe AuthenticationConfiguration
-> SourceConfiguration
SourceConfiguration'
            (Maybe ImageRepository
 -> Maybe CodeRepository
 -> Maybe Bool
 -> Maybe AuthenticationConfiguration
 -> SourceConfiguration)
-> Parser (Maybe ImageRepository)
-> Parser
     (Maybe CodeRepository
      -> Maybe Bool
      -> Maybe AuthenticationConfiguration
      -> SourceConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe ImageRepository)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ImageRepository")
            Parser
  (Maybe CodeRepository
   -> Maybe Bool
   -> Maybe AuthenticationConfiguration
   -> SourceConfiguration)
-> Parser (Maybe CodeRepository)
-> Parser
     (Maybe Bool
      -> Maybe AuthenticationConfiguration -> SourceConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe CodeRepository)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CodeRepository")
            Parser
  (Maybe Bool
   -> Maybe AuthenticationConfiguration -> SourceConfiguration)
-> Parser (Maybe Bool)
-> Parser
     (Maybe AuthenticationConfiguration -> SourceConfiguration)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AutoDeploymentsEnabled")
            Parser (Maybe AuthenticationConfiguration -> SourceConfiguration)
-> Parser (Maybe AuthenticationConfiguration)
-> Parser SourceConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AuthenticationConfiguration)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"AuthenticationConfiguration")
      )

instance Prelude.Hashable SourceConfiguration

instance Prelude.NFData SourceConfiguration

instance Core.ToJSON SourceConfiguration where
  toJSON :: SourceConfiguration -> Value
toJSON SourceConfiguration' {Maybe Bool
Maybe AuthenticationConfiguration
Maybe ImageRepository
Maybe CodeRepository
authenticationConfiguration :: Maybe AuthenticationConfiguration
autoDeploymentsEnabled :: Maybe Bool
codeRepository :: Maybe CodeRepository
imageRepository :: Maybe ImageRepository
$sel:authenticationConfiguration:SourceConfiguration' :: SourceConfiguration -> Maybe AuthenticationConfiguration
$sel:autoDeploymentsEnabled:SourceConfiguration' :: SourceConfiguration -> Maybe Bool
$sel:codeRepository:SourceConfiguration' :: SourceConfiguration -> Maybe CodeRepository
$sel:imageRepository:SourceConfiguration' :: SourceConfiguration -> Maybe ImageRepository
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ImageRepository" Text -> ImageRepository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (ImageRepository -> Pair) -> Maybe ImageRepository -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ImageRepository
imageRepository,
            (Text
"CodeRepository" Text -> CodeRepository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (CodeRepository -> Pair) -> Maybe CodeRepository -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CodeRepository
codeRepository,
            (Text
"AutoDeploymentsEnabled" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
autoDeploymentsEnabled,
            (Text
"AuthenticationConfiguration" Text -> AuthenticationConfiguration -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (AuthenticationConfiguration -> Pair)
-> Maybe AuthenticationConfiguration -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe AuthenticationConfiguration
authenticationConfiguration
          ]
      )