{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SecurityHub.CreateInsight
-- 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)
--
-- Creates a custom insight in Security Hub. An insight is a consolidation
-- of findings that relate to a security issue that requires attention or
-- remediation.
--
-- To group the related findings in the insight, use the
-- @GroupByAttribute@.
module Amazonka.SecurityHub.CreateInsight
  ( -- * Creating a Request
    CreateInsight (..),
    newCreateInsight,

    -- * Request Lenses
    createInsight_name,
    createInsight_filters,
    createInsight_groupByAttribute,

    -- * Destructuring the Response
    CreateInsightResponse (..),
    newCreateInsightResponse,

    -- * Response Lenses
    createInsightResponse_httpStatus,
    createInsightResponse_insightArn,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response
import Amazonka.SecurityHub.Types

-- | /See:/ 'newCreateInsight' smart constructor.
data CreateInsight = CreateInsight'
  { -- | The name of the custom insight to create.
    CreateInsight -> Text
name :: Prelude.Text,
    -- | One or more attributes used to filter the findings included in the
    -- insight. The insight only includes findings that match the criteria
    -- defined in the filters.
    CreateInsight -> AwsSecurityFindingFilters
filters :: AwsSecurityFindingFilters,
    -- | The attribute used to group the findings for the insight. The grouping
    -- attribute identifies the type of item that the insight applies to. For
    -- example, if an insight is grouped by resource identifier, then the
    -- insight produces a list of resource identifiers.
    CreateInsight -> Text
groupByAttribute :: Prelude.Text
  }
  deriving (CreateInsight -> CreateInsight -> Bool
(CreateInsight -> CreateInsight -> Bool)
-> (CreateInsight -> CreateInsight -> Bool) -> Eq CreateInsight
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateInsight -> CreateInsight -> Bool
$c/= :: CreateInsight -> CreateInsight -> Bool
== :: CreateInsight -> CreateInsight -> Bool
$c== :: CreateInsight -> CreateInsight -> Bool
Prelude.Eq, ReadPrec [CreateInsight]
ReadPrec CreateInsight
Int -> ReadS CreateInsight
ReadS [CreateInsight]
(Int -> ReadS CreateInsight)
-> ReadS [CreateInsight]
-> ReadPrec CreateInsight
-> ReadPrec [CreateInsight]
-> Read CreateInsight
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateInsight]
$creadListPrec :: ReadPrec [CreateInsight]
readPrec :: ReadPrec CreateInsight
$creadPrec :: ReadPrec CreateInsight
readList :: ReadS [CreateInsight]
$creadList :: ReadS [CreateInsight]
readsPrec :: Int -> ReadS CreateInsight
$creadsPrec :: Int -> ReadS CreateInsight
Prelude.Read, Int -> CreateInsight -> ShowS
[CreateInsight] -> ShowS
CreateInsight -> String
(Int -> CreateInsight -> ShowS)
-> (CreateInsight -> String)
-> ([CreateInsight] -> ShowS)
-> Show CreateInsight
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateInsight] -> ShowS
$cshowList :: [CreateInsight] -> ShowS
show :: CreateInsight -> String
$cshow :: CreateInsight -> String
showsPrec :: Int -> CreateInsight -> ShowS
$cshowsPrec :: Int -> CreateInsight -> ShowS
Prelude.Show, (forall x. CreateInsight -> Rep CreateInsight x)
-> (forall x. Rep CreateInsight x -> CreateInsight)
-> Generic CreateInsight
forall x. Rep CreateInsight x -> CreateInsight
forall x. CreateInsight -> Rep CreateInsight x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateInsight x -> CreateInsight
$cfrom :: forall x. CreateInsight -> Rep CreateInsight x
Prelude.Generic)

-- |
-- Create a value of 'CreateInsight' 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:
--
-- 'name', 'createInsight_name' - The name of the custom insight to create.
--
-- 'filters', 'createInsight_filters' - One or more attributes used to filter the findings included in the
-- insight. The insight only includes findings that match the criteria
-- defined in the filters.
--
-- 'groupByAttribute', 'createInsight_groupByAttribute' - The attribute used to group the findings for the insight. The grouping
-- attribute identifies the type of item that the insight applies to. For
-- example, if an insight is grouped by resource identifier, then the
-- insight produces a list of resource identifiers.
newCreateInsight ::
  -- | 'name'
  Prelude.Text ->
  -- | 'filters'
  AwsSecurityFindingFilters ->
  -- | 'groupByAttribute'
  Prelude.Text ->
  CreateInsight
newCreateInsight :: Text -> AwsSecurityFindingFilters -> Text -> CreateInsight
newCreateInsight Text
pName_ AwsSecurityFindingFilters
pFilters_ Text
pGroupByAttribute_ =
  CreateInsight' :: Text -> AwsSecurityFindingFilters -> Text -> CreateInsight
CreateInsight'
    { $sel:name:CreateInsight' :: Text
name = Text
pName_,
      $sel:filters:CreateInsight' :: AwsSecurityFindingFilters
filters = AwsSecurityFindingFilters
pFilters_,
      $sel:groupByAttribute:CreateInsight' :: Text
groupByAttribute = Text
pGroupByAttribute_
    }

