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

import qualified Amazonka.Core as Core
import Amazonka.ECS.Types.FirelensConfigurationType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The FireLens configuration for the container. This is used to specify
-- and configure a log router for container logs. For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html Custom Log Routing>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- /See:/ 'newFirelensConfiguration' smart constructor.
data FirelensConfiguration = FirelensConfiguration'
  { -- | The options to use when configuring the log router. This field is
    -- optional and can be used to specify a custom configuration file or to
    -- add additional metadata, such as the task, task definition, cluster, and
    -- container instance details to the log event. If specified, the syntax to
    -- use is
    -- @\"options\":{\"enable-ecs-log-metadata\":\"true|false\",\"config-file-type:\"s3|file\",\"config-file-value\":\"arn:aws:s3:::mybucket\/fluent.conf|filepath\"}@.
    -- For more information, see
    -- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef Creating a Task Definition that Uses a FireLens Configuration>
    -- in the /Amazon Elastic Container Service Developer Guide/.
    --
    -- Tasks hosted on Fargate only support the @file@ configuration file type.
    FirelensConfiguration -> Maybe (HashMap Text Text)
options :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The log router to use. The valid values are @fluentd@ or @fluentbit@.
    FirelensConfiguration -> FirelensConfigurationType
type' :: FirelensConfigurationType
  }
  deriving (FirelensConfiguration -> FirelensConfiguration -> Bool
(FirelensConfiguration -> FirelensConfiguration -> Bool)
-> (FirelensConfiguration -> FirelensConfiguration -> Bool)
-> Eq FirelensConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FirelensConfiguration -> FirelensConfiguration -> Bool
$c/= :: FirelensConfiguration -> FirelensConfiguration -> Bool
== :: FirelensConfiguration -> FirelensConfiguration -> Bool
$c== :: FirelensConfiguration -> FirelensConfiguration -> Bool
Prelude.Eq, ReadPrec [FirelensConfiguration]
ReadPrec FirelensConfiguration
Int -> ReadS FirelensConfiguration
ReadS [FirelensConfiguration]
(Int -> ReadS FirelensConfiguration)
-> ReadS [FirelensConfiguration]
-> ReadPrec FirelensConfiguration
-> ReadPrec [FirelensConfiguration]
-> Read FirelensConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FirelensConfiguration]
$creadListPrec :: ReadPrec [FirelensConfiguration]
readPrec :: ReadPrec FirelensConfiguration
$creadPrec :: ReadPrec FirelensConfiguration
readList :: ReadS [FirelensConfiguration]
$creadList :: ReadS [FirelensConfiguration]
readsPrec :: Int -> ReadS FirelensConfiguration
$creadsPrec :: Int -> ReadS FirelensConfiguration
Prelude.Read, Int -> FirelensConfiguration -> ShowS
[FirelensConfiguration] -> ShowS
FirelensConfiguration -> String
(Int -> FirelensConfiguration -> ShowS)
-> (FirelensConfiguration -> String)
-> ([FirelensConfiguration] -> ShowS)
-> Show FirelensConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FirelensConfiguration] -> ShowS
$cshowList :: [FirelensConfiguration] -> ShowS
show :: FirelensConfiguration -> String
$cshow :: FirelensConfiguration -> String
showsPrec :: Int -> FirelensConfiguration -> ShowS
$cshowsPrec :: Int -> FirelensConfiguration -> ShowS
Prelude.Show, (forall x. FirelensConfiguration -> Rep FirelensConfiguration x)
-> (forall x. Rep FirelensConfiguration x -> FirelensConfiguration)
-> Generic FirelensConfiguration
forall x. Rep FirelensConfiguration x -> FirelensConfiguration
forall x. FirelensConfiguration -> Rep FirelensConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FirelensConfiguration x -> FirelensConfiguration
$cfrom :: forall x. FirelensConfiguration -> Rep FirelensConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'FirelensConfiguration' 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:
--
-- 'options', 'firelensConfiguration_options' - The options to use when configuring the log router. This field is
-- optional and can be used to specify a custom configuration file or to
-- add additional metadata, such as the task, task definition, cluster, and
-- container instance details to the log event. If specified, the syntax to
-- use is
-- @\"options\":{\"enable-ecs-log-metadata\":\"true|false\",\"config-file-type:\"s3|file\",\"config-file-value\":\"arn:aws:s3:::mybucket\/fluent.conf|filepath\"}@.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef Creating a Task Definition that Uses a FireLens Configuration>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- Tasks hosted on Fargate only support the @file@ configuration file type.
--
-- 'type'', 'firelensConfiguration_type' - The log router to use. The valid values are @fluentd@ or @fluentbit@.
newFirelensConfiguration ::
  -- | 'type''
  FirelensConfigurationType ->
  FirelensConfiguration
