{-# 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.AppSync.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.AppSync.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

-- | Describes an API key.
--
-- Customers invoke AppSync GraphQL API operations with API keys as an
-- identity mechanism. There are two key versions:
--
-- __da1__: We introduced this version at launch in November 2017. These
-- keys always expire after 7 days. Amazon DynamoDB TTL manages key
-- expiration. These keys ceased to be valid after February 21, 2018, and
-- they should no longer be used.
--
-- -   @ListApiKeys@ returns the expiration time in milliseconds.
--
-- -   @CreateApiKey@ returns the expiration time in milliseconds.
--
-- -   @UpdateApiKey@ is not available for this key version.
--
-- -   @DeleteApiKey@ deletes the item from the table.
--
-- -   Expiration is stored in DynamoDB as milliseconds. This results in a
--     bug where keys are not automatically deleted because DynamoDB
--     expects the TTL to be stored in seconds. As a one-time action, we
--     deleted these keys from the table on February 21, 2018.
--
-- __da2__: We introduced this version in February 2018 when AppSync added
-- support to extend key expiration.
--
-- -   @ListApiKeys@ returns the expiration time and deletion time in
--     seconds.
--
-- -   @CreateApiKey@ returns the expiration time and deletion time in
--     seconds and accepts a user-provided expiration time in seconds.
--
-- -   @UpdateApiKey@ returns the expiration time and and deletion time in
--     seconds and accepts a user-provided expiration time in seconds.
--     Expired API keys are kept for 60 days after the expiration time. You
--     can update the key expiration time as long as the key isn\'t
--     deleted.
--
-- -   @DeleteApiKey@ deletes the item from the table.
--
-- -   Expiration is stored in DynamoDB as seconds. After the expiration
--     time, using the key to authenticate will fail. However, you can
--     reinstate the key before deletion.
--
-- -   Deletion is stored in DynamoDB as seconds. The key is deleted after
--     deletion time.
--
-- /See:/ 'newApiKey' smart constructor.
data ApiKey = ApiKey'
  { -- | The time after which the API key is deleted. The date is represented as
    -- seconds since the epoch, rounded down to the nearest hour.
    ApiKey -> Maybe Integer
deletes :: Prelude.Maybe Prelude.Integer,
    -- | A description of the purpose of the API key.
    ApiKey -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The time after which the API key expires. The date is represented as
    -- seconds since the epoch, rounded down to the nearest hour.
    ApiKey -> Maybe Integer
expires :: Prelude.Maybe Prelude.Integer,
    -- | The API key ID.
    ApiKey -> Maybe Text
id :: 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:
--
-- 'deletes', 'apiKey_deletes' - The time after which the API key is deleted. The date is represented as
-- seconds since the epoch, rounded down to the nearest hour.
--
-- 'description', 'apiKey_description' - A description of the purpose of the API key.
--
-- 'expires', 'apiKey_expires' - The time after which the API key expires. The date is represented as
-- seconds since the epoch, rounded down to the nearest hour.
--
-- 'id', 'apiKey_id' - The API key ID.
newApiKey ::
  ApiKey
newApiKey :: ApiKey
newApiKey =
  ApiKey'
    { $sel:deletes:ApiKey' :: Maybe Integer
deletes = forall a. Maybe a
Prelude.Nothing,
      $sel:description:ApiKey' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:expires:ApiKey' :: Maybe Integer
expires = forall a. Maybe a
Prelude.Nothing,
      $sel:id:ApiKey' :: Maybe Text
id = forall a. Maybe a
Prelude.Nothing
    }

-- | The time after which the API key is deleted. The date is represented as
-- seconds since the epoch, rounded down to the nearest hour.
apiKey_deletes :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Integer)
apiKey_deletes :: Lens' ApiKey (Maybe Integer)
apiKey_deletes = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Integer
deletes :: Maybe Integer
$sel:deletes:ApiKey' :: ApiKey -> Maybe Integer
deletes} -> Maybe Integer
deletes) (\s :: ApiKey
s@ApiKey' {} Maybe Integer
a -> ApiKey
s {$sel:deletes:ApiKey' :: Maybe Integer
deletes = Maybe Integer
a} :: ApiKey)

-- | A description of the purpose 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)

-- | The time after which the API key expires. The date is represented as
-- seconds since the epoch, rounded down to the nearest hour.
apiKey_expires :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Integer)
apiKey_expires :: Lens' ApiKey (Maybe Integer)
apiKey_expires = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApiKey' {Maybe Integer
expires :: Maybe Integer
$sel:expires:ApiKey' :: ApiKey -> Maybe Integer
expires} -> Maybe Integer
expires) (\s :: ApiKey
s@ApiKey' {} Maybe Integer
a -> ApiKey
s {$sel:expires:ApiKey' :: Maybe Integer
expires = Maybe Integer
a} :: ApiKey)

-- | The API key ID.
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)

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 Integer
-> Maybe Text -> Maybe Integer -> 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
"deletes")
            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
"expires")
            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")
      )

instance Prelude.Hashable ApiKey where
  hashWithSalt :: Int -> ApiKey -> Int
hashWithSalt Int
_salt ApiKey' {Maybe Integer
Maybe Text
id :: Maybe Text
expires :: Maybe Integer
description :: Maybe Text
deletes :: Maybe Integer
$sel:id:ApiKey' :: ApiKey -> Maybe Text
$sel:expires:ApiKey' :: ApiKey -> Maybe Integer
$sel:description:ApiKey' :: ApiKey -> Maybe Text
$sel:deletes:ApiKey' :: ApiKey -> Maybe Integer
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
deletes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Integer
expires
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
id

instance Prelude.NFData ApiKey where
  rnf :: ApiKey -> ()
rnf ApiKey' {Maybe Integer
Maybe Text
id :: Maybe Text
expires :: Maybe Integer
description :: Maybe Text
deletes :: Maybe Integer
$sel:id:ApiKey' :: ApiKey -> Maybe Text
$sel:expires:ApiKey' :: ApiKey -> Maybe Integer
$sel:description:ApiKey' :: ApiKey -> Maybe Text
$sel:deletes:ApiKey' :: ApiKey -> Maybe Integer
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Integer
deletes
      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 Integer
expires
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
id