{-# 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.QuickSight.Types.ResourcePermission
-- 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.QuickSight.Types.ResourcePermission where

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

-- | Permission for the resource.
--
-- /See:/ 'newResourcePermission' smart constructor.
data ResourcePermission = ResourcePermission'
  { -- | The Amazon Resource Name (ARN) of the principal. This can be one of the
    -- following:
    --
    -- -   The ARN of an Amazon QuickSight user or group associated with a data
    --     source or dataset. (This is common.)
    --
    -- -   The ARN of an Amazon QuickSight user, group, or namespace associated
    --     with an analysis, dashboard, template, or theme. (This is common.)
    --
    -- -   The ARN of an Amazon Web Services account root: This is an IAMARN
    --     rather than a Amazon QuickSight ARN. Use this option only to share
    --     resources (templates) across Amazon Web Services accounts. (This is
    --     less common.)
    ResourcePermission -> Text
principal :: Prelude.Text,
    -- | The IAMaction to grant or revoke permissions on.
    ResourcePermission -> NonEmpty Text
actions :: Prelude.NonEmpty Prelude.Text
  }
  deriving (ResourcePermission -> ResourcePermission -> Bool
(ResourcePermission -> ResourcePermission -> Bool)
-> (ResourcePermission -> ResourcePermission -> Bool)
-> Eq ResourcePermission
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourcePermission -> ResourcePermission -> Bool
$c/= :: ResourcePermission -> ResourcePermission -> Bool
== :: ResourcePermission -> ResourcePermission -> Bool
$c== :: ResourcePermission -> ResourcePermission -> Bool
Prelude.Eq, ReadPrec [ResourcePermission]
ReadPrec ResourcePermission
Int -> ReadS ResourcePermission
ReadS [ResourcePermission]
(Int -> ReadS ResourcePermission)
-> ReadS [ResourcePermission]
-> ReadPrec ResourcePermission
-> ReadPrec [ResourcePermission]
-> Read ResourcePermission
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourcePermission]
$creadListPrec :: ReadPrec [ResourcePermission]
readPrec :: ReadPrec ResourcePermission
$creadPrec :: ReadPrec ResourcePermission
readList :: ReadS [ResourcePermission]
$creadList :: ReadS [ResourcePermission]
readsPrec :: Int -> ReadS ResourcePermission
$creadsPrec :: Int -> ReadS ResourcePermission
Prelude.Read, Int -> ResourcePermission -> ShowS
[ResourcePermission] -> ShowS
ResourcePermission -> String
(Int -> ResourcePermission -> ShowS)
-> (ResourcePermission -> String)
-> ([ResourcePermission] -> ShowS)
-> Show ResourcePermission
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourcePermission] -> ShowS
$cshowList :: [ResourcePermission] -> ShowS
show :: ResourcePermission -> String
$cshow :: ResourcePermission -> String
showsPrec :: Int -> ResourcePermission -> ShowS
$cshowsPrec :: Int -> ResourcePermission -> ShowS
Prelude.Show, (forall x. ResourcePermission -> Rep ResourcePermission x)
-> (forall x. Rep ResourcePermission x -> ResourcePermission)
-> Generic ResourcePermission
forall x. Rep ResourcePermission x -> ResourcePermission
forall x. ResourcePermission -> Rep ResourcePermission x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourcePermission x -> ResourcePermission
$cfrom :: forall x. ResourcePermission -> Rep ResourcePermission x
Prelude.Generic)

-- |
-- Create a value of 'ResourcePermission' 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:
--
-- 'principal', 'resourcePermission_principal' - The Amazon Resource Name (ARN) of the principal. This can be one of the
-- following:
--
-- -   The ARN of an Amazon QuickSight user or group associated with a data
--     source or dataset. (This is common.)
--
-- -   The ARN of an Amazon QuickSight user, group, or namespace associated
--     with an analysis, dashboard, template, or theme. (This is common.)
--
-- -   The ARN of an Amazon Web Services account root: This is an IAMARN
--     rather than a Amazon QuickSight ARN. Use this option only to share
--     resources (templates) across Amazon Web Services accounts. (This is
--     less common.)
--
-- 'actions', 'resourcePermission_actions' - The IAMaction to grant or revoke permissions on.
newResourcePermission ::
  -- | 'principal'
  Prelude.Text ->
  -- | 'actions'
  Prelude.NonEmpty Prelude.Text ->
  ResourcePermission
newResourcePermission :: Text -> NonEmpty Text -> ResourcePermission
newResourcePermission Text
pPrincipal_ NonEmpty Text
pActions_ =
  ResourcePermission' :: Text -> NonEmpty Text -> ResourcePermission
