{-# 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.ImageBuilder.Types.LaunchPermissionConfiguration
-- 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.ImageBuilder.Types.LaunchPermissionConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Describes the configuration for a launch permission. The launch
-- permission modification request is sent to the
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyImageAttribute.html Amazon EC2 ModifyImageAttribute>
-- API on behalf of the user for each Region they have selected to
-- distribute the AMI. To make an AMI public, set the launch permission
-- authorized accounts to @all@. See the examples for making an AMI public
-- at
-- <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyImageAttribute.html Amazon EC2 ModifyImageAttribute>.
--
-- /See:/ 'newLaunchPermissionConfiguration' smart constructor.
data LaunchPermissionConfiguration = LaunchPermissionConfiguration'
  { -- | The Amazon Web Services account ID.
    LaunchPermissionConfiguration -> Maybe (NonEmpty Text)
userIds :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | The name of the group.
    LaunchPermissionConfiguration -> Maybe [Text]
userGroups :: Prelude.Maybe [Prelude.Text]
  }
  deriving (LaunchPermissionConfiguration
-> LaunchPermissionConfiguration -> Bool
(LaunchPermissionConfiguration
 -> LaunchPermissionConfiguration -> Bool)
-> (LaunchPermissionConfiguration
    -> LaunchPermissionConfiguration -> Bool)
-> Eq LaunchPermissionConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LaunchPermissionConfiguration
-> LaunchPermissionConfiguration -> Bool
$c/= :: LaunchPermissionConfiguration
-> LaunchPermissionConfiguration -> Bool
== :: LaunchPermissionConfiguration
-> LaunchPermissionConfiguration -> Bool
$c== :: LaunchPermissionConfiguration
-> LaunchPermissionConfiguration -> Bool
Prelude.Eq, ReadPrec [LaunchPermissionConfiguration]
ReadPrec LaunchPermissionConfiguration
Int -> ReadS LaunchPermissionConfiguration
ReadS [LaunchPermissionConfiguration]
(Int -> ReadS LaunchPermissionConfiguration)
-> ReadS [LaunchPermissionConfiguration]
-> ReadPrec LaunchPermissionConfiguration
-> ReadPrec [LaunchPermissionConfiguration]
-> Read LaunchPermissionConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LaunchPermissionConfiguration]
$creadListPrec :: ReadPrec [LaunchPermissionConfiguration]
readPrec :: ReadPrec LaunchPermissionConfiguration
$creadPrec :: ReadPrec LaunchPermissionConfiguration
readList :: ReadS [LaunchPermissionConfiguration]
$creadList :: ReadS [LaunchPermissionConfiguration]
readsPrec :: Int -> ReadS LaunchPermissionConfiguration
$creadsPrec :: Int -> ReadS LaunchPermissionConfiguration
Prelude.Read, Int -> LaunchPermissionConfiguration -> ShowS
[LaunchPermissionConfiguration] -> ShowS
LaunchPermissionConfiguration -> String
(Int -> LaunchPermissionConfiguration -> ShowS)
-> (LaunchPermissionConfiguration -> String)
-> ([LaunchPermissionConfiguration] -> ShowS)
-> Show LaunchPermissionConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LaunchPermissionConfiguration] -> ShowS
$cshowList :: [LaunchPermissionConfiguration] -> ShowS
show :: LaunchPermissionConfiguration -> String
$cshow :: LaunchPermissionConfiguration -> String
showsPrec :: Int -> LaunchPermissionConfiguration -> ShowS
$cshowsPrec :: Int -> LaunchPermissionConfiguration -> ShowS
Prelude.Show, (forall x.
 LaunchPermissionConfiguration
 -> Rep LaunchPermissionConfiguration x)
-> (forall x.
    Rep LaunchPermissionConfiguration x
    -> LaunchPermissionConfiguration)
-> Generic LaunchPermissionConfiguration
forall x.
Rep LaunchPermissionConfiguration x
-> LaunchPermissionConfiguration
forall x.
LaunchPermissionConfiguration
-> Rep LaunchPermissionConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep LaunchPermissionConfiguration x
-> LaunchPermissionConfiguration
$cfrom :: forall x.
LaunchPermissionConfiguration
-> Rep LaunchPermissionConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'LaunchPermissionConfiguration' 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:
--
-- 'userIds', 'launchPermissionConfiguration_userIds' - The Amazon Web Services account ID.
--
-- 'userGroups', 'launchPermissionConfiguration_userGroups' - The name of the group.
newLaunchPermissionConfiguration ::
  LaunchPermissionConfiguration
