{-# 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.ColumnLevelPermissionRule
-- 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.ColumnLevelPermissionRule where

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

-- | A rule defined to grant access on one or more restricted columns. Each
-- dataset can have multiple rules. To create a restricted column, you add
-- it to one or more rules. Each rule must contain at least one column and
-- at least one user or group. To be able to see a restricted column, a
-- user or group needs to be added to a rule for that column.
--
-- /See:/ 'newColumnLevelPermissionRule' smart constructor.
data ColumnLevelPermissionRule = ColumnLevelPermissionRule'
  { -- | An array of Amazon Resource Names (ARNs) for Amazon QuickSight users or
    -- groups.
    ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
principals :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | An array of column names.
    ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
columnNames :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
(ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool)
-> (ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool)
-> Eq ColumnLevelPermissionRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
$c/= :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
== :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
$c== :: ColumnLevelPermissionRule -> ColumnLevelPermissionRule -> Bool
Prelude.Eq, ReadPrec [ColumnLevelPermissionRule]
ReadPrec ColumnLevelPermissionRule
Int -> ReadS ColumnLevelPermissionRule
ReadS [ColumnLevelPermissionRule]
(Int -> ReadS ColumnLevelPermissionRule)
-> ReadS [ColumnLevelPermissionRule]
-> ReadPrec ColumnLevelPermissionRule
-> ReadPrec [ColumnLevelPermissionRule]
-> Read ColumnLevelPermissionRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ColumnLevelPermissionRule]
$creadListPrec :: ReadPrec [ColumnLevelPermissionRule]
readPrec :: ReadPrec ColumnLevelPermissionRule
$creadPrec :: ReadPrec ColumnLevelPermissionRule
readList :: ReadS [ColumnLevelPermissionRule]
$creadList :: ReadS [ColumnLevelPermissionRule]
readsPrec :: Int -> ReadS ColumnLevelPermissionRule
$creadsPrec :: Int -> ReadS ColumnLevelPermissionRule
Prelude.Read, Int -> ColumnLevelPermissionRule -> ShowS
[ColumnLevelPermissionRule] -> ShowS
ColumnLevelPermissionRule -> String
(Int -> ColumnLevelPermissionRule -> ShowS)
-> (ColumnLevelPermissionRule -> String)
-> ([ColumnLevelPermissionRule] -> ShowS)
-> Show ColumnLevelPermissionRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColumnLevelPermissionRule] -> ShowS
$cshowList :: [ColumnLevelPermissionRule] -> ShowS
show :: ColumnLevelPermissionRule -> String
$cshow :: ColumnLevelPermissionRule -> String
showsPrec :: Int -> ColumnLevelPermissionRule -> ShowS
$cshowsPrec :: Int -> ColumnLevelPermissionRule -> ShowS
Prelude.Show, (forall x.
 ColumnLevelPermissionRule -> Rep ColumnLevelPermissionRule x)
-> (forall x.
    Rep ColumnLevelPermissionRule x -> ColumnLevelPermissionRule)
-> Generic ColumnLevelPermissionRule
forall x.
Rep ColumnLevelPermissionRule x -> ColumnLevelPermissionRule
forall x.
ColumnLevelPermissionRule -> Rep ColumnLevelPermissionRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ColumnLevelPermissionRule x -> ColumnLevelPermissionRule
$cfrom :: forall x.
ColumnLevelPermissionRule -> Rep ColumnLevelPermissionRule x
Prelude.Generic)

-- |
-- Create a value of 'ColumnLevelPermissionRule' 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:
--
-- 'principals', 'columnLevelPermissionRule_principals' - An array of Amazon Resource Names (ARNs) for Amazon QuickSight users or
-- groups.
--
-- 'columnNames', 'columnLevelPermissionRule_columnNames' - An array of column names.
newColumnLevelPermissionRule ::
  ColumnLevelPermissionRule
newColumnLevelPermissionRule :: ColumnLevelPermissionRule
newColumnLevelPermissionRule =
  ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text) -> ColumnLevelPermissionRule
