{-# 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.GuardDuty.Types.Resource
-- 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.GuardDuty.Types.Resource where

import qualified Amazonka.Core as Core
import Amazonka.GuardDuty.Types.AccessKeyDetails
import Amazonka.GuardDuty.Types.InstanceDetails
import Amazonka.GuardDuty.Types.S3BucketDetail
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains information about the AWS resource associated with the activity
-- that prompted GuardDuty to generate a finding.
--
-- /See:/ 'newResource' smart constructor.
data Resource = Resource'
  { -- | The type of AWS resource.
    Resource -> Maybe Text
resourceType :: Prelude.Maybe Prelude.Text,
    -- | Contains information on the S3 bucket.
    Resource -> Maybe [S3BucketDetail]
s3BucketDetails :: Prelude.Maybe [S3BucketDetail],
    -- | The information about the EC2 instance associated with the activity that
    -- prompted GuardDuty to generate a finding.
    Resource -> Maybe InstanceDetails
instanceDetails :: Prelude.Maybe InstanceDetails,
    -- | The IAM access key details (IAM user information) of a user that engaged
    -- in the activity that prompted GuardDuty to generate a finding.
    Resource -> Maybe AccessKeyDetails
accessKeyDetails :: Prelude.Maybe AccessKeyDetails
  }
  deriving (Resource -> Resource -> Bool
(Resource -> Resource -> Bool)
-> (Resource -> Resource -> Bool) -> Eq Resource
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Resource -> Resource -> Bool
$c/= :: Resource -> Resource -> Bool
== :: Resource -> Resource -> Bool
$c== :: Resource -> Resource -> Bool
Prelude.Eq, ReadPrec [Resource]
ReadPrec Resource
Int -> ReadS Resource
ReadS [Resource]
(Int -> ReadS Resource)
-> ReadS [Resource]
-> ReadPrec Resource
-> ReadPrec [Resource]
-> Read Resource
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Resource]
$creadListPrec :: ReadPrec [Resource]
readPrec :: ReadPrec Resource
$creadPrec :: ReadPrec Resource
readList :: ReadS [Resource]
$creadList :: ReadS [Resource]
readsPrec :: Int -> ReadS Resource
$creadsPrec :: Int -> ReadS Resource
Prelude.Read, Int -> Resource -> ShowS
[Resource] -> ShowS
Resource -> String
(Int -> Resource -> ShowS)
-> (Resource -> String) -> ([Resource] -> ShowS) -> Show Resource
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resource] -> ShowS
$cshowList :: [Resource] -> ShowS
show :: Resource -> String
$cshow :: Resource -> String
showsPrec :: Int -> Resource -> ShowS
$cshowsPrec :: Int -> Resource -> ShowS
Prelude.Show, (forall x. Resource -> Rep Resource x)
-> (forall x. Rep Resource x -> Resource) -> Generic Resource
forall x. Rep Resource x -> Resource
forall x. Resource -> Rep Resource x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Resource x -> Resource
$cfrom :: forall x. Resource -> Rep Resource x
Prelude.Generic)

-- |
-- Create a value of 'Resource' 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:
--
-- 'resourceType', 'resource_resourceType' - The type of AWS resource.
--
-- 's3BucketDetails', 'resource_s3BucketDetails' - Contains information on the S3 bucket.
--
-- 'instanceDetails', 'resource_instanceDetails' - The information about the EC2 instance associated with the activity that
-- prompted GuardDuty to generate a finding.
--
-- 'accessKeyDetails', 'resource_accessKeyDetails' - The IAM access key details (IAM user information) of a user that engaged
-- in the activity that prompted GuardDuty to generate a finding.
newResource ::
  Resource
newResource :: Resource
newResource =
  Resource' :: Maybe Text
-> Maybe [S3BucketDetail]
-> Maybe InstanceDetails
-> Maybe AccessKeyDetails
-> Resource
Resource'
    { $sel:resourceType:Resource' :: Maybe Text
resourceType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:s3BucketDetails:Resource' :: Maybe [S3BucketDetail]
s3BucketDetails = Maybe [S3BucketDetail]
forall a. Maybe a
Prelude.Nothing,
      $sel:instanceDetails:Resource' :: Maybe InstanceDetails
instanceDetails = Maybe InstanceDetails
forall a. Maybe a
Prelude.Nothing,
      $sel:accessKeyDetails:Resource' :: Maybe AccessKeyDetails
accessKeyDetails = Maybe AccessKeyDetails
forall a. Maybe a
Prelude.Nothing
    }

-- | The type of AWS resource.
resource_resourceType :: Lens.Lens' Resource (Prelude.Maybe Prelude.Text)
resource_resourceType :: (Maybe Text -> f (Maybe Text)) -> Resource -> f Resource
resource_resourceType = (Resource -> Maybe Text)
-> (Resource -> Maybe Text -> Resource)
-> Lens Resource Resource (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe Text
resourceType :: Maybe Text
$sel:resourceType:Resource' :: Resource -> Maybe Text
resourceType} -> Maybe Text
resourceType) (\s :: Resource
s@Resource' {} Maybe Text
a -> Resource
s {$sel:resourceType:Resource' :: Maybe Text
resourceType = Maybe Text
a} :: Resource)

-- | Contains information on the S3 bucket.
resource_s3BucketDetails :: Lens.Lens' Resource (Prelude.Maybe [S3BucketDetail])
resource_s3BucketDetails :: (Maybe [S3BucketDetail] -> f (Maybe [S3BucketDetail]))
-> Resource -> f Resource
resource_s3BucketDetails = (Resource -> Maybe [S3BucketDetail])
-> (Resource -> Maybe [S3BucketDetail] -> Resource)
-> Lens
     Resource Resource (Maybe [S3BucketDetail]) (Maybe [S3BucketDetail])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe [S3BucketDetail]
