{-# 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.Greengrass.Types.ResourceAccessPolicy
-- 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.Greengrass.Types.ResourceAccessPolicy where

import qualified Amazonka.Core as Core
import Amazonka.Greengrass.Types.Permission
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A policy used by the function to access a resource.
--
-- /See:/ 'newResourceAccessPolicy' smart constructor.
data ResourceAccessPolicy = ResourceAccessPolicy'
  { -- | The permissions that the Lambda function has to the resource. Can be one
    -- of \'\'rw\'\' (read\/write) or \'\'ro\'\' (read-only).
    ResourceAccessPolicy -> Maybe Permission
permission :: Prelude.Maybe Permission,
    -- | The ID of the resource. (This ID is assigned to the resource when you
    -- create the resource definiton.)
    ResourceAccessPolicy -> Text
resourceId :: Prelude.Text
  }
  deriving (ResourceAccessPolicy -> ResourceAccessPolicy -> Bool
(ResourceAccessPolicy -> ResourceAccessPolicy -> Bool)
-> (ResourceAccessPolicy -> ResourceAccessPolicy -> Bool)
-> Eq ResourceAccessPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceAccessPolicy -> ResourceAccessPolicy -> Bool
$c/= :: ResourceAccessPolicy -> ResourceAccessPolicy -> Bool
== :: ResourceAccessPolicy -> ResourceAccessPolicy -> Bool
$c== :: ResourceAccessPolicy -> ResourceAccessPolicy -> Bool
Prelude.Eq, ReadPrec [ResourceAccessPolicy]
ReadPrec ResourceAccessPolicy
Int -> ReadS ResourceAccessPolicy
ReadS [ResourceAccessPolicy]
(Int -> ReadS ResourceAccessPolicy)
-> ReadS [ResourceAccessPolicy]
-> ReadPrec ResourceAccessPolicy
-> ReadPrec [ResourceAccessPolicy]
-> Read ResourceAccessPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResourceAccessPolicy]
$creadListPrec :: ReadPrec [ResourceAccessPolicy]
readPrec :: ReadPrec ResourceAccessPolicy
$creadPrec :: ReadPrec ResourceAccessPolicy
readList :: ReadS [ResourceAccessPolicy]
$creadList :: ReadS [ResourceAccessPolicy]
readsPrec :: Int -> ReadS ResourceAccessPolicy
$creadsPrec :: Int -> ReadS ResourceAccessPolicy
Prelude.Read, Int -> ResourceAccessPolicy -> ShowS
[ResourceAccessPolicy] -> ShowS
ResourceAccessPolicy -> String
(Int -> ResourceAccessPolicy -> ShowS)
-> (ResourceAccessPolicy -> String)
-> ([ResourceAccessPolicy] -> ShowS)
-> Show ResourceAccessPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceAccessPolicy] -> ShowS
$cshowList :: [ResourceAccessPolicy] -> ShowS
show :: ResourceAccessPolicy -> String
$cshow :: ResourceAccessPolicy -> String
showsPrec :: Int -> ResourceAccessPolicy -> ShowS
$cshowsPrec :: Int -> ResourceAccessPolicy -> ShowS
Prelude.Show, (forall x. ResourceAccessPolicy -> Rep ResourceAccessPolicy x)
-> (forall x. Rep ResourceAccessPolicy x -> ResourceAccessPolicy)
-> Generic ResourceAccessPolicy
forall x. Rep ResourceAccessPolicy x -> ResourceAccessPolicy
forall x. ResourceAccessPolicy -> Rep ResourceAccessPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResourceAccessPolicy x -> ResourceAccessPolicy
$cfrom :: forall x. ResourceAccessPolicy -> Rep ResourceAccessPolicy x
Prelude.Generic)

