{-# 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.Lightsail.Types.AccessKey
-- 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.Lightsail.Types.AccessKey where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Lightsail.Types.AccessKeyLastUsed
import Amazonka.Lightsail.Types.StatusType
import qualified Amazonka.Prelude as Prelude

-- | Describes an access key for an Amazon Lightsail bucket.
--
-- Access keys grant full programmatic access to the specified bucket and
-- its objects. You can have a maximum of two access keys per bucket. Use
-- the CreateBucketAccessKey action to create an access key for a specific
-- bucket. For more information about access keys, see
-- <https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-creating-bucket-access-keys Creating access keys for a bucket in Amazon Lightsail>
-- in the /Amazon Lightsail Developer Guide/.
--
-- The @secretAccessKey@ value is returned only in response to the
-- @CreateBucketAccessKey@ action. You can get a secret access key only
-- when you first create an access key; you cannot get the secret access
-- key later. If you lose the secret access key, you must create a new
-- access key.
--
-- /See:/ 'newAccessKey' smart constructor.
data AccessKey = AccessKey'
  { -- | The status of the access key.
    --
    -- A status of @Active@ means that the key is valid, while @Inactive@ means
    -- it is not.
    AccessKey -> Maybe StatusType
status :: Prelude.Maybe StatusType,
    -- | The timestamp when the access key was created.
    AccessKey -> Maybe POSIX
createdAt :: Prelude.Maybe Core.POSIX,
    -- | The secret access key used to sign requests.
    --
    -- You should store the secret access key in a safe location. We recommend
    -- that you delete the access key if the secret access key is compromised.
    AccessKey -> Maybe Text
secretAccessKey :: Prelude.Maybe Prelude.Text,
    -- | An object that describes the last time the access key was used.
    --
    -- This object does not include data in the response of a
    -- CreateBucketAccessKey action. If the access key has not been used, the
    -- @region@ and @serviceName@ values are @N\/A@, and the @lastUsedDate@
    -- value is null.
    AccessKey -> Maybe AccessKeyLastUsed
lastUsed :: Prelude.Maybe AccessKeyLastUsed,
    -- | The ID of the access key.
    AccessKey -> Maybe (Sensitive Text)
accessKeyId :: Prelude.Maybe (Core.Sensitive Prelude.Text)
  }
  deriving (AccessKey -> AccessKey -> Bool
(AccessKey -> AccessKey -> Bool)
-> (AccessKey -> AccessKey -> Bool) -> Eq AccessKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AccessKey -> AccessKey -> Bool
$c/= :: AccessKey -> AccessKey -> Bool
== :: AccessKey -> AccessKey -> Bool
$c== :: AccessKey -> AccessKey -> Bool
Prelude.Eq, Int -> AccessKey -> ShowS
[AccessKey] -> ShowS
AccessKey -> String
(Int -> AccessKey -> ShowS)
-> (AccessKey -> String)
-> ([AccessKey] -> ShowS)
-> Show AccessKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AccessKey] -> ShowS
$cshowList :: [AccessKey] -> ShowS
show :: AccessKey -> String
$cshow :: AccessKey -> String
showsPrec :: Int -> AccessKey -> ShowS
$cshowsPrec :: Int -> AccessKey -> ShowS
Prelude.Show, (forall x. AccessKey -> Rep AccessKey x)
-> (forall x. Rep AccessKey x -> AccessKey) -> Generic AccessKey
forall x. Rep AccessKey x -> AccessKey
forall x. AccessKey -> Rep AccessKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AccessKey x -> AccessKey
$cfrom :: forall x. AccessKey -> Rep AccessKey x
Prelude.Generic)

-- |
-- Create a value of 'AccessKey' 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:
--
-- 'status', 'accessKey_status' - The status of the access key.
--
-- A status of @Active@ means that the key is valid, while @Inactive@ means
-- it is not.
--
-- 'createdAt', 'accessKey_createdAt' - The timestamp when the access key was created.
--
-- 'secretAccessKey', 'accessKey_secretAccessKey' - The secret access key used to sign requests.
--
-- You should store the secret access key in a safe location. We recommend
-- that you delete the access key if the secret access key is compromised.
--
-- 'lastUsed', 'accessKey_lastUsed' - An object that describes the last time the access key was used.
--
-- This object does not include data in the response of a
-- CreateBucketAccessKey action. If the access key has not been used, the
-- @region@ and @serviceName@ values are @N\/A@, and the @lastUsedDate@
-- value is null.
--
-- 'accessKeyId', 'accessKey_accessKeyId' - The ID of the access key.
newAccessKey ::
  AccessKey
