{-# 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.IoT.Types.AuthInfo
-- 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.IoT.Types.AuthInfo where

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.ActionType
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A collection of authorization information.
--
-- /See:/ 'newAuthInfo' smart constructor.
data AuthInfo = AuthInfo'
  { -- | The type of action for which the principal is being authorized.
    AuthInfo -> Maybe ActionType
actionType :: Prelude.Maybe ActionType,
    -- | The resources for which the principal is being authorized to perform the
    -- specified action.
    AuthInfo -> [Text]
resources :: [Prelude.Text]
  }
  deriving (AuthInfo -> AuthInfo -> Bool
(AuthInfo -> AuthInfo -> Bool)
-> (AuthInfo -> AuthInfo -> Bool) -> Eq AuthInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AuthInfo -> AuthInfo -> Bool
$c/= :: AuthInfo -> AuthInfo -> Bool
== :: AuthInfo -> AuthInfo -> Bool
$c== :: AuthInfo -> AuthInfo -> Bool
Prelude.Eq, ReadPrec [AuthInfo]
ReadPrec AuthInfo
Int -> ReadS AuthInfo
ReadS [AuthInfo]
(Int -> ReadS AuthInfo)
-> ReadS [AuthInfo]
-> ReadPrec AuthInfo
-> ReadPrec [AuthInfo]
-> Read AuthInfo
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AuthInfo]
$creadListPrec :: ReadPrec [AuthInfo]
readPrec :: ReadPrec AuthInfo
$creadPrec :: ReadPrec AuthInfo
readList :: ReadS [AuthInfo]
$creadList :: ReadS [AuthInfo]
readsPrec :: Int -> ReadS AuthInfo
$creadsPrec :: Int -> ReadS AuthInfo
Prelude.Read, Int -> AuthInfo -> ShowS
[AuthInfo] -> ShowS
AuthInfo -> String
(Int -> AuthInfo -> ShowS)
-> (AuthInfo -> String) -> ([AuthInfo] -> ShowS) -> Show AuthInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AuthInfo] -> ShowS
$cshowList :: [AuthInfo] -> ShowS
show :: AuthInfo -> String
$cshow :: AuthInfo -> String
showsPrec :: Int -> AuthInfo -> ShowS
$cshowsPrec :: Int -> AuthInfo -> ShowS
Prelude.Show, (forall x. AuthInfo -> Rep AuthInfo x)
-> (forall x. Rep AuthInfo x -> AuthInfo) -> Generic AuthInfo
forall x. Rep AuthInfo x -> AuthInfo
forall x. AuthInfo -> Rep AuthInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AuthInfo x -> AuthInfo
$cfrom :: forall x. AuthInfo -> Rep AuthInfo x
Prelude.Generic)

-- |
-- Create a value of 'AuthInfo' 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:
--
-- 'actionType', 'authInfo_actionType' - The type of action for which the principal is being authorized.
--
-- 'resources', 'authInfo_resources' - The resources for which the principal is being authorized to perform the
-- specified action.
newAuthInfo ::
  AuthInfo
newAuthInfo :: AuthInfo
newAuthInfo =
  AuthInfo' :: Maybe ActionType -> [Text] -> AuthInfo
AuthInfo'
    { $sel:actionType:AuthInfo' :: Maybe ActionType
actionType = Maybe ActionType
forall a. Maybe a
Prelude.Nothing,
      $sel:resources:AuthInfo' :: [Text]
resources = [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | The type of action for which the principal is being authorized.
authInfo_actionType :: Lens.Lens' AuthInfo (Prelude.Maybe ActionType)
authInfo_actionType :: (Maybe ActionType -> f (Maybe ActionType))
-> AuthInfo -> f AuthInfo
authInfo_actionType = (AuthInfo -> Maybe ActionType)
-> (AuthInfo -> Maybe ActionType -> AuthInfo)
-> Lens AuthInfo AuthInfo (Maybe ActionType) (Maybe ActionType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthInfo' {Maybe ActionType
actionType :: Maybe ActionType
$sel:actionType:AuthInfo' :: AuthInfo -> Maybe ActionType
actionType} -> Maybe ActionType
actionType) (\s :: AuthInfo
s@AuthInfo' {} Maybe ActionType
a -> AuthInfo
s {$sel:actionType:AuthInfo' :: Maybe ActionType
actionType = Maybe ActionType
a} :: AuthInfo)

-- | The resources for which the principal is being authorized to perform the
-- specified action.
authInfo_resources :: Lens.Lens' AuthInfo [Prelude.Text]
authInfo_resources :: ([Text] -> f [Text]) -> AuthInfo -> f AuthInfo
authInfo_resources = (AuthInfo -> [Text])
-> (AuthInfo -> [Text] -> AuthInfo)
-> Lens AuthInfo AuthInfo [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AuthInfo' {[Text]
resources :: [Text]
$sel:resources:AuthInfo' :: AuthInfo -> [Text]
resources} -> [Text]
resources) (\s :: AuthInfo
s@AuthInfo' {} [Text]
a -> AuthInfo
s {$sel:resources:AuthInfo' :: [Text]
resources = [Text]
a} :: AuthInfo) (([Text] -> f [Text]) -> AuthInfo -> f AuthInfo)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> AuthInfo
-> f AuthInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable AuthInfo

instance Prelude.NFData AuthInfo

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