{-# 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.AccessAnalyzer.Types.EbsSnapshotConfiguration
-- 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.AccessAnalyzer.Types.EbsSnapshotConfiguration 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

-- | The proposed access control configuration for an Amazon EBS volume
-- snapshot. You can propose a configuration for a new Amazon EBS volume
-- snapshot or an Amazon EBS volume snapshot that you own by specifying the
-- user IDs, groups, and optional KMS encryption key. For more information,
-- see
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifySnapshotAttribute.html ModifySnapshotAttribute>.
--
-- /See:/ 'newEbsSnapshotConfiguration' smart constructor.
data EbsSnapshotConfiguration = EbsSnapshotConfiguration'
  { -- | The groups that have access to the Amazon EBS volume snapshot. If the
    -- value @all@ is specified, then the Amazon EBS volume snapshot is public.
    --
    -- -   If the configuration is for an existing Amazon EBS volume snapshot
    --     and you do not specify the @groups@, then the access preview uses
    --     the existing shared @groups@ for the snapshot.
    --
    -- -   If the access preview is for a new resource and you do not specify
    --     the @groups@, then the access preview considers the snapshot without
    --     any @groups@.
    --
    -- -   To propose deletion of existing shared @groups@, you can specify an
    --     empty list for @groups@.
    EbsSnapshotConfiguration -> Maybe [Text]
groups :: Prelude.Maybe [Prelude.Text],
    -- | The KMS key identifier for an encrypted Amazon EBS volume snapshot. The
    -- KMS key identifier is the key ARN, key ID, alias ARN, or alias name for
    -- the KMS key.
    --
    -- -   If the configuration is for an existing Amazon EBS volume snapshot
    --     and you do not specify the @kmsKeyId@, or you specify an empty
    --     string, then the access preview uses the existing @kmsKeyId@ of the
    --     snapshot.
    --
    -- -   If the access preview is for a new resource and you do not specify
    --     the @kmsKeyId@, the access preview considers the snapshot as
    --     unencrypted.
    EbsSnapshotConfiguration -> Maybe Text
kmsKeyId :: Prelude.Maybe Prelude.Text,
    -- | The IDs of the Amazon Web Services accounts that have access to the
    -- Amazon EBS volume snapshot.
    --
    -- -   If the configuration is for an existing Amazon EBS volume snapshot
    --     and you do not specify the @userIds@, then the access preview uses
    --     the existing shared @userIds@ for the snapshot.
    --
    -- -   If the access preview is for a new resource and you do not specify
    --     the @userIds@, then the access preview considers the snapshot
    --     without any @userIds@.
    --
    -- -   To propose deletion of existing shared @accountIds@, you can specify
    --     an empty list for @userIds@.
    EbsSnapshotConfiguration -> Maybe [Text]
userIds :: Prelude.Maybe [Prelude.Text]
  }
  deriving (EbsSnapshotConfiguration -> EbsSnapshotConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EbsSnapshotConfiguration -> EbsSnapshotConfiguration -> Bool
$c/= :: EbsSnapshotConfiguration -> EbsSnapshotConfiguration -> Bool
== :: EbsSnapshotConfiguration -> EbsSnapshotConfiguration -> Bool
$c== :: EbsSnapshotConfiguration -> EbsSnapshotConfiguration -> Bool
Prelude.Eq, ReadPrec [EbsSnapshotConfiguration]
ReadPrec EbsSnapshotConfiguration
Int -> ReadS EbsSnapshotConfiguration
ReadS [EbsSnapshotConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EbsSnapshotConfiguration]
$creadListPrec :: ReadPrec [EbsSnapshotConfiguration]
readPrec :: ReadPrec EbsSnapshotConfiguration
$creadPrec :: ReadPrec EbsSnapshotConfiguration
readList :: ReadS [EbsSnapshotConfiguration]
$creadList :: ReadS [EbsSnapshotConfiguration]
readsPrec :: Int -> ReadS EbsSnapshotConfiguration
$creadsPrec :: Int -> ReadS EbsSnapshotConfiguration
Prelude.Read, Int -> EbsSnapshotConfiguration -> ShowS
[EbsSnapshotConfiguration] -> ShowS
EbsSnapshotConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EbsSnapshotConfiguration] -> ShowS
$cshowList :: [EbsSnapshotConfiguration] -> ShowS
show :: EbsSnapshotConfiguration -> String
$cshow :: EbsSnapshotConfiguration -> String
showsPrec :: Int -> EbsSnapshotConfiguration -> ShowS
$cshowsPrec :: Int -> EbsSnapshotConfiguration -> ShowS
Prelude.Show, forall x.
Rep EbsSnapshotConfiguration x -> EbsSnapshotConfiguration
forall x.
EbsSnapshotConfiguration -> Rep EbsSnapshotConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep EbsSnapshotConfiguration x -> EbsSnapshotConfiguration
$cfrom :: forall x.
EbsSnapshotConfiguration -> Rep EbsSnapshotConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'EbsSnapshotConfiguration' 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:
--
-- 'groups', 'ebsSnapshotConfiguration_groups' - The groups that have access to the Amazon EBS volume snapshot. If the
-- value @all@ is specified, then the Amazon EBS volume snapshot is public.
--
-- -   If the configuration is for an existing Amazon EBS volume snapshot
--     and you do not specify the @groups@, then the access preview uses
--     the existing shared @groups@ for the snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the @groups@, then the access preview considers the snapshot without
--     any @groups@.
--
-- -   To propose deletion of existing shared @groups@, you can specify an
--     empty list for @groups@.
--
-- 'kmsKeyId', 'ebsSnapshotConfiguration_kmsKeyId' - The KMS key identifier for an encrypted Amazon EBS volume snapshot. The
-- KMS key identifier is the key ARN, key ID, alias ARN, or alias name for
-- the KMS key.
--
-- -   If the configuration is for an existing Amazon EBS volume snapshot
--     and you do not specify the @kmsKeyId@, or you specify an empty
--     string, then the access preview uses the existing @kmsKeyId@ of the
--     snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the @kmsKeyId@, the access preview considers the snapshot as
--     unencrypted.
--
-- 'userIds', 'ebsSnapshotConfiguration_userIds' - The IDs of the Amazon Web Services accounts that have access to the
-- Amazon EBS volume snapshot.
--
-- -   If the configuration is for an existing Amazon EBS volume snapshot
--     and you do not specify the @userIds@, then the access preview uses
--     the existing shared @userIds@ for the snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the @userIds@, then the access preview considers the snapshot
--     without any @userIds@.
--
-- -   To propose deletion of existing shared @accountIds@, you can specify
--     an empty list for @userIds@.
newEbsSnapshotConfiguration ::
  EbsSnapshotConfiguration
newEbsSnapshotConfiguration :: EbsSnapshotConfiguration
newEbsSnapshotConfiguration =
  EbsSnapshotConfiguration'
    { $sel:groups:EbsSnapshotConfiguration' :: Maybe [Text]
groups = forall a. Maybe a
Prelude.Nothing,
      $sel:kmsKeyId:EbsSnapshotConfiguration' :: Maybe Text
kmsKeyId = forall a. Maybe a
Prelude.Nothing,
      $sel:userIds:EbsSnapshotConfiguration' :: Maybe [Text]
userIds = forall a. Maybe a
Prelude.Nothing
    }

-- | The groups that have access to the Amazon EBS volume snapshot. If the
-- value @all@ is specified, then the Amazon EBS volume snapshot is public.
--
-- -   If the configuration is for an existing Amazon EBS volume snapshot
--     and you do not specify the @groups@, then the access preview uses
--     the existing shared @groups@ for the snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the @groups@, then the access preview considers the snapshot without
--     any @groups@.
--
-- -   To propose deletion of existing shared @groups@, you can specify an
--     empty list for @groups@.
ebsSnapshotConfiguration_groups :: Lens.Lens' EbsSnapshotConfiguration (Prelude.Maybe [Prelude.Text])
ebsSnapshotConfiguration_groups :: Lens' EbsSnapshotConfiguration (Maybe [Text])
ebsSnapshotConfiguration_groups = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsSnapshotConfiguration' {Maybe [Text]
groups :: Maybe [Text]
$sel:groups:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
groups} -> Maybe [Text]
groups) (\s :: EbsSnapshotConfiguration
s@EbsSnapshotConfiguration' {} Maybe [Text]
a -> EbsSnapshotConfiguration
s {$sel:groups:EbsSnapshotConfiguration' :: Maybe [Text]
groups = Maybe [Text]
a} :: EbsSnapshotConfiguration) 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 KMS key identifier for an encrypted Amazon EBS volume snapshot. The
-- KMS key identifier is the key ARN, key ID, alias ARN, or alias name for
-- the KMS key.
--
-- -   If the configuration is for an existing Amazon EBS volume snapshot
--     and you do not specify the @kmsKeyId@, or you specify an empty
--     string, then the access preview uses the existing @kmsKeyId@ of the
--     snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the @kmsKeyId@, the access preview considers the snapshot as
--     unencrypted.
ebsSnapshotConfiguration_kmsKeyId :: Lens.Lens' EbsSnapshotConfiguration (Prelude.Maybe Prelude.Text)
ebsSnapshotConfiguration_kmsKeyId :: Lens' EbsSnapshotConfiguration (Maybe Text)
ebsSnapshotConfiguration_kmsKeyId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsSnapshotConfiguration' {Maybe Text
kmsKeyId :: Maybe Text
$sel:kmsKeyId:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe Text
kmsKeyId} -> Maybe Text
kmsKeyId) (\s :: EbsSnapshotConfiguration
s@EbsSnapshotConfiguration' {} Maybe Text
a -> EbsSnapshotConfiguration
s {$sel:kmsKeyId:EbsSnapshotConfiguration' :: Maybe Text
kmsKeyId = Maybe Text
a} :: EbsSnapshotConfiguration)

