{-# 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.ProjectCache
-- 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.ProjectCache where

import Amazonka.CodeBuild.Types.CacheMode
import Amazonka.CodeBuild.Types.CacheType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about the cache for the build project.
--
-- /See:/ 'newProjectCache' smart constructor.
data ProjectCache = ProjectCache'
  { -- | Information about the cache location:
    --
    -- -   @NO_CACHE@ or @LOCAL@: This value is ignored.
    --
    -- -   @S3@: This is the S3 bucket name\/prefix.
    ProjectCache -> Maybe Text
location :: Prelude.Maybe Prelude.Text,
    -- | An array of strings that specify the local cache modes. You can use one
    -- or more local cache modes at the same time. This is only used for
    -- @LOCAL@ cache types.
    --
    -- Possible values are:
    --
    -- [LOCAL_SOURCE_CACHE]
    --     Caches Git metadata for primary and secondary sources. After the
    --     cache is created, subsequent builds pull only the change between
    --     commits. This mode is a good choice for projects with a clean
    --     working directory and a source that is a large Git repository. If
    --     you choose this option and your project does not use a Git
    --     repository (GitHub, GitHub Enterprise, or Bitbucket), the option is
    --     ignored.
    --
    -- [LOCAL_DOCKER_LAYER_CACHE]
    --     Caches existing Docker layers. This mode is a good choice for
    --     projects that build or pull large Docker images. It can prevent the
    --     performance issues caused by pulling large Docker images down from
    --     the network.
    --
    --     -   You can use a Docker layer cache in the Linux environment only.
    --
    --     -   The @privileged@ flag must be set so that your project has the
    --         required Docker permissions.
    --
    --     -   You should consider the security implications before you use a
    --         Docker layer cache.
    --
    -- [LOCAL_CUSTOM_CACHE]
    --     Caches directories you specify in the buildspec file. This mode is a
    --     good choice if your build scenario is not suited to one of the other
    --     three local cache modes. If you use a custom cache:
    --
    --     -   Only directories can be specified for caching. You cannot
    --         specify individual files.
    --
    --     -   Symlinks are used to reference cached directories.
    --
    --     -   Cached directories are linked to your build before it downloads
    --         its project sources. Cached items are overridden if a source
    --         item has the same name. Directories are specified using cache
    --         paths in the buildspec file.
    ProjectCache -> Maybe [CacheMode]
modes :: Prelude.Maybe [CacheMode],
    -- | The type of cache used by the build project. Valid values include:
    --
    -- -   @NO_CACHE@: The build project does not use any cache.
    --
    -- -   @S3@: The build project reads and writes from and to S3.
    --
    -- -   @LOCAL@: The build project stores a cache locally on a build host
    --     that is only available to that build host.
    ProjectCache -> CacheType
type' :: CacheType
  }
  deriving (ProjectCache -> ProjectCache -> Bool
(ProjectCache -> ProjectCache -> Bool)
-> (ProjectCache -> ProjectCache -> Bool) -> Eq ProjectCache
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProjectCache -> ProjectCache -> Bool
$c/= :: ProjectCache -> ProjectCache -> Bool
== :: ProjectCache -> ProjectCache -> Bool
$c== :: ProjectCache -> ProjectCache -> Bool
Prelude.Eq, ReadPrec [ProjectCache]
ReadPrec ProjectCache
Int -> ReadS ProjectCache
ReadS [ProjectCache]
(Int -> ReadS ProjectCache)
-> ReadS [ProjectCache]
-> ReadPrec ProjectCache
-> ReadPrec [ProjectCache]
-> Read ProjectCache
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ProjectCache]
$creadListPrec :: ReadPrec [ProjectCache]
readPrec :: ReadPrec ProjectCache
$creadPrec :: ReadPrec ProjectCache
readList :: ReadS [ProjectCache]
$creadList :: ReadS [ProjectCache]
readsPrec :: Int -> ReadS ProjectCache
$creadsPrec :: Int -> ReadS ProjectCache
Prelude.Read, Int -> ProjectCache -> ShowS
[ProjectCache] -> ShowS
ProjectCache -> String
(Int -> ProjectCache -> ShowS)
-> (ProjectCache -> String)
-> ([ProjectCache] -> ShowS)
-> Show ProjectCache
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProjectCache] -> ShowS
$cshowList :: [ProjectCache] -> ShowS
show :: ProjectCache -> String
$cshow :: ProjectCache -> String
showsPrec :: Int -> ProjectCache -> ShowS
$cshowsPrec :: Int -> ProjectCache -> ShowS
Prelude.Show, (forall x. ProjectCache -> Rep ProjectCache x)
-> (forall x. Rep ProjectCache x -> ProjectCache)
-> Generic ProjectCache
forall x. Rep ProjectCache x -> ProjectCache
forall x. ProjectCache -> Rep ProjectCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ProjectCache x -> ProjectCache
$cfrom :: forall x. ProjectCache -> Rep ProjectCache x
Prelude.Generic)