-- | The name of the custom insight to create.
createInsight_name :: Lens.Lens' CreateInsight Prelude.Text
createInsight_name :: (Text -> f Text) -> CreateInsight -> f CreateInsight
createInsight_name = (CreateInsight -> Text)
-> (CreateInsight -> Text -> CreateInsight)
-> Lens CreateInsight CreateInsight Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInsight' {Text
name :: Text
$sel:name:CreateInsight' :: CreateInsight -> Text
name} -> Text
name) (\s :: CreateInsight
s@CreateInsight' {} Text
a -> CreateInsight
s {$sel:name:CreateInsight' :: Text
name = Text
a} :: CreateInsight)

-- | One or more attributes used to filter the findings included in the
-- insight. The insight only includes findings that match the criteria
-- defined in the filters.
createInsight_filters :: Lens.Lens' CreateInsight AwsSecurityFindingFilters
createInsight_filters :: (AwsSecurityFindingFilters -> f AwsSecurityFindingFilters)
-> CreateInsight -> f CreateInsight
createInsight_filters = (CreateInsight -> AwsSecurityFindingFilters)
-> (CreateInsight -> AwsSecurityFindingFilters -> CreateInsight)
-> Lens
     CreateInsight
     CreateInsight
     AwsSecurityFindingFilters
     AwsSecurityFindingFilters
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInsight' {AwsSecurityFindingFilters
filters :: AwsSecurityFindingFilters
$sel:filters:CreateInsight' :: CreateInsight -> AwsSecurityFindingFilters
filters} -> AwsSecurityFindingFilters
filters) (\s :: CreateInsight
s@CreateInsight' {} AwsSecurityFindingFilters
a -> CreateInsight
s {$sel:filters:CreateInsight' :: AwsSecurityFindingFilters
filters = AwsSecurityFindingFilters
a} :: CreateInsight)

-- | The attribute used to group the findings for the insight. The grouping
-- attribute identifies the type of item that the insight applies to. For
-- example, if an insight is grouped by resource identifier, then the
-- insight produces a list of resource identifiers.
createInsight_groupByAttribute :: Lens.Lens' CreateInsight Prelude.Text
createInsight_groupByAttribute :: (Text -> f Text) -> CreateInsight -> f CreateInsight
createInsight_groupByAttribute = (CreateInsight -> Text)
-> (CreateInsight -> Text -> CreateInsight)
-> Lens CreateInsight CreateInsight Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInsight' {Text
groupByAttribute :: Text
$sel:groupByAttribute:CreateInsight' :: CreateInsight -> Text
groupByAttribute} -> Text
groupByAttribute) (\s :: CreateInsight
s@CreateInsight' {} Text
a -> CreateInsight
s {$sel:groupByAttribute:CreateInsight' :: Text
groupByAttribute = Text
a} :: CreateInsight)

instance Core.AWSRequest CreateInsight where
  type
    AWSResponse CreateInsight =
      CreateInsightResponse
  request :: CreateInsight -> Request CreateInsight
request = Service -> CreateInsight -> Request CreateInsight
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateInsight
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateInsight)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateInsight))
-> Logger
-> Service
-> Proxy CreateInsight
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateInsight)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Int -> Text -> CreateInsightResponse
CreateInsightResponse'
            (Int -> Text -> CreateInsightResponse)
-> Either String Int
-> Either String (Text -> CreateInsightResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String (Text -> CreateInsightResponse)
-> Either String Text -> Either String CreateInsightResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"InsightArn")
      )

instance Prelude.Hashable CreateInsight

instance Prelude.NFData CreateInsight

instance Core.ToHeaders CreateInsight where
  toHeaders :: CreateInsight -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateInsight -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreateInsight where
  toJSON :: CreateInsight -> Value
toJSON CreateInsight' {Text
AwsSecurityFindingFilters
groupByAttribute :: Text
filters :: AwsSecurityFindingFilters
name :: Text
$sel:groupByAttribute:CreateInsight' :: CreateInsight -> Text
$sel:filters:CreateInsight' :: CreateInsight -> AwsSecurityFindingFilters
$sel:name:CreateInsight' :: CreateInsight -> 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
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Filters" Text -> AwsSecurityFindingFilters -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AwsSecurityFindingFilters
filters),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"GroupByAttribute" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
groupByAttribute)
          ]
      )

instance Core.ToPath CreateInsight where
  toPath :: CreateInsight -> ByteString
toPath = ByteString -> CreateInsight -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/insights"

instance Core.ToQuery CreateInsight where
  toQuery :: CreateInsight -> QueryString