-- |
-- Create a value of 'ResourceAccessPolicy' 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:
--
-- 'permission', 'resourceAccessPolicy_permission' - The permissions that the Lambda function has to the resource. Can be one
-- of \'\'rw\'\' (read\/write) or \'\'ro\'\' (read-only).
--
-- 'resourceId', 'resourceAccessPolicy_resourceId' - The ID of the resource. (This ID is assigned to the resource when you
-- create the resource definiton.)
newResourceAccessPolicy ::
  -- | 'resourceId'
  Prelude.Text ->
  ResourceAccessPolicy
newResourceAccessPolicy :: Text -> ResourceAccessPolicy
newResourceAccessPolicy Text
pResourceId_ =
  ResourceAccessPolicy' :: Maybe Permission -> Text -> ResourceAccessPolicy
ResourceAccessPolicy'
    { $sel:permission:ResourceAccessPolicy' :: Maybe Permission
permission = Maybe Permission
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceId:ResourceAccessPolicy' :: Text
resourceId = Text
pResourceId_
    }

-- | The permissions that the Lambda function has to the resource. Can be one
-- of \'\'rw\'\' (read\/write) or \'\'ro\'\' (read-only).
resourceAccessPolicy_permission :: Lens.Lens' ResourceAccessPolicy (Prelude.Maybe Permission)
resourceAccessPolicy_permission :: (Maybe Permission -> f (Maybe Permission))
-> ResourceAccessPolicy -> f ResourceAccessPolicy
resourceAccessPolicy_permission = (ResourceAccessPolicy -> Maybe Permission)
-> (ResourceAccessPolicy
    -> Maybe Permission -> ResourceAccessPolicy)
-> Lens
     ResourceAccessPolicy
     ResourceAccessPolicy
     (Maybe Permission)
     (Maybe Permission)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceAccessPolicy' {Maybe Permission
permission :: Maybe Permission
$sel:permission:ResourceAccessPolicy' :: ResourceAccessPolicy -> Maybe Permission
permission} -> Maybe Permission
permission) (\s :: ResourceAccessPolicy
s@ResourceAccessPolicy' {} Maybe Permission
a -> ResourceAccessPolicy
s {$sel:permission:ResourceAccessPolicy' :: Maybe Permission
permission = Maybe Permission
a} :: ResourceAccessPolicy)

-- | The ID of the resource. (This ID is assigned to the resource when you
-- create the resource definiton.)
resourceAccessPolicy_resourceId :: Lens.Lens' ResourceAccessPolicy Prelude.Text
resourceAccessPolicy_resourceId :: (Text -> f Text) -> ResourceAccessPolicy -> f ResourceAccessPolicy
resourceAccessPolicy_resourceId = (ResourceAccessPolicy -> Text)
-> (ResourceAccessPolicy -> Text -> ResourceAccessPolicy)
-> Lens ResourceAccessPolicy ResourceAccessPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResourceAccessPolicy' {Text
resourceId :: Text
$sel:resourceId:ResourceAccessPolicy' :: ResourceAccessPolicy -> Text
resourceId} -> Text
resourceId) (\s :: ResourceAccessPolicy
s@ResourceAccessPolicy' {} Text
a -> ResourceAccessPolicy
s {$sel:resourceId:ResourceAccessPolicy' :: Text
resourceId = Text
a} :: ResourceAccessPolicy)

instance Core.FromJSON ResourceAccessPolicy where
  parseJSON :: Value -> Parser ResourceAccessPolicy
parseJSON =
    String
-> (Object -> Parser ResourceAccessPolicy)
-> Value
-> Parser ResourceAccessPolicy
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ResourceAccessPolicy"
      ( \Object
x ->
          Maybe Permission -> Text -> ResourceAccessPolicy
ResourceAccessPolicy'
            (Maybe Permission -> Text -> ResourceAccessPolicy)
-> Parser (Maybe Permission)
-> Parser (Text -> ResourceAccessPolicy)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Permission)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Permission")
            Parser (Text -> ResourceAccessPolicy)
-> Parser Text -> Parser ResourceAccessPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ResourceId")
      )

instance Prelude.Hashable ResourceAccessPolicy

instance Prelude.NFData ResourceAccessPolicy

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