-- |
-- Create a value of 'ProjectCache' 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:
--
-- 'location', 'projectCache_location' - Information about the cache location:
--
-- -   @NO_CACHE@ or @LOCAL@: This value is ignored.
--
-- -   @S3@: This is the S3 bucket name\/prefix.
--
-- 'modes', 'projectCache_modes' - An array of strings that specify the local cache modes. You can use one
-- or more local cache modes at the same time. This is only used for
-- @LOCAL@ cache types.
--
-- Possible values are:
--
-- [LOCAL_SOURCE_CACHE]
--     Caches Git metadata for primary and secondary sources. After the
--     cache is created, subsequent builds pull only the change between
--     commits. This mode is a good choice for projects with a clean
--     working directory and a source that is a large Git repository. If
--     you choose this option and your project does not use a Git
--     repository (GitHub, GitHub Enterprise, or Bitbucket), the option is
--     ignored.
--
-- [LOCAL_DOCKER_LAYER_CACHE]
--     Caches existing Docker layers. This mode is a good choice for
--     projects that build or pull large Docker images. It can prevent the
--     performance issues caused by pulling large Docker images down from
--     the network.
--
--     -   You can use a Docker layer cache in the Linux environment only.
--
--     -   The @privileged@ flag must be set so that your project has the
--         required Docker permissions.
--
--     -   You should consider the security implications before you use a
--         Docker layer cache.
--
-- [LOCAL_CUSTOM_CACHE]
--     Caches directories you specify in the buildspec file. This mode is a
--     good choice if your build scenario is not suited to one of the other
--     three local cache modes. If you use a custom cache:
--
--     -   Only directories can be specified for caching. You cannot
--         specify individual files.
--
--     -   Symlinks are used to reference cached directories.
--
--     -   Cached directories are linked to your build before it downloads
--         its project sources. Cached items are overridden if a source
--         item has the same name. Directories are specified using cache
--         paths in the buildspec file.
--
-- 'type'', 'projectCache_type' - The type of cache used by the build project. Valid values include:
--
-- -   @NO_CACHE@: The build project does not use any cache.
--
-- -   @S3@: The build project reads and writes from and to S3.
--
-- -   @LOCAL@: The build project stores a cache locally on a build host
--     that is only available to that build host.
newProjectCache ::
  -- | 'type''
  CacheType ->
  ProjectCache
newProjectCache :: CacheType -> ProjectCache
newProjectCache CacheType
pType_ =
  ProjectCache' :: Maybe Text -> Maybe [CacheMode] -> CacheType -> ProjectCache
ProjectCache'
    { $sel:location:ProjectCache' :: Maybe Text
location = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:modes:ProjectCache' :: Maybe [CacheMode]
modes = Maybe [CacheMode]
forall a. Maybe a
Prelude.Nothing,
      $sel:type':ProjectCache' :: CacheType
type' = CacheType
pType_
    }

-- | Information about the cache location:
--
-- -   @NO_CACHE@ or @LOCAL@: This value is ignored.
--
-- -   @S3@: This is the S3 bucket name\/prefix.
projectCache_location :: Lens.Lens' ProjectCache (Prelude.Maybe Prelude.Text)
projectCache_location :: (Maybe Text -> f (Maybe Text)) -> ProjectCache -> f ProjectCache
projectCache_location = (ProjectCache -> Maybe Text)
-> (ProjectCache -> Maybe Text -> ProjectCache)
-> Lens ProjectCache ProjectCache (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectCache' {Maybe Text
location :: Maybe Text
$sel:location:ProjectCache' :: ProjectCache -> Maybe Text
location} -> Maybe Text
location) (\s :: ProjectCache
s@ProjectCache' {} Maybe Text
a -> ProjectCache
s {$sel:location:ProjectCache' :: Maybe Text
location = Maybe Text
a} :: ProjectCache)

-- | An array of strings that specify the local cache modes. You can use one
-- or more local cache modes at the same time. This is only used for
-- @LOCAL@ cache types.
--
-- Possible values are:
--
-- [LOCAL_SOURCE_CACHE]
--     Caches Git metadata for primary and secondary sources. After the
--     cache is created, subsequent builds pull only the change between
--     commits. This mode is a good choice for projects with a clean
--     working directory and a source that is a large Git repository. If
--     you choose this option and your project does not use a Git
--     repository (GitHub, GitHub Enterprise, or Bitbucket), the option is
--     ignored.
--
-- [LOCAL_DOCKER_LAYER_CACHE]
--     Caches existing Docker layers. This mode is a good choice for
--     projects that build or pull large Docker images. It can prevent the
--     performance issues caused by pulling large Docker images down from
--     the network.
--
--     -   You can use a Docker layer cache in the Linux environment only.
--
--     -   The @privileged@ flag must be set so that your project has the
--         required Docker permissions.
--
--     -   You should consider the security implications before you use a
--         Docker layer cache.
--
-- [LOCAL_CUSTOM_CACHE]
--     Caches directories you specify in the buildspec file. This mode is a
--     good choice if your build scenario is not suited to one of the other
--     three local cache modes. If you use a custom cache:
--
--     -   Only directories can be specified for caching. You cannot
--         specify individual files.
--
--     -   Symlinks are used to reference cached directories.
--
--     -   Cached directories are linked to your build before it downloads
--         its project sources. Cached items are overridden if a source
--         item has the same name. Directories are specified using cache
--         paths in the buildspec file.
projectCache_modes :: Lens.Lens' ProjectCache (Prelude.Maybe [CacheMode])
projectCache_modes :: (Maybe [CacheMode] -> f (Maybe [CacheMode]))
-> ProjectCache -> f ProjectCache
projectCache_modes = (ProjectCache -> Maybe [CacheMode])
-> (ProjectCache -> Maybe [CacheMode] -> ProjectCache)
-> Lens
     ProjectCache ProjectCache (Maybe [CacheMode]) (Maybe [CacheMode])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectCache' {Maybe [CacheMode]