newAccessKey :: AccessKey
newAccessKey =
  AccessKey' :: Maybe StatusType
-> Maybe POSIX
-> Maybe Text
-> Maybe AccessKeyLastUsed
-> Maybe (Sensitive Text)
-> AccessKey
AccessKey'
    { $sel:status:AccessKey' :: Maybe StatusType
status = Maybe StatusType
forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:AccessKey' :: Maybe POSIX
createdAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:secretAccessKey:AccessKey' :: Maybe Text
secretAccessKey = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:lastUsed:AccessKey' :: Maybe AccessKeyLastUsed
lastUsed = Maybe AccessKeyLastUsed
forall a. Maybe a
Prelude.Nothing,
      $sel:accessKeyId:AccessKey' :: Maybe (Sensitive Text)
accessKeyId = Maybe (Sensitive Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | The status of the access key.
--
-- A status of @Active@ means that the key is valid, while @Inactive@ means
-- it is not.
accessKey_status :: Lens.Lens' AccessKey (Prelude.Maybe StatusType)
accessKey_status :: (Maybe StatusType -> f (Maybe StatusType))
-> AccessKey -> f AccessKey
accessKey_status = (AccessKey -> Maybe StatusType)
-> (AccessKey -> Maybe StatusType -> AccessKey)
-> Lens AccessKey AccessKey (Maybe StatusType) (Maybe StatusType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKey' {Maybe StatusType
status :: Maybe StatusType
$sel:status:AccessKey' :: AccessKey -> Maybe StatusType
status} -> Maybe StatusType
status) (\s :: AccessKey
s@AccessKey' {} Maybe StatusType
a -> AccessKey
s {$sel:status:AccessKey' :: Maybe StatusType
status = Maybe StatusType
a} :: AccessKey)

-- | The timestamp when the access key was created.
accessKey_createdAt :: Lens.Lens' AccessKey (Prelude.Maybe Prelude.UTCTime)
accessKey_createdAt :: (Maybe UTCTime -> f (Maybe UTCTime)) -> AccessKey -> f AccessKey
accessKey_createdAt = (AccessKey -> Maybe POSIX)
-> (AccessKey -> Maybe POSIX -> AccessKey)
-> Lens AccessKey AccessKey (Maybe POSIX) (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKey' {Maybe POSIX
createdAt :: Maybe POSIX
$sel:createdAt:AccessKey' :: AccessKey -> Maybe POSIX
createdAt} -> Maybe POSIX
createdAt) (\s :: AccessKey
s@AccessKey' {} Maybe POSIX
a -> AccessKey
s {$sel:createdAt:AccessKey' :: Maybe POSIX
createdAt = Maybe POSIX
a} :: AccessKey) ((Maybe POSIX -> f (Maybe POSIX)) -> AccessKey -> f AccessKey)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> AccessKey
-> f AccessKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
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 POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The secret access key used to sign requests.
--
-- You should store the secret access key in a safe location. We recommend
-- that you delete the access key if the secret access key is compromised.
accessKey_secretAccessKey :: Lens.Lens' AccessKey (Prelude.Maybe Prelude.Text)
accessKey_secretAccessKey :: (Maybe Text -> f (Maybe Text)) -> AccessKey -> f AccessKey
accessKey_secretAccessKey = (AccessKey -> Maybe Text)
-> (AccessKey -> Maybe Text -> AccessKey)
-> Lens AccessKey AccessKey (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKey' {Maybe Text
secretAccessKey :: Maybe Text
$sel:secretAccessKey:AccessKey' :: AccessKey -> Maybe Text
secretAccessKey} -> Maybe Text
secretAccessKey) (\s :: AccessKey
s@AccessKey' {} Maybe Text
a -> AccessKey
s {$sel:secretAccessKey:AccessKey' :: Maybe Text
secretAccessKey = Maybe Text
a} :: AccessKey)

-- | An object that describes the last time the access key was used.
--
-- This object does not include data in the response of a
-- CreateBucketAccessKey action. If the access key has not been used, the
-- @region@ and @serviceName@ values are @N\/A@, and the @lastUsedDate@
-- value is null.
accessKey_lastUsed :: Lens.Lens' AccessKey (Prelude.Maybe AccessKeyLastUsed)
accessKey_lastUsed :: (Maybe AccessKeyLastUsed -> f (Maybe AccessKeyLastUsed))
-> AccessKey -> f AccessKey
accessKey_lastUsed = (AccessKey -> Maybe AccessKeyLastUsed)
-> (AccessKey -> Maybe AccessKeyLastUsed -> AccessKey)
-> Lens
     AccessKey
     AccessKey
     (Maybe AccessKeyLastUsed)
     (Maybe AccessKeyLastUsed)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKey' {Maybe AccessKeyLastUsed
