{-# 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.GuardDuty.UpdateDetector
-- 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)
--
-- Updates the Amazon GuardDuty detector specified by the detectorId.
module Amazonka.GuardDuty.UpdateDetector
  ( -- * Creating a Request
    UpdateDetector (..),
    newUpdateDetector,

    -- * Request Lenses
    updateDetector_findingPublishingFrequency,
    updateDetector_dataSources,
    updateDetector_enable,
    updateDetector_detectorId,

    -- * Destructuring the Response
    UpdateDetectorResponse (..),
    newUpdateDetectorResponse,

    -- * Response Lenses
    updateDetectorResponse_httpStatus,
  )
where

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

-- | /See:/ 'newUpdateDetector' smart constructor.
data UpdateDetector = UpdateDetector'
  { -- | An enum value that specifies how frequently findings are exported, such
    -- as to CloudWatch Events.
    UpdateDetector -> Maybe FindingPublishingFrequency
findingPublishingFrequency :: Prelude.Maybe FindingPublishingFrequency,
    -- | Describes which data sources will be updated.
    UpdateDetector -> Maybe DataSourceConfigurations
dataSources :: Prelude.Maybe DataSourceConfigurations,
    -- | Specifies whether the detector is enabled or not enabled.
    UpdateDetector -> Maybe Bool
enable :: Prelude.Maybe Prelude.Bool,
    -- | The unique ID of the detector to update.
    UpdateDetector -> Text
detectorId :: Prelude.Text
  }
  deriving (UpdateDetector -> UpdateDetector -> Bool
(UpdateDetector -> UpdateDetector -> Bool)
-> (UpdateDetector -> UpdateDetector -> Bool) -> Eq UpdateDetector
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateDetector -> UpdateDetector -> Bool
$c/= :: UpdateDetector -> UpdateDetector -> Bool
== :: UpdateDetector -> UpdateDetector -> Bool
$c== :: UpdateDetector -> UpdateDetector -> Bool
Prelude.Eq, ReadPrec [UpdateDetector]
ReadPrec UpdateDetector
Int -> ReadS UpdateDetector
ReadS [UpdateDetector]
(Int -> ReadS UpdateDetector)
-> ReadS [UpdateDetector]
-> ReadPrec UpdateDetector
-> ReadPrec [UpdateDetector]
-> Read UpdateDetector
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateDetector]
$creadListPrec :: ReadPrec [UpdateDetector]
readPrec :: ReadPrec UpdateDetector
$creadPrec :: ReadPrec UpdateDetector
readList :: ReadS [UpdateDetector]
$creadList :: ReadS [UpdateDetector]
readsPrec :: Int -> ReadS UpdateDetector
$creadsPrec :: Int -> ReadS UpdateDetector
Prelude.Read, Int -> UpdateDetector -> ShowS
[UpdateDetector] -> ShowS
UpdateDetector -> String
(Int -> UpdateDetector -> ShowS)
-> (UpdateDetector -> String)
-> ([UpdateDetector] -> ShowS)
-> Show UpdateDetector
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateDetector] -> ShowS
$cshowList :: [UpdateDetector] -> ShowS
show :: UpdateDetector -> String
$cshow :: UpdateDetector -> String
showsPrec :: Int -> UpdateDetector -> ShowS
$cshowsPrec :: Int -> UpdateDetector -> ShowS
Prelude.Show, (forall x. UpdateDetector -> Rep UpdateDetector x)
-> (forall x. Rep UpdateDetector x -> UpdateDetector)
-> Generic UpdateDetector
forall x. Rep UpdateDetector x -> UpdateDetector
forall x. UpdateDetector -> Rep UpdateDetector x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateDetector x -> UpdateDetector
$cfrom :: forall x. UpdateDetector -> Rep UpdateDetector x
Prelude.Generic)

-- |
-- Create a value of 'UpdateDetector' 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:
--
-- 'findingPublishingFrequency', 'updateDetector_findingPublishingFrequency' - An enum value that specifies how frequently findings are exported, such
-- as to CloudWatch Events.
--
-- 'dataSources', 'updateDetector_dataSources' - Describes which data sources will be updated.
--
-- 'enable', 'updateDetector_enable' - Specifies whether the detector is enabled or not enabled.
--
-- 'detectorId', 'updateDetector_detectorId' - The unique ID of the detector to update.
newUpdateDetector ::
  -- | 'detectorId'
  Prelude.Text ->
  UpdateDetector
