{-# 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.APIGateway.Types.ApiKey
-- 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.APIGateway.Types.ApiKey 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

-- | A resource that can be distributed to callers for executing Method
-- resources that require an API key. API keys can be mapped to any Stage
-- on any RestApi, which indicates that the callers with the API key can
-- make requests to that stage.
--
-- /See:/ 'newApiKey' smart constructor.
data ApiKey = ApiKey'
  { -- | The timestamp when the API Key was created.
    ApiKey -> Maybe POSIX
createdDate :: Prelude.Maybe Data.POSIX,
    -- | An AWS Marketplace customer identifier , when integrating with the AWS
    -- SaaS Marketplace.
    ApiKey -> Maybe Text
customerId :: Prelude.Maybe Prelude.Text,
    -- | The description of the API Key.
    ApiKey -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | Specifies whether the API Key can be used by callers.
    ApiKey -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The identifier of the API Key.
    ApiKey -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The timestamp when the API Key was last updated.
    ApiKey -> Maybe POSIX
lastUpdatedDate :: Prelude.Maybe Data.POSIX,
    -- | The name of the API Key.
    ApiKey -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A list of Stage resources that are associated with the ApiKey resource.
    ApiKey -> Maybe [Text]
stageKeys :: Prelude.Maybe [Prelude.Text],
    -- | The collection of tags. Each tag element is associated with a given
    -- resource.
    ApiKey -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The value of the API Key.
    ApiKey -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (ApiKey -> ApiKey -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApiKey -> ApiKey -> Bool
$c/= :: ApiKey -> ApiKey -> Bool
== :: ApiKey -> ApiKey -> Bool
$c== :: ApiKey -> ApiKey -> Bool
Prelude.Eq, ReadPrec [ApiKey]
ReadPrec ApiKey
Int -> ReadS ApiKey
ReadS [ApiKey]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApiKey]
$creadListPrec :: ReadPrec [ApiKey]
readPrec :: ReadPrec ApiKey
$creadPrec :: ReadPrec ApiKey
readList :: ReadS [ApiKey]
$creadList :: ReadS [ApiKey]
readsPrec :: Int -> ReadS ApiKey
$creadsPrec :: Int -> ReadS ApiKey
Prelude.Read, Int -> ApiKey -> ShowS
[ApiKey] -> ShowS
ApiKey -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApiKey] -> ShowS
$cshowList :: [ApiKey] -> ShowS
show :: ApiKey -> String
$cshow :: ApiKey -> String
showsPrec :: Int -> ApiKey -> ShowS
$cshowsPrec :: Int -> ApiKey -> ShowS
Prelude.Show, forall x. Rep ApiKey x -> ApiKey
forall x. ApiKey -> Rep ApiKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApiKey x -> ApiKey
$cfrom :: forall x. ApiKey -> Rep ApiKey x
Prelude.Generic)

-- |
-- Create a value of 'ApiKey' 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:
--
-- 'createdDate', 'apiKey_createdDate' - The timestamp when the API Key was created.
--
-- 'customerId', 'apiKey_customerId' - An AWS Marketplace customer identifier , when integrating with the AWS
-- SaaS Marketplace.
--
-- 'description', 'apiKey_description' - The description of the API Key.
--
-- 'enabled', 'apiKey_enabled' - Specifies whether the API Key can be used by callers.
--
-- 'id', 'apiKey_id' - The identifier of the API Key.
--
-- 'lastUpdatedDate', 'apiKey_lastUpdatedDate' - The timestamp when the API Key was last updated.
--
-- 'name', 'apiKey_name' - The name of the API Key.
--
-- 'stageKeys', 'apiKey_stageKeys' - A list of Stage resources that are associated with the ApiKey resource.
--
-- 'tags', 'apiKey_tags' - The collection of tags. Each tag element is associated with a given
-- resource.
--
-- 'value', 'apiKey_value' - The value of the API Key.
newApiKey ::
  ApiKey
