{-# 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.ImageBuilder.Types.InstanceMetadataOptions
-- 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.ImageBuilder.Types.InstanceMetadataOptions where

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

-- | The instance metadata options that apply to the HTTP requests that
-- pipeline builds use to launch EC2 build and test instances. For more
-- information about instance metadata options, see
-- <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html Configure the instance metadata options>
-- in the //Amazon EC2 User Guide// for Linux instances, or
-- <https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/configuring-instance-metadata-options.html Configure the instance metadata options>
-- in the //Amazon EC2 Windows Guide// for Windows instances.
--
-- /See:/ 'newInstanceMetadataOptions' smart constructor.
data InstanceMetadataOptions = InstanceMetadataOptions'
  { -- | Limit the number of hops that an instance metadata request can traverse
    -- to reach its destination.
    InstanceMetadataOptions -> Maybe Natural
httpPutResponseHopLimit :: Prelude.Maybe Prelude.Natural,
    -- | Indicates whether a signed token header is required for instance
    -- metadata retrieval requests. The values affect the response as follows:
    --
    -- -   __required__ – When you retrieve the IAM role credentials, version
    --     2.0 credentials are returned in all cases.
    --
    -- -   __optional__ – You can include a signed token header in your request
    --     to retrieve instance metadata, or you can leave it out. If you
    --     include it, version 2.0 credentials are returned for the IAM role.
    --     Otherwise, version 1.0 credentials are returned.
    --
    -- The default setting is __optional__.
    InstanceMetadataOptions -> Maybe Text
httpTokens :: Prelude.Maybe Prelude.Text
  }
  deriving (InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
(InstanceMetadataOptions -> InstanceMetadataOptions -> Bool)
-> (InstanceMetadataOptions -> InstanceMetadataOptions -> Bool)
-> Eq InstanceMetadataOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
$c/= :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
== :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
$c== :: InstanceMetadataOptions -> InstanceMetadataOptions -> Bool
Prelude.Eq, ReadPrec [InstanceMetadataOptions]
ReadPrec InstanceMetadataOptions
Int -> ReadS InstanceMetadataOptions
ReadS [InstanceMetadataOptions]
(Int -> ReadS InstanceMetadataOptions)
-> ReadS [InstanceMetadataOptions]
-> ReadPrec InstanceMetadataOptions
-> ReadPrec [InstanceMetadataOptions]
-> Read InstanceMetadataOptions
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [InstanceMetadataOptions]
$creadListPrec :: ReadPrec [InstanceMetadataOptions]
readPrec :: ReadPrec InstanceMetadataOptions
$creadPrec :: ReadPrec InstanceMetadataOptions
readList :: ReadS [InstanceMetadataOptions]
$creadList :: ReadS [InstanceMetadataOptions]
readsPrec :: Int -> ReadS InstanceMetadataOptions
$creadsPrec :: Int -> ReadS InstanceMetadataOptions
Prelude.Read, Int -> InstanceMetadataOptions -> ShowS
[InstanceMetadataOptions] -> ShowS
InstanceMetadataOptions -> String
(Int -> InstanceMetadataOptions -> ShowS)
-> (InstanceMetadataOptions -> String)
-> ([InstanceMetadataOptions] -> ShowS)
-> Show InstanceMetadataOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InstanceMetadataOptions] -> ShowS
$cshowList :: [InstanceMetadataOptions] -> ShowS
show :: InstanceMetadataOptions -> String
$cshow :: InstanceMetadataOptions -> String
showsPrec :: Int -> InstanceMetadataOptions -> ShowS
$cshowsPrec :: Int -> InstanceMetadataOptions -> ShowS
Prelude.Show, (forall x.
 InstanceMetadataOptions -> Rep InstanceMetadataOptions x)
-> (forall x.
    Rep InstanceMetadataOptions x -> InstanceMetadataOptions)
-> Generic InstanceMetadataOptions
forall x. Rep InstanceMetadataOptions x -> InstanceMetadataOptions
forall x. InstanceMetadataOptions -> Rep InstanceMetadataOptions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep InstanceMetadataOptions x -> InstanceMetadataOptions
$cfrom :: forall x. InstanceMetadataOptions -> Rep InstanceMetadataOptions x
Prelude.Generic)

-- |
-- Create a value of 'InstanceMetadataOptions' 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:
--
-- 'httpPutResponseHopLimit', 'instanceMetadataOptions_httpPutResponseHopLimit' - Limit the number of hops that an instance metadata request can traverse
-- to reach its destination.
--
-- 'httpTokens', 'instanceMetadataOptions_httpTokens' - Indicates whether a signed token header is required for instance
-- metadata retrieval requests. The values affect the response as follows:
--
-- -   __required__ – When you retrieve the IAM role credentials, version
--     2.0 credentials are returned in all cases.
--
-- -   __optional__ – You can include a signed token header in your request
--     to retrieve instance metadata, or you can leave it out. If you
--     include it, version 2.0 credentials are returned for the IAM role.
--     Otherwise, version 1.0 credentials are returned.
--
-- The default setting is __optional__.
newInstanceMetadataOptions ::
  InstanceMetadataOptions