toQuery = QueryString -> CreateInsight -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newCreateInsightResponse' smart constructor.
data CreateInsightResponse = CreateInsightResponse'
  { -- | The response's http status code.
    CreateInsightResponse -> Int
httpStatus :: Prelude.Int,
    -- | The ARN of the insight created.
    CreateInsightResponse -> Text
insightArn :: Prelude.Text
  }
  deriving (CreateInsightResponse -> CreateInsightResponse -> Bool
(CreateInsightResponse -> CreateInsightResponse -> Bool)
-> (CreateInsightResponse -> CreateInsightResponse -> Bool)
-> Eq CreateInsightResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateInsightResponse -> CreateInsightResponse -> Bool
$c/= :: CreateInsightResponse -> CreateInsightResponse -> Bool
== :: CreateInsightResponse -> CreateInsightResponse -> Bool
$c== :: CreateInsightResponse -> CreateInsightResponse -> Bool
Prelude.Eq, ReadPrec [CreateInsightResponse]
ReadPrec CreateInsightResponse
Int -> ReadS CreateInsightResponse
ReadS [CreateInsightResponse]
(Int -> ReadS CreateInsightResponse)
-> ReadS [CreateInsightResponse]
-> ReadPrec CreateInsightResponse
-> ReadPrec [CreateInsightResponse]
-> Read CreateInsightResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateInsightResponse]
$creadListPrec :: ReadPrec [CreateInsightResponse]
readPrec :: ReadPrec CreateInsightResponse
$creadPrec :: ReadPrec CreateInsightResponse
readList :: ReadS [CreateInsightResponse]
$creadList :: ReadS [CreateInsightResponse]
readsPrec :: Int -> ReadS CreateInsightResponse
$creadsPrec :: Int -> ReadS CreateInsightResponse
Prelude.Read, Int -> CreateInsightResponse -> ShowS
[CreateInsightResponse] -> ShowS
CreateInsightResponse -> String
(Int -> CreateInsightResponse -> ShowS)
-> (CreateInsightResponse -> String)
-> ([CreateInsightResponse] -> ShowS)
-> Show CreateInsightResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateInsightResponse] -> ShowS
$cshowList :: [CreateInsightResponse] -> ShowS
show :: CreateInsightResponse -> String
$cshow :: CreateInsightResponse -> String
showsPrec :: Int -> CreateInsightResponse -> ShowS
$cshowsPrec :: Int -> CreateInsightResponse -> ShowS
Prelude.Show, (forall x. CreateInsightResponse -> Rep CreateInsightResponse x)
-> (forall x. Rep CreateInsightResponse x -> CreateInsightResponse)
-> Generic CreateInsightResponse
forall x. Rep CreateInsightResponse x -> CreateInsightResponse
forall x. CreateInsightResponse -> Rep CreateInsightResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateInsightResponse x -> CreateInsightResponse
$cfrom :: forall x. CreateInsightResponse -> Rep CreateInsightResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateInsightResponse' 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:
--
-- 'httpStatus', 'createInsightResponse_httpStatus' - The response's http status code.
--
-- 'insightArn', 'createInsightResponse_insightArn' - The ARN of the insight created.
newCreateInsightResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'insightArn'
  Prelude.Text ->
  CreateInsightResponse
newCreateInsightResponse :: Int -> Text -> CreateInsightResponse
newCreateInsightResponse Int
pHttpStatus_ Text
pInsightArn_ =
  CreateInsightResponse' :: Int -> Text -> CreateInsightResponse
CreateInsightResponse'
    { $sel:httpStatus:CreateInsightResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:insightArn:CreateInsightResponse' :: Text
insightArn = Text
pInsightArn_
    }

-- | The response's http status code.
createInsightResponse_httpStatus :: Lens.Lens' CreateInsightResponse Prelude.Int
createInsightResponse_httpStatus :: (Int -> f Int) -> CreateInsightResponse -> f CreateInsightResponse
createInsightResponse_httpStatus = (CreateInsightResponse -> Int)
-> (CreateInsightResponse -> Int -> CreateInsightResponse)
-> Lens CreateInsightResponse CreateInsightResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInsightResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreateInsightResponse' :: CreateInsightResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreateInsightResponse
s@CreateInsightResponse' {} Int
a -> CreateInsightResponse
s {$sel:httpStatus:CreateInsightResponse' :: Int
httpStatus = Int
a} :: CreateInsightResponse)

-- | The ARN of the insight created.
createInsightResponse_insightArn :: Lens.Lens' CreateInsightResponse Prelude.Text
createInsightResponse_insightArn :: (Text -> f Text)
-> CreateInsightResponse -> f CreateInsightResponse
createInsightResponse_insightArn = (CreateInsightResponse -> Text)
-> (CreateInsightResponse -> Text -> CreateInsightResponse)
-> Lens CreateInsightResponse CreateInsightResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateInsightResponse' {Text
insightArn :: Text
$sel:insightArn:CreateInsightResponse' :: CreateInsightResponse -> Text
insightArn} -> Text
insightArn) (\s :: CreateInsightResponse
s@CreateInsightResponse' {} Text
a -> CreateInsightResponse
s {$sel:insightArn:CreateInsightResponse' :: Text
insightArn = Text
a} :: CreateInsightResponse)

instance Prelude.NFData CreateInsightResponse