newFirelensConfiguration :: FirelensConfigurationType -> FirelensConfiguration
newFirelensConfiguration FirelensConfigurationType
pType_ =
  FirelensConfiguration' :: Maybe (HashMap Text Text)
-> FirelensConfigurationType -> FirelensConfiguration
FirelensConfiguration'
    { $sel:options:FirelensConfiguration' :: Maybe (HashMap Text Text)
options = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:type':FirelensConfiguration' :: FirelensConfigurationType
type' = FirelensConfigurationType
pType_
    }

-- | The options to use when configuring the log router. This field is
-- optional and can be used to specify a custom configuration file or to
-- add additional metadata, such as the task, task definition, cluster, and
-- container instance details to the log event. If specified, the syntax to
-- use is
-- @\"options\":{\"enable-ecs-log-metadata\":\"true|false\",\"config-file-type:\"s3|file\",\"config-file-value\":\"arn:aws:s3:::mybucket\/fluent.conf|filepath\"}@.
-- For more information, see
-- <https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-taskdef Creating a Task Definition that Uses a FireLens Configuration>
-- in the /Amazon Elastic Container Service Developer Guide/.
--
-- Tasks hosted on Fargate only support the @file@ configuration file type.
firelensConfiguration_options :: Lens.Lens' FirelensConfiguration (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
firelensConfiguration_options :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> FirelensConfiguration -> f FirelensConfiguration
firelensConfiguration_options = (FirelensConfiguration -> Maybe (HashMap Text Text))
-> (FirelensConfiguration
    -> Maybe (HashMap Text Text) -> FirelensConfiguration)
-> Lens
     FirelensConfiguration
     FirelensConfiguration
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirelensConfiguration' {Maybe (HashMap Text Text)
options :: Maybe (HashMap Text Text)
$sel:options:FirelensConfiguration' :: FirelensConfiguration -> Maybe (HashMap Text Text)
options} -> Maybe (HashMap Text Text)
options) (\s :: FirelensConfiguration
s@FirelensConfiguration' {} Maybe (HashMap Text Text)
a -> FirelensConfiguration
s {$sel:options:FirelensConfiguration' :: Maybe (HashMap Text Text)
options = Maybe (HashMap Text Text)
a} :: FirelensConfiguration) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> FirelensConfiguration -> f FirelensConfiguration)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> FirelensConfiguration
-> f FirelensConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The log router to use. The valid values are @fluentd@ or @fluentbit@.
firelensConfiguration_type :: Lens.Lens' FirelensConfiguration FirelensConfigurationType
firelensConfiguration_type :: (FirelensConfigurationType -> f FirelensConfigurationType)
-> FirelensConfiguration -> f FirelensConfiguration
firelensConfiguration_type = (FirelensConfiguration -> FirelensConfigurationType)
-> (FirelensConfiguration
    -> FirelensConfigurationType -> FirelensConfiguration)
-> Lens
     FirelensConfiguration
     FirelensConfiguration
     FirelensConfigurationType
     FirelensConfigurationType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\FirelensConfiguration' {FirelensConfigurationType
type' :: FirelensConfigurationType
$sel:type':FirelensConfiguration' :: FirelensConfiguration -> FirelensConfigurationType
type'} -> FirelensConfigurationType
type') (\s :: FirelensConfiguration
s@FirelensConfiguration' {} FirelensConfigurationType
a -> FirelensConfiguration
s {$sel:type':FirelensConfiguration' :: FirelensConfigurationType
type' = FirelensConfigurationType
a} :: FirelensConfiguration)

instance Core.FromJSON FirelensConfiguration where
  parseJSON :: Value -> Parser FirelensConfiguration
parseJSON =
    String
-> (Object -> Parser FirelensConfiguration)
-> Value
-> Parser FirelensConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"FirelensConfiguration"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> FirelensConfigurationType -> FirelensConfiguration
FirelensConfiguration'
            (Maybe (HashMap Text Text)
 -> FirelensConfigurationType -> FirelensConfiguration)
-> Parser (Maybe (HashMap Text Text))
-> Parser (FirelensConfigurationType -> FirelensConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"options" Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty)
            Parser (FirelensConfigurationType -> FirelensConfiguration)
-> Parser FirelensConfigurationType -> Parser FirelensConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser FirelensConfigurationType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"type")
      )

instance Prelude.Hashable FirelensConfiguration

instance Prelude.NFData FirelensConfiguration

instance Core.ToJSON FirelensConfiguration where
  toJSON :: FirelensConfiguration -> Value
toJSON FirelensConfiguration' {Maybe (HashMap Text Text)
FirelensConfigurationType
type' :: FirelensConfigurationType
options :: Maybe (HashMap Text Text)
$sel:type':FirelensConfiguration' :: FirelensConfiguration -> FirelensConfigurationType
$sel:options:FirelensConfiguration' :: FirelensConfiguration -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"options" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
options,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"type" Text -> FirelensConfigurationType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= FirelensConfigurationType
type')
          ]
      )