newUpdateDetector :: Text -> UpdateDetector
newUpdateDetector Text
pDetectorId_ =
  UpdateDetector' :: Maybe FindingPublishingFrequency
-> Maybe DataSourceConfigurations
-> Maybe Bool
-> Text
-> UpdateDetector
UpdateDetector'
    { $sel:findingPublishingFrequency:UpdateDetector' :: Maybe FindingPublishingFrequency
findingPublishingFrequency =
        Maybe FindingPublishingFrequency
forall a. Maybe a
Prelude.Nothing,
      $sel:dataSources:UpdateDetector' :: Maybe DataSourceConfigurations
dataSources = Maybe DataSourceConfigurations
forall a. Maybe a
Prelude.Nothing,
      $sel:enable:UpdateDetector' :: Maybe Bool
enable = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:detectorId:UpdateDetector' :: Text
detectorId = Text
pDetectorId_
    }

-- | An enum value that specifies how frequently findings are exported, such
-- as to CloudWatch Events.
updateDetector_findingPublishingFrequency :: Lens.Lens' UpdateDetector (Prelude.Maybe FindingPublishingFrequency)
updateDetector_findingPublishingFrequency :: (Maybe FindingPublishingFrequency
 -> f (Maybe FindingPublishingFrequency))
-> UpdateDetector -> f UpdateDetector
updateDetector_findingPublishingFrequency = (UpdateDetector -> Maybe FindingPublishingFrequency)
-> (UpdateDetector
    -> Maybe FindingPublishingFrequency -> UpdateDetector)
-> Lens
     UpdateDetector
     UpdateDetector
     (Maybe FindingPublishingFrequency)
     (Maybe FindingPublishingFrequency)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDetector' {Maybe FindingPublishingFrequency
findingPublishingFrequency :: Maybe FindingPublishingFrequency
$sel:findingPublishingFrequency:UpdateDetector' :: UpdateDetector -> Maybe FindingPublishingFrequency
findingPublishingFrequency} -> Maybe FindingPublishingFrequency
findingPublishingFrequency) (\s :: UpdateDetector
s@UpdateDetector' {} Maybe FindingPublishingFrequency
a -> UpdateDetector
s {$sel:findingPublishingFrequency:UpdateDetector' :: Maybe FindingPublishingFrequency
findingPublishingFrequency = Maybe FindingPublishingFrequency
a} :: UpdateDetector)

-- | Describes which data sources will be updated.
updateDetector_dataSources :: Lens.Lens' UpdateDetector (Prelude.Maybe DataSourceConfigurations)
updateDetector_dataSources :: (Maybe DataSourceConfigurations
 -> f (Maybe DataSourceConfigurations))
-> UpdateDetector -> f UpdateDetector
updateDetector_dataSources = (UpdateDetector -> Maybe DataSourceConfigurations)
-> (UpdateDetector
    -> Maybe DataSourceConfigurations -> UpdateDetector)
-> Lens
     UpdateDetector
     UpdateDetector
     (Maybe DataSourceConfigurations)
     (Maybe DataSourceConfigurations)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDetector' {Maybe DataSourceConfigurations
dataSources :: Maybe DataSourceConfigurations
$sel:dataSources:UpdateDetector' :: UpdateDetector -> Maybe DataSourceConfigurations
dataSources} -> Maybe DataSourceConfigurations
dataSources) (\s :: UpdateDetector
s@UpdateDetector' {} Maybe DataSourceConfigurations
a -> UpdateDetector
s {$sel:dataSources:UpdateDetector' :: Maybe DataSourceConfigurations
dataSources = Maybe DataSourceConfigurations
a} :: UpdateDetector)

-- | Specifies whether the detector is enabled or not enabled.
updateDetector_enable :: Lens.Lens' UpdateDetector (Prelude.Maybe Prelude.Bool)
updateDetector_enable :: (Maybe Bool -> f (Maybe Bool))
-> UpdateDetector -> f UpdateDetector
updateDetector_enable = (UpdateDetector -> Maybe Bool)
-> (UpdateDetector -> Maybe Bool -> UpdateDetector)
-> Lens UpdateDetector UpdateDetector (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDetector' {Maybe Bool
enable :: Maybe Bool
$sel:enable:UpdateDetector' :: UpdateDetector -> Maybe Bool
enable} -> Maybe Bool
enable) (\s :: UpdateDetector
s@UpdateDetector' {} Maybe Bool
a -> UpdateDetector
s {$sel:enable:UpdateDetector' :: Maybe Bool
enable = Maybe Bool
a} :: UpdateDetector)

