{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ECS.Types.VolumeFrom where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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'
  { -- | 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,
    -- | The name of another container within the same task definition to mount
    -- volumes from.
    VolumeFrom -> Maybe Text
sourceContainer :: Prelude.Maybe Prelude.Text
  }
  deriving (VolumeFrom -> VolumeFrom -> Bool
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]
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
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. 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:
--
-- '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@.
--
-- 'sourceContainer', 'volumeFrom_sourceContainer' - The name of another container within the same task definition to mount
-- volumes from.
newVolumeFrom ::
  VolumeFrom
newVolumeFrom :: VolumeFrom
newVolumeFrom =
  VolumeFrom'
    { $sel:readOnly:VolumeFrom' :: Maybe Bool
readOnly = forall a. Maybe a
Prelude.Nothing,
      $sel:sourceContainer:VolumeFrom' :: Maybe Text
sourceContainer = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' VolumeFrom (Maybe Bool)
volumeFrom_readOnly = 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)

-- | The name of another container within the same task definition to mount
-- volumes from.
volumeFrom_sourceContainer :: Lens.Lens' VolumeFrom (Prelude.Maybe Prelude.Text)
volumeFrom_sourceContainer :: Lens' VolumeFrom (Maybe Text)
volumeFrom_sourceContainer = 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)

instance Data.FromJSON VolumeFrom where
  parseJSON :: Value -> Parser VolumeFrom
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"VolumeFrom"
      ( \Object
x ->
          Maybe Bool -> Maybe Text -> VolumeFrom
VolumeFrom'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"readOnly")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"sourceContainer")
      )

instance Prelude.Hashable VolumeFrom where
  hashWithSalt :: Int -> VolumeFrom -> Int
hashWithSalt Int
_salt VolumeFrom' {Maybe Bool
Maybe Text
sourceContainer :: Maybe Text
readOnly :: Maybe Bool
$sel:sourceContainer:VolumeFrom' :: VolumeFrom -> Maybe Text
$sel:readOnly:VolumeFrom' :: VolumeFrom -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
readOnly
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sourceContainer

instance Prelude.NFData VolumeFrom where
  rnf :: VolumeFrom -> ()
rnf VolumeFrom' {Maybe Bool
Maybe Text
sourceContainer :: Maybe Text
readOnly :: Maybe Bool
$sel:sourceContainer:VolumeFrom' :: VolumeFrom -> Maybe Text
$sel:readOnly:VolumeFrom' :: VolumeFrom -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
readOnly
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sourceContainer

instance Data.ToJSON VolumeFrom where
  toJSON :: VolumeFrom -> Value
toJSON VolumeFrom' {Maybe Bool
Maybe Text
sourceContainer :: Maybe Text
readOnly :: Maybe Bool
$sel:sourceContainer:VolumeFrom' :: VolumeFrom -> Maybe Text
$sel:readOnly:VolumeFrom' :: VolumeFrom -> Maybe Bool
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"readOnly" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
readOnly,
            (Key
"sourceContainer" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
sourceContainer
          ]
      )