ColumnLevelPermissionRule'
    { $sel:principals:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
principals =
        Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:columnNames:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
columnNames = Maybe (NonEmpty Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | An array of Amazon Resource Names (ARNs) for Amazon QuickSight users or
-- groups.
columnLevelPermissionRule_principals :: Lens.Lens' ColumnLevelPermissionRule (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
columnLevelPermissionRule_principals :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ColumnLevelPermissionRule -> f ColumnLevelPermissionRule
columnLevelPermissionRule_principals = (ColumnLevelPermissionRule -> Maybe (NonEmpty Text))
-> (ColumnLevelPermissionRule
    -> Maybe (NonEmpty Text) -> ColumnLevelPermissionRule)
-> Lens
     ColumnLevelPermissionRule
     ColumnLevelPermissionRule
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
principals :: Maybe (NonEmpty Text)
$sel:principals:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
principals} -> Maybe (NonEmpty Text)
principals) (\s :: ColumnLevelPermissionRule
s@ColumnLevelPermissionRule' {} Maybe (NonEmpty Text)
a -> ColumnLevelPermissionRule
s {$sel:principals:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
principals = Maybe (NonEmpty Text)
a} :: ColumnLevelPermissionRule) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> ColumnLevelPermissionRule -> f ColumnLevelPermissionRule)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ColumnLevelPermissionRule
-> f ColumnLevelPermissionRule
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

-- | An array of column names.
columnLevelPermissionRule_columnNames :: Lens.Lens' ColumnLevelPermissionRule (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
columnLevelPermissionRule_columnNames :: (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ColumnLevelPermissionRule -> f ColumnLevelPermissionRule
columnLevelPermissionRule_columnNames = (ColumnLevelPermissionRule -> Maybe (NonEmpty Text))
-> (ColumnLevelPermissionRule
    -> Maybe (NonEmpty Text) -> ColumnLevelPermissionRule)
-> Lens
     ColumnLevelPermissionRule
     ColumnLevelPermissionRule
     (Maybe (NonEmpty Text))
     (Maybe (NonEmpty Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
columnNames :: Maybe (NonEmpty Text)
$sel:columnNames:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
columnNames} -> Maybe (NonEmpty Text)
columnNames) (\s :: ColumnLevelPermissionRule
s@ColumnLevelPermissionRule' {} Maybe (NonEmpty Text)
a -> ColumnLevelPermissionRule
s {$sel:columnNames:ColumnLevelPermissionRule' :: Maybe (NonEmpty Text)
columnNames = Maybe (NonEmpty Text)
a} :: ColumnLevelPermissionRule) ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
 -> ColumnLevelPermissionRule -> f ColumnLevelPermissionRule)
-> ((Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
    -> Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> (Maybe (NonEmpty Text) -> f (Maybe (NonEmpty Text)))
-> ColumnLevelPermissionRule
-> f ColumnLevelPermissionRule
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

instance Core.FromJSON ColumnLevelPermissionRule where
  parseJSON :: Value -> Parser ColumnLevelPermissionRule
parseJSON =
    String
-> (Object -> Parser ColumnLevelPermissionRule)
-> Value
-> Parser ColumnLevelPermissionRule
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ColumnLevelPermissionRule"
      ( \Object
x ->
          Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text) -> ColumnLevelPermissionRule
ColumnLevelPermissionRule'
            (Maybe (NonEmpty Text)
 -> Maybe (NonEmpty Text) -> ColumnLevelPermissionRule)
-> Parser (Maybe (NonEmpty Text))
-> Parser (Maybe (NonEmpty Text) -> ColumnLevelPermissionRule)
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
"Principals")
            Parser (Maybe (NonEmpty Text) -> ColumnLevelPermissionRule)
-> Parser (Maybe (NonEmpty Text))
-> Parser ColumnLevelPermissionRule
forall (f :: * -> *) a b. Applicative f => 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
"ColumnNames")
      )

instance Prelude.Hashable ColumnLevelPermissionRule

instance Prelude.NFData ColumnLevelPermissionRule

instance Core.ToJSON ColumnLevelPermissionRule where
  toJSON :: ColumnLevelPermissionRule -> Value
toJSON ColumnLevelPermissionRule' {Maybe (NonEmpty Text)
columnNames :: Maybe (NonEmpty Text)
principals :: Maybe (NonEmpty Text)
$sel:columnNames:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
$sel:principals:ColumnLevelPermissionRule' :: ColumnLevelPermissionRule -> Maybe (NonEmpty Text)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Principals" 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)
principals,
            (Text
"ColumnNames" 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)
columnNames
          ]
      )