-- | The IDs of the Amazon Web Services accounts that have access to the
-- Amazon EBS volume snapshot.
--
-- -   If the configuration is for an existing Amazon EBS volume snapshot
--     and you do not specify the @userIds@, then the access preview uses
--     the existing shared @userIds@ for the snapshot.
--
-- -   If the access preview is for a new resource and you do not specify
--     the @userIds@, then the access preview considers the snapshot
--     without any @userIds@.
--
-- -   To propose deletion of existing shared @accountIds@, you can specify
--     an empty list for @userIds@.
ebsSnapshotConfiguration_userIds :: Lens.Lens' EbsSnapshotConfiguration (Prelude.Maybe [Prelude.Text])
ebsSnapshotConfiguration_userIds :: Lens' EbsSnapshotConfiguration (Maybe [Text])
ebsSnapshotConfiguration_userIds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\EbsSnapshotConfiguration' {Maybe [Text]
userIds :: Maybe [Text]
$sel:userIds:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
userIds} -> Maybe [Text]
userIds) (\s :: EbsSnapshotConfiguration
s@EbsSnapshotConfiguration' {} Maybe [Text]
a -> EbsSnapshotConfiguration
s {$sel:userIds:EbsSnapshotConfiguration' :: Maybe [Text]
userIds = Maybe [Text]
a} :: EbsSnapshotConfiguration) 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

