{-# 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.CodeBuild.Types.SourceAuth
-- 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.CodeBuild.Types.SourceAuth where

import Amazonka.CodeBuild.Types.SourceAuthType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about the authorization settings for CodeBuild to access the
-- source code to be built.
--
-- This information is for the CodeBuild console\'s use only. Your code
-- should not get or set this information directly.
--
-- /See:/ 'newSourceAuth' smart constructor.
data SourceAuth = SourceAuth'
  { -- | The resource value that applies to the specified authorization type.
    SourceAuth -> Maybe Text
resource :: Prelude.Maybe Prelude.Text,
    -- | This data type is deprecated and is no longer accurate or used.
    --
    -- The authorization type to use. The only valid value is @OAUTH@, which
    -- represents the OAuth authorization type.
    SourceAuth -> SourceAuthType
type' :: SourceAuthType
  }
  deriving (SourceAuth -> SourceAuth -> Bool
(SourceAuth -> SourceAuth -> Bool)
-> (SourceAuth -> SourceAuth -> Bool) -> Eq SourceAuth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SourceAuth -> SourceAuth -> Bool
$c/= :: SourceAuth -> SourceAuth -> Bool
== :: SourceAuth -> SourceAuth -> Bool
$c== :: SourceAuth -> SourceAuth -> Bool
Prelude.Eq, ReadPrec [SourceAuth]
ReadPrec SourceAuth
Int -> ReadS SourceAuth
ReadS [SourceAuth]
(Int -> ReadS SourceAuth)
-> ReadS [SourceAuth]
-> ReadPrec SourceAuth
-> ReadPrec [SourceAuth]
-> Read SourceAuth
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SourceAuth]
$creadListPrec :: ReadPrec [SourceAuth]
readPrec :: ReadPrec SourceAuth
$creadPrec :: ReadPrec SourceAuth
readList :: ReadS [SourceAuth]
$creadList :: ReadS [SourceAuth]
readsPrec :: Int -> ReadS SourceAuth
$creadsPrec :: Int -> ReadS SourceAuth
Prelude.Read, Int -> SourceAuth -> ShowS
[SourceAuth] -> ShowS
SourceAuth -> String
(Int -> SourceAuth -> ShowS)
-> (SourceAuth -> String)
-> ([SourceAuth] -> ShowS)
-> Show SourceAuth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SourceAuth] -> ShowS
$cshowList :: [SourceAuth] -> ShowS
show :: SourceAuth -> String
$cshow :: SourceAuth -> String
showsPrec :: Int -> SourceAuth -> ShowS
$cshowsPrec :: Int -> SourceAuth -> ShowS
Prelude.Show, (forall x. SourceAuth -> Rep SourceAuth x)
-> (forall x. Rep SourceAuth x -> SourceAuth) -> Generic SourceAuth
forall x. Rep SourceAuth x -> SourceAuth
forall x. SourceAuth -> Rep SourceAuth x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SourceAuth x -> SourceAuth
$cfrom :: forall x. SourceAuth -> Rep SourceAuth x
Prelude.Generic)

-- |
-- Create a value of 'SourceAuth' 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:
--
-- 'resource', 'sourceAuth_resource' - The resource value that applies to the specified authorization type.
--
-- 'type'', 'sourceAuth_type' - This data type is deprecated and is no longer accurate or used.
--
-- The authorization type to use. The only valid value is @OAUTH@, which
-- represents the OAuth authorization type.
newSourceAuth ::
  -- | 'type''
  SourceAuthType ->
  SourceAuth
newSourceAuth :: SourceAuthType -> SourceAuth
newSourceAuth SourceAuthType
pType_ =
  SourceAuth' :: Maybe Text -> SourceAuthType -> SourceAuth
SourceAuth'
    { $sel:resource:SourceAuth' :: Maybe Text
resource = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:type':SourceAuth' :: SourceAuthType
type' = SourceAuthType
pType_
    }

-- | The resource value that applies to the specified authorization type.
sourceAuth_resource :: Lens.Lens' SourceAuth (Prelude.Maybe Prelude.Text)
sourceAuth_resource :: (Maybe Text -> f (Maybe Text)) -> SourceAuth -> f SourceAuth
sourceAuth_resource = (SourceAuth -> Maybe Text)
-> (SourceAuth -> Maybe Text -> SourceAuth)
-> Lens SourceAuth SourceAuth (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceAuth' {Maybe Text
resource :: Maybe Text
$sel:resource:SourceAuth' :: SourceAuth -> Maybe Text
resource} -> Maybe Text
resource) (\s :: SourceAuth
s@SourceAuth' {} Maybe Text
a -> SourceAuth
s {$sel:resource:SourceAuth' :: Maybe Text
resource = Maybe Text
a} :: SourceAuth)

-- | This data type is deprecated and is no longer accurate or used.
--
-- The authorization type to use. The only valid value is @OAUTH@, which
-- represents the OAuth authorization type.
sourceAuth_type :: Lens.Lens' SourceAuth SourceAuthType
sourceAuth_type :: (SourceAuthType -> f SourceAuthType) -> SourceAuth -> f SourceAuth
sourceAuth_type = (SourceAuth -> SourceAuthType)
-> (SourceAuth -> SourceAuthType -> SourceAuth)
-> Lens SourceAuth SourceAuth SourceAuthType SourceAuthType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SourceAuth' {SourceAuthType
type' :: SourceAuthType
$sel:type':SourceAuth' :: SourceAuth -> SourceAuthType
type'} -> SourceAuthType
type') (\s :: SourceAuth
s@SourceAuth' {} SourceAuthType
a -> SourceAuth
s {$sel:type':SourceAuth' :: SourceAuthType
type' = SourceAuthType
a} :: SourceAuth)

instance Core.FromJSON SourceAuth where
  parseJSON :: Value -> Parser SourceAuth
parseJSON =
    String
-> (Object -> Parser SourceAuth) -> Value -> Parser SourceAuth
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SourceAuth"
      ( \Object
x ->
          Maybe Text -> SourceAuthType -> SourceAuth
SourceAuth'
            (Maybe Text -> SourceAuthType -> SourceAuth)
-> Parser (Maybe Text) -> Parser (SourceAuthType -> SourceAuth)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"resource")
            Parser (SourceAuthType -> SourceAuth)
-> Parser SourceAuthType -> Parser SourceAuth
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser SourceAuthType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable SourceAuth

instance Prelude.NFData SourceAuth

instance Core.ToJSON SourceAuth where
  toJSON :: SourceAuth -> Value
toJSON SourceAuth' {Maybe Text
SourceAuthType
type' :: SourceAuthType
resource :: Maybe Text
$sel:type':SourceAuth' :: SourceAuth -> SourceAuthType
$sel:resource:SourceAuth' :: SourceAuth -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"resource" 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
resource,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> SourceAuthType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= SourceAuthType
type')
          ]
      )