{-# 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.ECS.Types.VolumeFrom
-- 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.ECS.Types.VolumeFrom where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Details on a data volume from another container in the same task
-- definition.
--
-- /See:/ 'newVolumeFrom' smart constructor.
data VolumeFrom = VolumeFrom'
  { -- | The name of another container within the same task definition from which
    -- to mount volumes.
    VolumeFrom -> Maybe Text
sourceContainer :: Prelude.Maybe Prelude.Text,
    -- | If this value is @true@, the container has read-only access to the
    -- volume. If this value is @false@, then the container can write to the
    -- volume. The default value is @false@.
    VolumeFrom -> Maybe Bool
readOnly :: Prelude.Maybe Prelude.Bool
  }
  deriving (VolumeFrom -> VolumeFrom -> Bool
(VolumeFrom -> VolumeFrom -> Bool)
-> (VolumeFrom -> VolumeFrom -> Bool) -> Eq VolumeFrom
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VolumeFrom -> VolumeFrom -> Bool
$c/= :: VolumeFrom -> VolumeFrom -> Bool
== :: VolumeFrom -> VolumeFrom -> Bool
$c== :: VolumeFrom -> VolumeFrom -> Bool
Prelude.Eq, ReadPrec [VolumeFrom]
ReadPrec VolumeFrom
Int -> ReadS VolumeFrom
ReadS [VolumeFrom]
(Int -> ReadS VolumeFrom)
-> ReadS [VolumeFrom]
-> ReadPrec VolumeFrom
-> ReadPrec [VolumeFrom]
-> Read VolumeFrom
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VolumeFrom]
$creadListPrec :: ReadPrec [VolumeFrom]
readPrec :: ReadPrec VolumeFrom
$creadPrec :: ReadPrec VolumeFrom
readList :: ReadS [VolumeFrom]
$creadList :: ReadS [VolumeFrom]
readsPrec :: Int -> ReadS VolumeFrom
$creadsPrec :: Int -> ReadS VolumeFrom
Prelude.Read, Int -> VolumeFrom -> ShowS
[VolumeFrom] -> ShowS
VolumeFrom -> String
(Int -> VolumeFrom -> ShowS)
-> (VolumeFrom -> String)
-> ([VolumeFrom] -> ShowS)
-> Show VolumeFrom
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VolumeFrom] -> ShowS
$cshowList :: [VolumeFrom] -> ShowS
show :: VolumeFrom -> String
$cshow :: VolumeFrom -> String
showsPrec :: Int -> VolumeFrom -> ShowS
$cshowsPrec :: Int -> VolumeFrom -> ShowS
Prelude.Show, (forall x. VolumeFrom -> Rep VolumeFrom x)
-> (forall x. Rep VolumeFrom x -> VolumeFrom) -> Generic VolumeFrom
forall x. Rep VolumeFrom x -> VolumeFrom
forall x. VolumeFrom -> Rep VolumeFrom x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep VolumeFrom x -> VolumeFrom
$cfrom :: forall x. VolumeFrom -> Rep VolumeFrom x
Prelude.Generic)

-- |
-- Create a value of 'VolumeFrom' 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:
--
-- 'sourceContainer', 'volumeFrom_sourceContainer' - The name of another container within the same task definition from which
-- to mount volumes.
--
-- 'readOnly', 'volumeFrom_readOnly' - If this value is @true@, the container has read-only access to the
-- volume. If this value is @false@, then the container can write to the
-- volume. The default value is @false@.
newVolumeFrom ::
  VolumeFrom
newVolumeFrom :: VolumeFrom
newVolumeFrom =
  VolumeFrom' :: Maybe Text -> Maybe Bool -> VolumeFrom
VolumeFrom'
    { $sel:sourceContainer:VolumeFrom' :: Maybe Text
sourceContainer = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:readOnly:VolumeFrom' :: Maybe Bool
readOnly = Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | The name of another container within the same task definition from which
-- to mount volumes.
volumeFrom_sourceContainer :: Lens.Lens' VolumeFrom (Prelude.Maybe Prelude.Text)
volumeFrom_sourceContainer :: (Maybe Text -> f (Maybe Text)) -> VolumeFrom -> f VolumeFrom
volumeFrom_sourceContainer = (VolumeFrom -> Maybe Text)
-> (VolumeFrom -> Maybe Text -> VolumeFrom)
-> Lens VolumeFrom VolumeFrom (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VolumeFrom' {Maybe Text
sourceContainer :: Maybe Text
$sel:sourceContainer:VolumeFrom' :: VolumeFrom -> Maybe Text
sourceContainer} -> Maybe Text
sourceContainer) (\s :: VolumeFrom
s@VolumeFrom' {} Maybe Text
a -> VolumeFrom
s {$sel:sourceContainer:VolumeFrom' :: Maybe Text
sourceContainer = Maybe Text
a} :: VolumeFrom)

-- | If this value is @true@, the container has read-only access to the
-- volume. If this value is @false@, then the container can write to the
-- volume. The default value is @false@.
volumeFrom_readOnly :: Lens.Lens' VolumeFrom (Prelude.Maybe Prelude.Bool)
volumeFrom_readOnly :: (Maybe Bool -> f (Maybe Bool)) -> VolumeFrom -> f VolumeFrom
volumeFrom_readOnly = (VolumeFrom -> Maybe Bool)
-> (VolumeFrom -> Maybe Bool -> VolumeFrom)
-> Lens VolumeFrom VolumeFrom (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\VolumeFrom' {Maybe Bool
readOnly :: Maybe Bool
$sel:readOnly:VolumeFrom' :: VolumeFrom -> Maybe Bool
readOnly} -> Maybe Bool
readOnly) (\s :: VolumeFrom
s@VolumeFrom' {} Maybe Bool
a -> VolumeFrom
s {$sel:readOnly:VolumeFrom' :: Maybe Bool
readOnly = Maybe Bool
a} :: VolumeFrom)

instance Core.FromJSON VolumeFrom where
  parseJSON :: Value -> Parser VolumeFrom
parseJSON =
    String
-> (Object -> Parser VolumeFrom) -> Value -> Parser VolumeFrom
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"VolumeFrom"
      ( \Object
x ->
          Maybe Text -> Maybe Bool -> VolumeFrom
VolumeFrom'
            (Maybe Text -> Maybe Bool -> VolumeFrom)
-> Parser (Maybe Text) -> Parser (Maybe Bool -> VolumeFrom)
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
"sourceContainer")
            Parser (Maybe Bool -> VolumeFrom)
-> Parser (Maybe Bool) -> Parser VolumeFrom
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
"readOnly")
      )

instance Prelude.Hashable VolumeFrom

instance Prelude.NFData VolumeFrom

instance Core.ToJSON VolumeFrom where
  toJSON :: VolumeFrom -> Value
toJSON VolumeFrom' {Maybe Bool
Maybe Text
readOnly :: Maybe Bool
sourceContainer :: Maybe Text
$sel:readOnly:VolumeFrom' :: VolumeFrom -> Maybe Bool
$sel:sourceContainer:VolumeFrom' :: VolumeFrom -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"sourceContainer" 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
sourceContainer,
            (Text
"readOnly" 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
readOnly
          ]
      )