lastUsed :: Maybe AccessKeyLastUsed
$sel:lastUsed:AccessKey' :: AccessKey -> Maybe AccessKeyLastUsed
lastUsed} -> Maybe AccessKeyLastUsed
lastUsed) (\s :: AccessKey
s@AccessKey' {} Maybe AccessKeyLastUsed
a -> AccessKey
s {$sel:lastUsed:AccessKey' :: Maybe AccessKeyLastUsed
lastUsed = Maybe AccessKeyLastUsed
a} :: AccessKey)

-- | The ID of the access key.
accessKey_accessKeyId :: Lens.Lens' AccessKey (Prelude.Maybe Prelude.Text)
accessKey_accessKeyId :: (Maybe Text -> f (Maybe Text)) -> AccessKey -> f AccessKey
accessKey_accessKeyId = (AccessKey -> Maybe (Sensitive Text))
-> (AccessKey -> Maybe (Sensitive Text) -> AccessKey)
-> Lens
     AccessKey
     AccessKey
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AccessKey' {Maybe (Sensitive Text)
accessKeyId :: Maybe (Sensitive Text)
$sel:accessKeyId:AccessKey' :: AccessKey -> Maybe (Sensitive Text)
accessKeyId} -> Maybe (Sensitive Text)
accessKeyId) (\s :: AccessKey
s@AccessKey' {} Maybe (Sensitive Text)
a -> AccessKey
s {$sel:accessKeyId:AccessKey' :: Maybe (Sensitive Text)
accessKeyId = Maybe (Sensitive Text)
a} :: AccessKey) ((Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
 -> AccessKey -> f AccessKey)
-> ((Maybe Text -> f (Maybe Text))
    -> Maybe (Sensitive Text) -> f (Maybe (Sensitive Text)))
-> (Maybe Text -> f (Maybe Text))
-> AccessKey
-> f AccessKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso (Sensitive Text) (Sensitive Text) Text Text
-> Iso
     (Maybe (Sensitive Text))
     (Maybe (Sensitive Text))
     (Maybe Text)
     (Maybe 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 (Sensitive Text) (Sensitive Text) Text Text
forall a. Iso' (Sensitive a) a
Core._Sensitive

instance Core.FromJSON AccessKey where
  parseJSON :: Value -> Parser AccessKey
parseJSON =
    String -> (Object -> Parser AccessKey) -> Value -> Parser AccessKey
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AccessKey"
      ( \Object
x ->
          Maybe StatusType
-> Maybe POSIX
-> Maybe Text
-> Maybe AccessKeyLastUsed
-> Maybe (Sensitive Text)
-> AccessKey
AccessKey'
            (Maybe StatusType
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe AccessKeyLastUsed
 -> Maybe (Sensitive Text)
 -> AccessKey)
-> Parser (Maybe StatusType)
-> Parser
     (Maybe POSIX
      -> Maybe Text
      -> Maybe AccessKeyLastUsed
      -> Maybe (Sensitive Text)
      -> AccessKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe StatusType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"status")
            Parser
  (Maybe POSIX
   -> Maybe Text
   -> Maybe AccessKeyLastUsed
   -> Maybe (Sensitive Text)
   -> AccessKey)
-> Parser (Maybe POSIX)
-> Parser
     (Maybe Text
      -> Maybe AccessKeyLastUsed -> Maybe (Sensitive Text) -> AccessKey)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"createdAt")
            Parser
  (Maybe Text
   -> Maybe AccessKeyLastUsed -> Maybe (Sensitive Text) -> AccessKey)
-> Parser (Maybe Text)
-> Parser
     (Maybe AccessKeyLastUsed -> Maybe (Sensitive Text) -> AccessKey)
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
"secretAccessKey")
            Parser
  (Maybe AccessKeyLastUsed -> Maybe (Sensitive Text) -> AccessKey)
-> Parser (Maybe AccessKeyLastUsed)
-> Parser (Maybe (Sensitive Text) -> AccessKey)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AccessKeyLastUsed)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"lastUsed")
            Parser (Maybe (Sensitive Text) -> AccessKey)
-> Parser (Maybe (Sensitive Text)) -> Parser AccessKey
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Sensitive Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"accessKeyId")
      )

instance Prelude.Hashable AccessKey

instance Prelude.NFData AccessKey