modes :: Maybe [CacheMode]
$sel:modes:ProjectCache' :: ProjectCache -> Maybe [CacheMode]
modes} -> Maybe [CacheMode]
modes) (\s :: ProjectCache
s@ProjectCache' {} Maybe [CacheMode]
a -> ProjectCache
s {$sel:modes:ProjectCache' :: Maybe [CacheMode]
modes = Maybe [CacheMode]
a} :: ProjectCache) ((Maybe [CacheMode] -> f (Maybe [CacheMode]))
 -> ProjectCache -> f ProjectCache)
-> ((Maybe [CacheMode] -> f (Maybe [CacheMode]))
    -> Maybe [CacheMode] -> f (Maybe [CacheMode]))
-> (Maybe [CacheMode] -> f (Maybe [CacheMode]))
-> ProjectCache
-> f ProjectCache
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [CacheMode] [CacheMode] [CacheMode] [CacheMode]
-> Iso
     (Maybe [CacheMode])
     (Maybe [CacheMode])
     (Maybe [CacheMode])
     (Maybe [CacheMode])
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 [CacheMode] [CacheMode] [CacheMode] [CacheMode]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The type of cache used by the build project. Valid values include:
--
-- -   @NO_CACHE@: The build project does not use any cache.
--
-- -   @S3@: The build project reads and writes from and to S3.
--
-- -   @LOCAL@: The build project stores a cache locally on a build host
--     that is only available to that build host.
projectCache_type :: Lens.Lens' ProjectCache CacheType
projectCache_type :: (CacheType -> f CacheType) -> ProjectCache -> f ProjectCache
projectCache_type = (ProjectCache -> CacheType)
-> (ProjectCache -> CacheType -> ProjectCache)
-> Lens ProjectCache ProjectCache CacheType CacheType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ProjectCache' {CacheType
type' :: CacheType
$sel:type':ProjectCache' :: ProjectCache -> CacheType
type'} -> CacheType
type') (\s :: ProjectCache
s@ProjectCache' {} CacheType
a -> ProjectCache
s {$sel:type':ProjectCache' :: CacheType
type' = CacheType
a} :: ProjectCache)

instance Core.FromJSON ProjectCache where
  parseJSON :: Value -> Parser ProjectCache
parseJSON =
    String
-> (Object -> Parser ProjectCache) -> Value -> Parser ProjectCache
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ProjectCache"
      ( \Object
x ->
          Maybe Text -> Maybe [CacheMode] -> CacheType -> ProjectCache
ProjectCache'
            (Maybe Text -> Maybe [CacheMode] -> CacheType -> ProjectCache)
-> Parser (Maybe Text)
-> Parser (Maybe [CacheMode] -> CacheType -> ProjectCache)
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
"location")
            Parser (Maybe [CacheMode] -> CacheType -> ProjectCache)
-> Parser (Maybe [CacheMode]) -> Parser (CacheType -> ProjectCache)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [CacheMode]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"modes" Parser (Maybe (Maybe [CacheMode]))
-> Maybe [CacheMode] -> Parser (Maybe [CacheMode])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [CacheMode]
forall a. Monoid a => a
Prelude.mempty)
            Parser (CacheType -> ProjectCache)
-> Parser CacheType -> Parser ProjectCache
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser CacheType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable ProjectCache

instance Prelude.NFData ProjectCache

instance Core.ToJSON ProjectCache where
  toJSON :: ProjectCache -> Value
toJSON ProjectCache' {Maybe [CacheMode]
Maybe Text
CacheType
type' :: CacheType
modes :: Maybe [CacheMode]
location :: Maybe Text
$sel:type':ProjectCache' :: ProjectCache -> CacheType
$sel:modes:ProjectCache' :: ProjectCache -> Maybe [CacheMode]
$sel:location:ProjectCache' :: ProjectCache -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"location" 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
location,
            (Text
"modes" Text -> [CacheMode] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([CacheMode] -> Pair) -> Maybe [CacheMode] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CacheMode]
modes,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> CacheType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= CacheType
type')
          ]
      )