{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Lightsail.Types.AccessKey where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_CreateBucketAccessKey.html 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 ID of the access key.
    AccessKey -> Maybe (Sensitive Text)
accessKeyId :: Prelude.Maybe (Data.Sensitive Prelude.Text),
    -- | The timestamp when the access key was created.
    AccessKey -> Maybe POSIX
createdAt :: Prelude.Maybe Data.POSIX,
    -- | An object that describes the last time the access key was used.
    --
    -- This object does not include data in the response of a
    -- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_CreateBucketAccessKey.html 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 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,
    -- | 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
  }
  deriving (AccessKey -> AccessKey -> Bool
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
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. 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:
--
-- 'accessKeyId', 'accessKey_accessKeyId' - The ID of the access key.
--
-- 'createdAt', 'accessKey_createdAt' - The timestamp when the access key was created.
--
-- '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
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_CreateBucketAccessKey.html CreateBucketAccessKey>
-- action. If the access key has not been used, the @region@ and
-- @serviceName@ values are @N\/A@, and the @lastUsedDate@ value is null.
--
-- '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.
--
-- '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.
newAccessKey ::
  AccessKey
newAccessKey :: AccessKey
newAccessKey =
  AccessKey'
    { $sel:accessKeyId:AccessKey' :: Maybe (Sensitive Text)
accessKeyId = forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:AccessKey' :: Maybe POSIX
createdAt = forall a. Maybe a
Prelude.Nothing,
      $sel:lastUsed:AccessKey' :: Maybe AccessKeyLastUsed
lastUsed = forall a. Maybe a
Prelude.Nothing,
      $sel:secretAccessKey:AccessKey' :: Maybe Text
secretAccessKey = forall a. Maybe a
Prelude.Nothing,
      $sel:status:AccessKey' :: Maybe StatusType
status = forall a. Maybe a
Prelude.Nothing
    }

-- | The ID of the access key.
accessKey_accessKeyId :: Lens.Lens' AccessKey (Prelude.Maybe Prelude.Text)
accessKey_accessKeyId :: Lens' AccessKey (Maybe Text)
accessKey_accessKeyId = 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) 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. Iso' (Sensitive a) a
Data._Sensitive

-- | The timestamp when the access key was created.
accessKey_createdAt :: Lens.Lens' AccessKey (Prelude.Maybe Prelude.UTCTime)
accessKey_createdAt :: Lens' AccessKey (Maybe UTCTime)
accessKey_createdAt = 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) 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 object that describes the last time the access key was used.
--
-- This object does not include data in the response of a
-- <https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_CreateBucketAccessKey.html 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 :: Lens' AccessKey (Maybe AccessKeyLastUsed)
accessKey_lastUsed = 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 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 :: Lens' AccessKey (Maybe Text)
accessKey_secretAccessKey = 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)

-- | 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 :: Lens' AccessKey (Maybe StatusType)
accessKey_status = 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)

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

instance Prelude.Hashable AccessKey where
  hashWithSalt :: Int -> AccessKey -> Int
hashWithSalt Int
_salt AccessKey' {Maybe Text
Maybe (Sensitive Text)
Maybe POSIX
Maybe AccessKeyLastUsed
Maybe StatusType
status :: Maybe StatusType
secretAccessKey :: Maybe Text
lastUsed :: Maybe AccessKeyLastUsed
createdAt :: Maybe POSIX
accessKeyId :: Maybe (Sensitive Text)
$sel:status:AccessKey' :: AccessKey -> Maybe StatusType
$sel:secretAccessKey:AccessKey' :: AccessKey -> Maybe Text
$sel:lastUsed:AccessKey' :: AccessKey -> Maybe AccessKeyLastUsed
$sel:createdAt:AccessKey' :: AccessKey -> Maybe POSIX
$sel:accessKeyId:AccessKey' :: AccessKey -> Maybe (Sensitive Text)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (Sensitive Text)
accessKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createdAt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AccessKeyLastUsed
lastUsed
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
secretAccessKey
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StatusType
status

instance Prelude.NFData AccessKey where
  rnf :: AccessKey -> ()
rnf AccessKey' {Maybe Text
Maybe (Sensitive Text)
Maybe POSIX
Maybe AccessKeyLastUsed
Maybe StatusType
status :: Maybe StatusType
secretAccessKey :: Maybe Text
lastUsed :: Maybe AccessKeyLastUsed
createdAt :: Maybe POSIX
accessKeyId :: Maybe (Sensitive Text)
$sel:status:AccessKey' :: AccessKey -> Maybe StatusType
$sel:secretAccessKey:AccessKey' :: AccessKey -> Maybe Text
$sel:lastUsed:AccessKey' :: AccessKey -> Maybe AccessKeyLastUsed
$sel:createdAt:AccessKey' :: AccessKey -> Maybe POSIX
$sel:accessKeyId:AccessKey' :: AccessKey -> Maybe (Sensitive Text)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (Sensitive Text)
accessKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createdAt
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe AccessKeyLastUsed
lastUsed
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
secretAccessKey
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe StatusType
status