newInstanceMetadataOptions :: InstanceMetadataOptions
newInstanceMetadataOptions =
  InstanceMetadataOptions' :: Maybe Natural -> Maybe Text -> InstanceMetadataOptions
InstanceMetadataOptions'
    { $sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: Maybe Natural
httpPutResponseHopLimit =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:httpTokens:InstanceMetadataOptions' :: Maybe Text
httpTokens = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | Limit the number of hops that an instance metadata request can traverse
-- to reach its destination.
instanceMetadataOptions_httpPutResponseHopLimit :: Lens.Lens' InstanceMetadataOptions (Prelude.Maybe Prelude.Natural)
instanceMetadataOptions_httpPutResponseHopLimit :: (Maybe Natural -> f (Maybe Natural))
-> InstanceMetadataOptions -> f InstanceMetadataOptions
instanceMetadataOptions_httpPutResponseHopLimit = (InstanceMetadataOptions -> Maybe Natural)
-> (InstanceMetadataOptions
    -> Maybe Natural -> InstanceMetadataOptions)
-> Lens
     InstanceMetadataOptions
     InstanceMetadataOptions
     (Maybe Natural)
     (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceMetadataOptions' {Maybe Natural
httpPutResponseHopLimit :: Maybe Natural
$sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe Natural
httpPutResponseHopLimit} -> Maybe Natural
httpPutResponseHopLimit) (\s :: InstanceMetadataOptions
s@InstanceMetadataOptions' {} Maybe Natural
a -> InstanceMetadataOptions
s {$sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: Maybe Natural
httpPutResponseHopLimit = Maybe Natural
a} :: InstanceMetadataOptions)

-- | Indicates whether a signed token header is required for instance
-- metadata retrieval requests. The values affect the response as follows:
--
-- -   __required__ – When you retrieve the IAM role credentials, version
--     2.0 credentials are returned in all cases.
--
-- -   __optional__ – You can include a signed token header in your request
--     to retrieve instance metadata, or you can leave it out. If you
--     include it, version 2.0 credentials are returned for the IAM role.
--     Otherwise, version 1.0 credentials are returned.
--
-- The default setting is __optional__.
instanceMetadataOptions_httpTokens :: Lens.Lens' InstanceMetadataOptions (Prelude.Maybe Prelude.Text)
instanceMetadataOptions_httpTokens :: (Maybe Text -> f (Maybe Text))
-> InstanceMetadataOptions -> f InstanceMetadataOptions
instanceMetadataOptions_httpTokens = (InstanceMetadataOptions -> Maybe Text)
-> (InstanceMetadataOptions
    -> Maybe Text -> InstanceMetadataOptions)
-> Lens
     InstanceMetadataOptions
     InstanceMetadataOptions
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\InstanceMetadataOptions' {Maybe Text
httpTokens :: Maybe Text
$sel:httpTokens:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe Text
httpTokens} -> Maybe Text
httpTokens) (\s :: InstanceMetadataOptions
s@InstanceMetadataOptions' {} Maybe Text
a -> InstanceMetadataOptions
s {$sel:httpTokens:InstanceMetadataOptions' :: Maybe Text
httpTokens = Maybe Text
a} :: InstanceMetadataOptions)

instance Core.FromJSON InstanceMetadataOptions where
  parseJSON :: Value -> Parser InstanceMetadataOptions
parseJSON =
    String
-> (Object -> Parser InstanceMetadataOptions)
-> Value
-> Parser InstanceMetadataOptions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"InstanceMetadataOptions"
      ( \Object
x ->
          Maybe Natural -> Maybe Text -> InstanceMetadataOptions
InstanceMetadataOptions'
            (Maybe Natural -> Maybe Text -> InstanceMetadataOptions)
-> Parser (Maybe Natural)
-> Parser (Maybe Text -> InstanceMetadataOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"httpPutResponseHopLimit")
            Parser (Maybe Text -> InstanceMetadataOptions)
-> Parser (Maybe Text) -> Parser InstanceMetadataOptions
forall (f :: * -> *) a b. Applicative f => 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
"httpTokens")
      )

instance Prelude.Hashable InstanceMetadataOptions

instance Prelude.NFData InstanceMetadataOptions

instance Core.ToJSON InstanceMetadataOptions where
  toJSON :: InstanceMetadataOptions -> Value
toJSON InstanceMetadataOptions' {Maybe Natural
Maybe Text
httpTokens :: Maybe Text
httpPutResponseHopLimit :: Maybe Natural
$sel:httpTokens:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe Text
$sel:httpPutResponseHopLimit:InstanceMetadataOptions' :: InstanceMetadataOptions -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"httpPutResponseHopLimit" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
httpPutResponseHopLimit,
            (Text
"httpTokens" 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
httpTokens
          ]
      )