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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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__: This version was introduced at launch in November 2017. These
-- keys always expire after 7 days. Key expiration is managed by Amazon
-- DynamoDB TTL. The keys ceased to be valid after February 21, 2018 and
-- should not be used after that date.
--
-- -   @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 Amazon 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 will delete these keys from the table after February 21,
--     2018.
--
-- __da2__: This version was introduced 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. Key
--     expiration time can be updated while the key is not deleted.
--
-- -   @DeleteApiKey@ deletes the item from the table.
--
-- -   Expiration is stored in Amazon DynamoDB as seconds. After the
--     expiration time, using the key to authenticate will fail. But the
--     key can be reinstated before deletion.
--
-- -   Deletion is stored in Amazon DynamoDB as seconds. The key will be
--     deleted after deletion time.
--
-- /See:/ 'newApiKey' smart constructor.
data ApiKey = 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 -> Maybe Integer
expires :: Prelude.Maybe Prelude.Integer,
    -- | 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,
    -- | The API key ID.
    ApiKey -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | A description of the purpose of the API key.
    ApiKey -> Maybe Text
description :: Prelude.Maybe Prelude.Text
  }
  deriving (ApiKey -> ApiKey -> Bool
(ApiKey -> ApiKey -> Bool)
-> (ApiKey -> ApiKey -> Bool) -> Eq ApiKey
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]
(Int -> ReadS ApiKey)
-> ReadS [ApiKey]
-> ReadPrec ApiKey
-> ReadPrec [ApiKey]
-> Read 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
(Int -> ApiKey -> ShowS)
-> (ApiKey -> String) -> ([ApiKey] -> ShowS) -> Show ApiKey
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. ApiKey -> Rep ApiKey x)
-> (forall x. Rep ApiKey x -> ApiKey) -> Generic ApiKey
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:
--
-- '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.
--
-- '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.
--
-- 'id', 'apiKey_id' - The API key ID.
--
-- 'description', 'apiKey_description' - A description of the purpose of the API key.
newApiKey ::
  ApiKey
newApiKey :: ApiKey
newApiKey =
  ApiKey' :: Maybe Integer
-> Maybe Integer -> Maybe Text -> Maybe Text -> ApiKey
ApiKey'
    { $sel:expires:ApiKey' :: Maybe Integer
expires = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:deletes:ApiKey' :: Maybe Integer
deletes = Maybe Integer
forall a. Maybe a
Prelude.Nothing,
      $sel:id:ApiKey' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:ApiKey' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Integer -> f (Maybe Integer)) -> ApiKey -> f ApiKey
apiKey_expires = (ApiKey -> Maybe Integer)
-> (ApiKey -> Maybe Integer -> ApiKey)
-> Lens ApiKey ApiKey (Maybe Integer) (Maybe Integer)
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 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 :: (Maybe Integer -> f (Maybe Integer)) -> ApiKey -> f ApiKey
apiKey_deletes = (ApiKey -> Maybe Integer)
-> (ApiKey -> Maybe Integer -> ApiKey)
-> Lens ApiKey ApiKey (Maybe Integer) (Maybe Integer)
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)

-- | The API key ID.
apiKey_id :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_id :: (Maybe Text -> f (Maybe Text)) -> ApiKey -> f ApiKey
apiKey_id = (ApiKey -> Maybe Text)
-> (ApiKey -> Maybe Text -> ApiKey)
-> Lens ApiKey ApiKey (Maybe Text) (Maybe Text)
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)

-- | A description of the purpose of the API key.
apiKey_description :: Lens.Lens' ApiKey (Prelude.Maybe Prelude.Text)
apiKey_description :: (Maybe Text -> f (Maybe Text)) -> ApiKey -> f ApiKey
apiKey_description = (ApiKey -> Maybe Text)
-> (ApiKey -> Maybe Text -> ApiKey)
-> Lens ApiKey ApiKey (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON ApiKey where
  parseJSON :: Value -> Parser ApiKey
parseJSON =
    String -> (Object -> Parser ApiKey) -> Value -> Parser ApiKey
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ApiKey"
      ( \Object
x ->
          Maybe Integer
-> Maybe Integer -> Maybe Text -> Maybe Text -> ApiKey
ApiKey'
            (Maybe Integer
 -> Maybe Integer -> Maybe Text -> Maybe Text -> ApiKey)
-> Parser (Maybe Integer)
-> Parser (Maybe Integer -> Maybe Text -> Maybe Text -> ApiKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"expires")
            Parser (Maybe Integer -> Maybe Text -> Maybe Text -> ApiKey)
-> Parser (Maybe Integer)
-> Parser (Maybe Text -> Maybe Text -> ApiKey)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"deletes")
            Parser (Maybe Text -> Maybe Text -> ApiKey)
-> Parser (Maybe Text) -> Parser (Maybe Text -> ApiKey)
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
"id")
            Parser (Maybe Text -> ApiKey)
-> Parser (Maybe Text) -> Parser ApiKey
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
"description")
      )

instance Prelude.Hashable ApiKey

instance Prelude.NFData ApiKey