-- | The unique ID of the detector to update.
updateDetector_detectorId :: Lens.Lens' UpdateDetector Prelude.Text
updateDetector_detectorId :: (Text -> f Text) -> UpdateDetector -> f UpdateDetector
updateDetector_detectorId = (UpdateDetector -> Text)
-> (UpdateDetector -> Text -> UpdateDetector)
-> Lens UpdateDetector UpdateDetector Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateDetector' {Text
detectorId :: Text
$sel:detectorId:UpdateDetector' :: UpdateDetector -> Text
detectorId} -> Text
detectorId) (\s :: UpdateDetector
s@UpdateDetector' {} Text
a -> UpdateDetector
s {$sel:detectorId:UpdateDetector' :: Text
detectorId = Text
a} :: UpdateDetector)

instance Core.AWSRequest UpdateDetector where
  type
    AWSResponse UpdateDetector =
      UpdateDetectorResponse
  request :: UpdateDetector -> Request UpdateDetector
request = Service -> UpdateDetector -> Request UpdateDetector
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateDetector
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateDetector)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateDetector))
-> Logger
-> Service
-> Proxy UpdateDetector
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateDetector)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> UpdateDetectorResponse
UpdateDetectorResponse'
            (Int -> UpdateDetectorResponse)
-> Either String Int -> Either String UpdateDetectorResponse
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))
      )

instance Prelude.Hashable UpdateDetector

instance Prelude.NFData UpdateDetector

instance Core.ToHeaders UpdateDetector where
  toHeaders :: UpdateDetector -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateDetector -> 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 UpdateDetector where
  toJSON :: UpdateDetector -> Value
toJSON UpdateDetector' {Maybe Bool
Maybe FindingPublishingFrequency
Maybe DataSourceConfigurations
Text
detectorId :: Text
enable :: Maybe Bool
dataSources :: Maybe DataSourceConfigurations
findingPublishingFrequency :: Maybe FindingPublishingFrequency
$sel:detectorId:UpdateDetector' :: UpdateDetector -> Text
$sel:enable:UpdateDetector' :: UpdateDetector -> Maybe Bool
$sel:dataSources:UpdateDetector' :: UpdateDetector -> Maybe DataSourceConfigurations
$sel:findingPublishingFrequency:UpdateDetector' :: UpdateDetector -> Maybe FindingPublishingFrequency
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"findingPublishingFrequency" Text -> FindingPublishingFrequency -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (FindingPublishingFrequency -> Pair)
-> Maybe FindingPublishingFrequency -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe FindingPublishingFrequency
findingPublishingFrequency,
            (Text
"dataSources" Text -> DataSourceConfigurations -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (DataSourceConfigurations -> Pair)
-> Maybe DataSourceConfigurations -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe DataSourceConfigurations
dataSources,
            (Text
"enable" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
enable
          ]
      )

instance Core.ToPath UpdateDetector where
  toPath :: UpdateDetector -> ByteString
toPath UpdateDetector' {Maybe Bool
Maybe FindingPublishingFrequency
Maybe DataSourceConfigurations
Text
detectorId :: Text
enable :: Maybe Bool
dataSources :: Maybe DataSourceConfigurations
findingPublishingFrequency :: Maybe FindingPublishingFrequency
$sel:detectorId:UpdateDetector' :: UpdateDetector -> Text
$sel:enable:UpdateDetector' :: UpdateDetector -> Maybe Bool
$sel:dataSources:UpdateDetector' :: UpdateDetector -> Maybe DataSourceConfigurations
$sel:findingPublishingFrequency:UpdateDetector' :: UpdateDetector -> Maybe FindingPublishingFrequency
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/detector/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
detectorId]

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

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

-- |
-- Create a value of 'UpdateDetectorResponse' 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', 'updateDetectorResponse_httpStatus' - The response's http status code.
newUpdateDetectorResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateDetectorResponse
newUpdateDetectorResponse :: Int -> UpdateDetectorResponse
newUpdateDetectorResponse Int
pHttpStatus_ =
  UpdateDetectorResponse' :: Int -> UpdateDetectorResponse
UpdateDetectorResponse' {$sel:httpStatus:UpdateDetectorResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData UpdateDetectorResponse