instance Data.FromJSON EbsSnapshotConfiguration where
  parseJSON :: Value -> Parser EbsSnapshotConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"EbsSnapshotConfiguration"
      ( \Object
x ->
          Maybe [Text]
-> Maybe Text -> Maybe [Text] -> EbsSnapshotConfiguration
EbsSnapshotConfiguration'
            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
"groups" 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
"kmsKeyId")
            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
"userIds" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable EbsSnapshotConfiguration where
  hashWithSalt :: Int -> EbsSnapshotConfiguration -> Int
hashWithSalt Int
_salt EbsSnapshotConfiguration' {Maybe [Text]
Maybe Text
userIds :: Maybe [Text]
kmsKeyId :: Maybe Text
groups :: Maybe [Text]
$sel:userIds:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
$sel:kmsKeyId:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe Text
$sel:groups:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
groups
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
kmsKeyId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
userIds

instance Prelude.NFData EbsSnapshotConfiguration where
  rnf :: EbsSnapshotConfiguration -> ()
rnf EbsSnapshotConfiguration' {Maybe [Text]
Maybe Text
userIds :: Maybe [Text]
kmsKeyId :: Maybe Text
groups :: Maybe [Text]
$sel:userIds:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
$sel:kmsKeyId:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe Text
$sel:groups:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
groups
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
kmsKeyId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
userIds

instance Data.ToJSON EbsSnapshotConfiguration where
  toJSON :: EbsSnapshotConfiguration -> Value
toJSON EbsSnapshotConfiguration' {Maybe [Text]
Maybe Text
userIds :: Maybe [Text]
kmsKeyId :: Maybe Text
groups :: Maybe [Text]
$sel:userIds:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
$sel:kmsKeyId:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe Text
$sel:groups:EbsSnapshotConfiguration' :: EbsSnapshotConfiguration -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"groups" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
groups,
            (Key
"kmsKeyId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
kmsKeyId,
            (Key
"userIds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
userIds
          ]
      )