s3BucketDetails :: Maybe [S3BucketDetail]
$sel:s3BucketDetails:Resource' :: Resource -> Maybe [S3BucketDetail]
s3BucketDetails} -> Maybe [S3BucketDetail]
s3BucketDetails) (\s :: Resource
s@Resource' {} Maybe [S3BucketDetail]
a -> Resource
s {$sel:s3BucketDetails:Resource' :: Maybe [S3BucketDetail]
s3BucketDetails = Maybe [S3BucketDetail]
a} :: Resource) ((Maybe [S3BucketDetail] -> f (Maybe [S3BucketDetail]))
 -> Resource -> f Resource)
-> ((Maybe [S3BucketDetail] -> f (Maybe [S3BucketDetail]))
    -> Maybe [S3BucketDetail] -> f (Maybe [S3BucketDetail]))
-> (Maybe [S3BucketDetail] -> f (Maybe [S3BucketDetail]))
-> Resource
-> f Resource
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [S3BucketDetail] [S3BucketDetail] [S3BucketDetail] [S3BucketDetail]
-> Iso
     (Maybe [S3BucketDetail])
     (Maybe [S3BucketDetail])
     (Maybe [S3BucketDetail])
     (Maybe [S3BucketDetail])
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
  [S3BucketDetail] [S3BucketDetail] [S3BucketDetail] [S3BucketDetail]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The information about the EC2 instance associated with the activity that
-- prompted GuardDuty to generate a finding.
resource_instanceDetails :: Lens.Lens' Resource (Prelude.Maybe InstanceDetails)
resource_instanceDetails :: (Maybe InstanceDetails -> f (Maybe InstanceDetails))
-> Resource -> f Resource
resource_instanceDetails = (Resource -> Maybe InstanceDetails)
-> (Resource -> Maybe InstanceDetails -> Resource)
-> Lens
     Resource Resource (Maybe InstanceDetails) (Maybe InstanceDetails)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe InstanceDetails
instanceDetails :: Maybe InstanceDetails
$sel:instanceDetails:Resource' :: Resource -> Maybe InstanceDetails
instanceDetails} -> Maybe InstanceDetails
instanceDetails) (\s :: Resource
s@Resource' {} Maybe InstanceDetails
a -> Resource
s {$sel:instanceDetails:Resource' :: Maybe InstanceDetails
instanceDetails = Maybe InstanceDetails
a} :: Resource)

-- | The IAM access key details (IAM user information) of a user that engaged
-- in the activity that prompted GuardDuty to generate a finding.
resource_accessKeyDetails :: Lens.Lens' Resource (Prelude.Maybe AccessKeyDetails)
resource_accessKeyDetails :: (Maybe AccessKeyDetails -> f (Maybe AccessKeyDetails))
-> Resource -> f Resource
resource_accessKeyDetails = (Resource -> Maybe AccessKeyDetails)
-> (Resource -> Maybe AccessKeyDetails -> Resource)
-> Lens
     Resource Resource (Maybe AccessKeyDetails) (Maybe AccessKeyDetails)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Resource' {Maybe AccessKeyDetails
accessKeyDetails :: Maybe AccessKeyDetails
$sel:accessKeyDetails:Resource' :: Resource -> Maybe AccessKeyDetails
accessKeyDetails} -> Maybe AccessKeyDetails
accessKeyDetails) (\s :: Resource
s@Resource' {} Maybe AccessKeyDetails
a -> Resource
s {$sel:accessKeyDetails:Resource' :: Maybe AccessKeyDetails
accessKeyDetails = Maybe AccessKeyDetails
a} :: Resource)

instance Core.FromJSON Resource where
  parseJSON :: Value -> Parser Resource
parseJSON =
    String -> (Object -> Parser Resource) -> Value -> Parser Resource
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Resource"
      ( \Object
x ->
          Maybe Text
-> Maybe [S3BucketDetail]
-> Maybe InstanceDetails
-> Maybe AccessKeyDetails
-> Resource
Resource'
            (Maybe Text
 -> Maybe [S3BucketDetail]
 -> Maybe InstanceDetails
 -> Maybe AccessKeyDetails
 -> Resource)
-> Parser (Maybe Text)
-> Parser
     (Maybe [S3BucketDetail]
      -> Maybe InstanceDetails -> Maybe AccessKeyDetails -> Resource)
forall (f :: * -> *) a b. Functor 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
"resourceType")
            Parser
  (Maybe [S3BucketDetail]
   -> Maybe InstanceDetails -> Maybe AccessKeyDetails -> Resource)
-> Parser (Maybe [S3BucketDetail])
-> Parser
     (Maybe InstanceDetails -> Maybe AccessKeyDetails -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [S3BucketDetail]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"s3BucketDetails"
                            Parser (Maybe (Maybe [S3BucketDetail]))
-> Maybe [S3BucketDetail] -> Parser (Maybe [S3BucketDetail])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [S3BucketDetail]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe InstanceDetails -> Maybe AccessKeyDetails -> Resource)
-> Parser (Maybe InstanceDetails)
-> Parser (Maybe AccessKeyDetails -> Resource)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe InstanceDetails)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"instanceDetails")
            Parser (Maybe AccessKeyDetails -> Resource)
-> Parser (Maybe AccessKeyDetails) -> Parser Resource
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe AccessKeyDetails)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"accessKeyDetails")
      )

instance Prelude.Hashable Resource

instance Prelude.NFData Resource