ResourcePermission'
    { $sel:principal:ResourcePermission' :: Text
principal = Text
pPrincipal_,
      $sel:actions:ResourcePermission' :: NonEmpty Text
actions = Tagged (NonEmpty Text) (Identity (NonEmpty Text))
-> Tagged (NonEmpty Text) (Identity (NonEmpty Text))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Text) (Identity (NonEmpty Text))
 -> Tagged (NonEmpty Text) (Identity (NonEmpty Text)))
-> NonEmpty Text -> NonEmpty Text
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Text
pActions_
    }

-- | The Amazon Resource Name (ARN) of the principal. This can be one of the
-- following:
--
-- -   The ARN of an Amazon QuickSight user or group associated with a data
--     source or dataset. (This is common.)
--
-- -   The ARN of an Amazon QuickSight user, group, or namespace associated
--     with an analysis, dashboard, template, or theme. (This is common.)
--
-- -   The ARN of an Amazon Web Services account root: This is an IAMARN
--     rather than a Amazon QuickSight ARN. Use this option only to share
--     resources (templates) across Amazon Web Services accounts. (This is
--     less common.)
resourcePermission_principal :: Lens.Lens' ResourcePermission Prelude.Text
resourcePermission_principal :: (Text -> f Text) -> ResourcePermission -> f ResourcePermission
resourcePermission_principal = (ResourcePermission -> Text)
-> (ResourcePermission -> Text -> ResourcePermission)
-> Lens ResourcePermission ResourcePermission Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePermission' {Text
principal :: Text
$sel:principal:ResourcePermission' :: ResourcePermission -> Text
principal} -> Text
principal) (\s :: ResourcePermission
s@ResourcePermission' {} Text
a -> ResourcePermission
s {$sel:principal:ResourcePermission' :: Text
principal = Text
a} :: ResourcePermission)

-- | The IAMaction to grant or revoke permissions on.
resourcePermission_actions :: Lens.Lens' ResourcePermission (Prelude.NonEmpty Prelude.Text)
resourcePermission_actions :: (NonEmpty Text -> f (NonEmpty Text))
-> ResourcePermission -> f ResourcePermission
resourcePermission_actions = (ResourcePermission -> NonEmpty Text)
-> (ResourcePermission -> NonEmpty Text -> ResourcePermission)
-> Lens
     ResourcePermission
     ResourcePermission
     (NonEmpty Text)
     (NonEmpty Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourcePermission' {NonEmpty Text
actions :: NonEmpty Text
$sel:actions:ResourcePermission' :: ResourcePermission -> NonEmpty Text
actions} -> NonEmpty Text
actions) (\s :: ResourcePermission
s@ResourcePermission' {} NonEmpty Text
a -> ResourcePermission
s {$sel:actions:ResourcePermission' :: NonEmpty Text
actions = NonEmpty Text
a} :: ResourcePermission) ((NonEmpty Text -> f (NonEmpty Text))
 -> ResourcePermission -> f ResourcePermission)
-> ((NonEmpty Text -> f (NonEmpty Text))
    -> NonEmpty Text -> f (NonEmpty Text))
-> (NonEmpty Text -> f (NonEmpty Text))
-> ResourcePermission
-> f ResourcePermission
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Text -> f (NonEmpty Text))
-> NonEmpty Text -> f (NonEmpty Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON ResourcePermission where
  parseJSON :: Value -> Parser ResourcePermission
parseJSON =
    String
-> (Object -> Parser ResourcePermission)
-> Value
-> Parser ResourcePermission
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourcePermission"
      ( \Object
x ->
          Text -> NonEmpty Text -> ResourcePermission
ResourcePermission'
            (Text -> NonEmpty Text -> ResourcePermission)
-> Parser Text -> Parser (NonEmpty Text -> ResourcePermission)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Principal")
            Parser (NonEmpty Text -> ResourcePermission)
-> Parser (NonEmpty Text) -> Parser ResourcePermission
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty Text)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Actions")
      )

instance Prelude.Hashable ResourcePermission

instance Prelude.NFData ResourcePermission

instance Core.ToJSON ResourcePermission where
  toJSON :: ResourcePermission -> Value
toJSON ResourcePermission' {NonEmpty Text
Text
actions :: NonEmpty Text
principal :: Text
$sel:actions:ResourcePermission' :: ResourcePermission -> NonEmpty Text
$sel:principal:ResourcePermission' :: ResourcePermission -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Principal" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
principal),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Actions" Text -> NonEmpty Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Text
actions)
          ]
      )