newLaunchPermissionConfiguration :: LaunchPermissionConfiguration
newLaunchPermissionConfiguration =
  LaunchPermissionConfiguration' :: Maybe (NonEmpty Text)
-> Maybe [Text] -> LaunchPermissionConfiguration
LaunchPermissionConfiguration'
    { $sel:userIds:LaunchPermissionConfiguration' :: Maybe (NonEmpty Text)
userIds =
        Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:userGroups:LaunchPermissionConfiguration' :: Maybe [Text]
userGroups = Maybe [Text]
forall a. Maybe a
Prelude.Nothing
    }

-- | The Amazon Web Services account ID.
launchPermissionConfiguration_userIds :: Lens.Lens' LaunchPermissionConfiguration (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
launchPermissionConfiguration_userIds :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> LaunchPermissionConfiguration -> f LaunchPermissionConfiguration
launchPermissionConfiguration_userIds = (LaunchPermissionConfiguration -> Maybe (NonEmpty Text))
-> (LaunchPermissionConfiguration
    -> Maybe (NonEmpty Text) -> LaunchPermissionConfiguration)
-> Lens
     LaunchPermissionConfiguration
     LaunchPermissionConfiguration
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchPermissionConfiguration' {Maybe (NonEmpty Text)
userIds :: Maybe (NonEmpty Text)
$sel:userIds:LaunchPermissionConfiguration' :: LaunchPermissionConfiguration -> Maybe (NonEmpty Text)
userIds} -> Maybe (NonEmpty Text)
userIds) (\s :: LaunchPermissionConfiguration
s@LaunchPermissionConfiguration' {} Maybe (NonEmpty Text)
a -> LaunchPermissionConfiguration
s {$sel:userIds:LaunchPermissionConfiguration' :: Maybe (NonEmpty Text)
userIds = Maybe (NonEmpty Text)
a} :: LaunchPermissionConfiguration) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> LaunchPermissionConfiguration
 -> f LaunchPermissionConfiguration)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> LaunchPermissionConfiguration
-> f LaunchPermissionConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
-> Iso
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty 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
  (NonEmpty Text) (NonEmpty Text) (NonEmpty Text) (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the group.
launchPermissionConfiguration_userGroups :: Lens.Lens' LaunchPermissionConfiguration (Prelude.Maybe [Prelude.Text])
launchPermissionConfiguration_userGroups :: (Maybe [Text] -> f (Maybe [Text]))
-> LaunchPermissionConfiguration -> f LaunchPermissionConfiguration
launchPermissionConfiguration_userGroups = (LaunchPermissionConfiguration -> Maybe [Text])
-> (LaunchPermissionConfiguration
    -> Maybe [Text] -> LaunchPermissionConfiguration)
-> Lens
     LaunchPermissionConfiguration
     LaunchPermissionConfiguration
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LaunchPermissionConfiguration' {Maybe [Text]
userGroups :: Maybe [Text]
$sel:userGroups:LaunchPermissionConfiguration' :: LaunchPermissionConfiguration -> Maybe [Text]
userGroups} -> Maybe [Text]
userGroups) (\s :: LaunchPermissionConfiguration
s@LaunchPermissionConfiguration' {} Maybe [Text]
a -> LaunchPermissionConfiguration
s {$sel:userGroups:LaunchPermissionConfiguration' :: Maybe [Text]
userGroups = Maybe [Text]
a} :: LaunchPermissionConfiguration) ((Maybe [Text] -> f (Maybe [Text]))
 -> LaunchPermissionConfiguration
 -> f LaunchPermissionConfiguration)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> LaunchPermissionConfiguration
-> f LaunchPermissionConfiguration
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON LaunchPermissionConfiguration where
  parseJSON :: Value -> Parser LaunchPermissionConfiguration
parseJSON =
    String
-> (Object -> Parser LaunchPermissionConfiguration)
-> Value
-> Parser LaunchPermissionConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"LaunchPermissionConfiguration"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe [Text] -> LaunchPermissionConfiguration
LaunchPermissionConfiguration'
            (Maybe (NonEmpty Text)
 -> Maybe [Text] -> LaunchPermissionConfiguration)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Maybe [Text] -> LaunchPermissionConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (NonEmpty Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"userIds")
            Parser (Maybe [Text] -> LaunchPermissionConfiguration)
-> Parser (Maybe [Text]) -> Parser LaunchPermissionConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [Text]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"userGroups" Parser (Maybe (Maybe [Text]))
-> Maybe [Text] -> Parser (Maybe [Text])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Text]
forall a. Monoid a => a
Prelude.mempty)
      )

instance
  Prelude.Hashable
    LaunchPermissionConfiguration

instance Prelude.NFData LaunchPermissionConfiguration

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