newApiKey :: ApiKey
newApiKey =
  ApiKey'
    { $sel:createdDate:ApiKey' :: Maybe POSIX
createdDate = forall a. Maybe a
Prelude.Nothing,
      $sel:customerId:ApiKey' :: Maybe Text
customerId = forall a. Maybe a
Prelude.Nothing,
      $sel:description:ApiKey' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:ApiKey' :: Maybe Bool
enabled = forall a. Maybe a
Prelude.Nothing,
      $sel:id:ApiKey' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing,
      $sel:lastUpdatedDate:ApiKey' :: Maybe POSIX
lastUpdatedDate = forall a. Maybe a
Prelude.Nothing,
      $sel:name:ApiKey' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:stageKeys:ApiKey' :: Maybe [Text]
stageKeys = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:ApiKey' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:value:ApiKey' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The timestamp when the API Key was created.
apiKey_createdDate :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.UTCTime)
apiKey_createdDate :: Lens' ApiKey (Maybe UTCTime)
apiKey_createdDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe POSIX
createdDate :: Maybe POSIX
$sel:createdDate:ApiKey' :: ApiKey -> Maybe POSIX
createdDate} -> Maybe POSIX
createdDate) (\s :: ApiKey
s@ApiKey' {} Maybe POSIX
a -> ApiKey
s {$sel:createdDate:ApiKey' :: Maybe POSIX
createdDate = Maybe POSIX
a} :: ApiKey) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | An AWS Marketplace customer identifier , when integrating with the AWS
-- SaaS Marketplace.
apiKey_customerId :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_customerId :: Lens' ApiKey (Maybe Text)
apiKey_customerId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Text
customerId :: Maybe Text
$sel:customerId:ApiKey' :: ApiKey -> Maybe Text
customerId} -> Maybe Text
customerId) (\s :: ApiKey
s@ApiKey' {} Maybe Text
a -> ApiKey
s {$sel:customerId:ApiKey' :: Maybe Text
customerId = Maybe Text
a} :: ApiKey)

-- | The description of the API Key.
apiKey_description :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_description :: Lens' ApiKey (Maybe Text)
apiKey_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Text
description :: Maybe Text
$sel:description:ApiKey' :: ApiKey -> Maybe Text
description} -> Maybe Text
description) (\s :: ApiKey
s@ApiKey' {} Maybe Text
a -> ApiKey
s {$sel:description:ApiKey' :: Maybe Text
description = Maybe Text
a} :: ApiKey)

-- | Specifies whether the API Key can be used by callers.
apiKey_enabled :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Bool)
apiKey_enabled :: Lens' ApiKey (Maybe Bool)
apiKey_enabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:ApiKey' :: ApiKey -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: ApiKey
s@ApiKey' {} Maybe Bool
a -> ApiKey
s {$sel:enabled:ApiKey' :: Maybe Bool
enabled = Maybe Bool
a} :: ApiKey)

-- | The identifier of the API Key.
apiKey_id :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_id :: Lens' ApiKey (Maybe Text)
apiKey_id = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Text
id :: Maybe Text
$sel:id:ApiKey' :: ApiKey -> Maybe Text
id} -> Maybe Text
id) (\s :: ApiKey
s@ApiKey' {} Maybe Text
a -> ApiKey
s {$sel:id:ApiKey' :: Maybe Text
id = Maybe Text
a} :: ApiKey)

-- | The timestamp when the API Key was last updated.
apiKey_lastUpdatedDate :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.UTCTime)
apiKey_lastUpdatedDate :: Lens' ApiKey (Maybe UTCTime)
apiKey_lastUpdatedDate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe POSIX
lastUpdatedDate :: Maybe POSIX
$sel:lastUpdatedDate:ApiKey' :: ApiKey -> Maybe POSIX
lastUpdatedDate} -> Maybe POSIX
lastUpdatedDate) (\s :: ApiKey
s@ApiKey' {} Maybe POSIX
a -> ApiKey
s {$sel:lastUpdatedDate:ApiKey' :: Maybe POSIX
lastUpdatedDate = Maybe POSIX
a} :: ApiKey) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The name of the API Key.
apiKey_name :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_name :: Lens' ApiKey (Maybe Text)
apiKey_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Text
name :: Maybe Text
$sel:name:ApiKey' :: ApiKey -> Maybe Text
name} -> Maybe Text
name) (\s :: ApiKey
s@ApiKey' {} Maybe Text
a -> ApiKey
s {$sel:name:ApiKey' :: Maybe Text
name = Maybe Text
a} :: ApiKey)

-- | A list of Stage resources that are associated with the ApiKey resource.
apiKey_stageKeys :: Lens.Lens' ApiKey (Prelude.Maybe [Prelude.Text])
apiKey_stageKeys :: Lens' ApiKey (Maybe [Text])
apiKey_stageKeys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe [Text]
stageKeys :: Maybe [Text]
$sel:stageKeys:ApiKey' :: ApiKey -> Maybe [Text]
stageKeys} -> Maybe [Text]
stageKeys) (\s :: ApiKey
s@ApiKey' {} Maybe [Text]
a -> ApiKey
s {$sel:stageKeys:ApiKey' :: Maybe [Text]
stageKeys = Maybe [Text]
a} :: ApiKey) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The collection of tags. Each tag element is associated with a given
-- resource.
apiKey_tags :: Lens.Lens' ApiKey (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
apiKey_tags :: Lens' ApiKey (Maybe (HashMap Text Text))
apiKey_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:ApiKey' :: ApiKey -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: ApiKey
s@ApiKey' {} Maybe (HashMap Text Text)
a -> ApiKey
s {$sel:tags:ApiKey' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: ApiKey) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The value of the API Key.
apiKey_value :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_value :: Lens' ApiKey (Maybe Text)
apiKey_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Text
value :: Maybe Text
$sel:value:ApiKey' :: ApiKey -> Maybe Text
value} -> Maybe Text
value) (\s :: ApiKey
s@ApiKey' {} Maybe Text
a -> ApiKey
s {$sel:value:ApiKey' :: Maybe Text
value = Maybe Text
a} :: ApiKey)

instance Data.FromJSON ApiKey where
  parseJSON :: Value -> Parser ApiKey
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ApiKey"
      ( \Object
x ->
          Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe [Text]
-> Maybe (HashMap Text Text)
-> Maybe Text
-> ApiKey
ApiKey'
            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
"createdDate")
            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
"customerId")
            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
"description")
            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
"enabled")
            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
"id")
            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
"lastUpdatedDate")
            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
"name")
            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
"stageKeys" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"tags" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"value")
      )

instance Prelude.Hashable ApiKey where
  hashWithSalt :: Int -> ApiKey -> Int
hashWithSalt Int
_salt ApiKey' {Maybe Bool
Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
value :: Maybe Text
tags :: Maybe (HashMap Text Text)
stageKeys :: Maybe [Text]
name :: Maybe Text
lastUpdatedDate :: Maybe POSIX
id :: Maybe Text
enabled :: Maybe Bool
description :: Maybe Text
customerId :: Maybe Text
createdDate :: Maybe POSIX
$sel:value:ApiKey' :: ApiKey -> Maybe Text
$sel:tags:ApiKey' :: ApiKey -> Maybe (HashMap Text Text)
$sel:stageKeys:ApiKey' :: ApiKey -> Maybe [Text]
$sel:name:ApiKey' :: ApiKey -> Maybe Text
$sel:lastUpdatedDate:ApiKey' :: ApiKey -> Maybe POSIX
$sel:id:ApiKey' :: ApiKey -> Maybe Text
$sel:enabled:ApiKey' :: ApiKey -> Maybe Bool
$sel:description:ApiKey' :: ApiKey -> Maybe Text
$sel:customerId:ApiKey' :: ApiKey -> Maybe Text
$sel:createdDate:ApiKey' :: ApiKey -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createdDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
customerId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
enabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
lastUpdatedDate
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
stageKeys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData ApiKey where
  rnf :: ApiKey -> ()
rnf ApiKey' {Maybe Bool
Maybe [Text]
Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
value :: Maybe Text
tags :: Maybe (HashMap Text Text)
stageKeys :: Maybe [Text]
name :: Maybe Text
lastUpdatedDate :: Maybe POSIX
id :: Maybe Text
enabled :: Maybe Bool
description :: Maybe Text
customerId :: Maybe Text
createdDate :: Maybe POSIX
$sel:value:ApiKey' :: ApiKey -> Maybe Text
$sel:tags:ApiKey' :: ApiKey -> Maybe (HashMap Text Text)
$sel:stageKeys:ApiKey' :: ApiKey -> Maybe [Text]
$sel:name:ApiKey' :: ApiKey -> Maybe Text
$sel:lastUpdatedDate:ApiKey' :: ApiKey -> Maybe POSIX
$sel:id:ApiKey' :: ApiKey -> Maybe Text
$sel:enabled:ApiKey' :: ApiKey -> Maybe Bool
$sel:description:ApiKey' :: ApiKey -> Maybe Text
$sel:customerId:ApiKey' :: ApiKey -> Maybe Text
$sel:createdDate:ApiKey' :: ApiKey -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createdDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
customerId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
enabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
lastUpdatedDate
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
stageKeys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value