{-# 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.IoT.StartOnDemandAuditTask
-- 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)
--
-- Starts an on-demand Device Defender audit.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions StartOnDemandAuditTask>
-- action.
module Amazonka.IoT.StartOnDemandAuditTask
  ( -- * Creating a Request
    StartOnDemandAuditTask (..),
    newStartOnDemandAuditTask,

    -- * Request Lenses
    startOnDemandAuditTask_targetCheckNames,

    -- * Destructuring the Response
    StartOnDemandAuditTaskResponse (..),
    newStartOnDemandAuditTaskResponse,

    -- * Response Lenses
    startOnDemandAuditTaskResponse_taskId,
    startOnDemandAuditTaskResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT.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:/ 'newStartOnDemandAuditTask' smart constructor.
data StartOnDemandAuditTask = StartOnDemandAuditTask'
  { -- | Which checks are performed during the audit. The checks you specify must
    -- be enabled for your account or an exception occurs. Use
    -- @DescribeAccountAuditConfiguration@ to see the list of all checks,
    -- including those that are enabled or @UpdateAccountAuditConfiguration@ to
    -- select which checks are enabled.
    StartOnDemandAuditTask -> [Text]
targetCheckNames :: [Prelude.Text]
  }
  deriving (StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool
(StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool)
-> (StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool)
-> Eq StartOnDemandAuditTask
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool
$c/= :: StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool
== :: StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool
$c== :: StartOnDemandAuditTask -> StartOnDemandAuditTask -> Bool
Prelude.Eq, ReadPrec [StartOnDemandAuditTask]
ReadPrec StartOnDemandAuditTask
Int -> ReadS StartOnDemandAuditTask
ReadS [StartOnDemandAuditTask]
(Int -> ReadS StartOnDemandAuditTask)
-> ReadS [StartOnDemandAuditTask]
-> ReadPrec StartOnDemandAuditTask
-> ReadPrec [StartOnDemandAuditTask]
-> Read StartOnDemandAuditTask
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartOnDemandAuditTask]
$creadListPrec :: ReadPrec [StartOnDemandAuditTask]
readPrec :: ReadPrec StartOnDemandAuditTask
$creadPrec :: ReadPrec StartOnDemandAuditTask
readList :: ReadS [StartOnDemandAuditTask]
$creadList :: ReadS [StartOnDemandAuditTask]
readsPrec :: Int -> ReadS StartOnDemandAuditTask
$creadsPrec :: Int -> ReadS StartOnDemandAuditTask
Prelude.Read, Int -> StartOnDemandAuditTask -> ShowS
[StartOnDemandAuditTask] -> ShowS
StartOnDemandAuditTask -> String
(Int -> StartOnDemandAuditTask -> ShowS)
-> (StartOnDemandAuditTask -> String)
-> ([StartOnDemandAuditTask] -> ShowS)
-> Show StartOnDemandAuditTask
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartOnDemandAuditTask] -> ShowS
$cshowList :: [StartOnDemandAuditTask] -> ShowS
show :: StartOnDemandAuditTask -> String
$cshow :: StartOnDemandAuditTask -> String
showsPrec :: Int -> StartOnDemandAuditTask -> ShowS
$cshowsPrec :: Int -> StartOnDemandAuditTask -> ShowS
Prelude.Show, (forall x. StartOnDemandAuditTask -> Rep StartOnDemandAuditTask x)
-> (forall x.
    Rep StartOnDemandAuditTask x -> StartOnDemandAuditTask)
-> Generic StartOnDemandAuditTask
forall x. Rep StartOnDemandAuditTask x -> StartOnDemandAuditTask
forall x. StartOnDemandAuditTask -> Rep StartOnDemandAuditTask x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartOnDemandAuditTask x -> StartOnDemandAuditTask
$cfrom :: forall x. StartOnDemandAuditTask -> Rep StartOnDemandAuditTask x
Prelude.Generic)

-- |
-- Create a value of 'StartOnDemandAuditTask' 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:
--
-- 'targetCheckNames', 'startOnDemandAuditTask_targetCheckNames' - Which checks are performed during the audit. The checks you specify must
-- be enabled for your account or an exception occurs. Use
-- @DescribeAccountAuditConfiguration@ to see the list of all checks,
-- including those that are enabled or @UpdateAccountAuditConfiguration@ to
-- select which checks are enabled.
newStartOnDemandAuditTask ::
  StartOnDemandAuditTask
newStartOnDemandAuditTask :: StartOnDemandAuditTask
newStartOnDemandAuditTask =
  StartOnDemandAuditTask' :: [Text] -> StartOnDemandAuditTask
StartOnDemandAuditTask'
    { $sel:targetCheckNames:StartOnDemandAuditTask' :: [Text]
targetCheckNames =
        [Text]
forall a. Monoid a => a
Prelude.mempty
    }

-- | Which checks are performed during the audit. The checks you specify must
-- be enabled for your account or an exception occurs. Use
-- @DescribeAccountAuditConfiguration@ to see the list of all checks,
-- including those that are enabled or @UpdateAccountAuditConfiguration@ to
-- select which checks are enabled.
startOnDemandAuditTask_targetCheckNames :: Lens.Lens' StartOnDemandAuditTask [Prelude.Text]
startOnDemandAuditTask_targetCheckNames :: ([Text] -> f [Text])
-> StartOnDemandAuditTask -> f StartOnDemandAuditTask
startOnDemandAuditTask_targetCheckNames = (StartOnDemandAuditTask -> [Text])
-> (StartOnDemandAuditTask -> [Text] -> StartOnDemandAuditTask)
-> Lens StartOnDemandAuditTask StartOnDemandAuditTask [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartOnDemandAuditTask' {[Text]
targetCheckNames :: [Text]
$sel:targetCheckNames:StartOnDemandAuditTask' :: StartOnDemandAuditTask -> [Text]
targetCheckNames} -> [Text]
targetCheckNames) (\s :: StartOnDemandAuditTask
s@StartOnDemandAuditTask' {} [Text]
a -> StartOnDemandAuditTask
s {$sel:targetCheckNames:StartOnDemandAuditTask' :: [Text]
targetCheckNames = [Text]
a} :: StartOnDemandAuditTask) (([Text] -> f [Text])
 -> StartOnDemandAuditTask -> f StartOnDemandAuditTask)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> StartOnDemandAuditTask
-> f StartOnDemandAuditTask
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.AWSRequest StartOnDemandAuditTask where
  type
    AWSResponse StartOnDemandAuditTask =
      StartOnDemandAuditTaskResponse
  request :: StartOnDemandAuditTask -> Request StartOnDemandAuditTask
request = Service -> StartOnDemandAuditTask -> Request StartOnDemandAuditTask
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartOnDemandAuditTask
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartOnDemandAuditTask)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartOnDemandAuditTask))
-> Logger
-> Service
-> Proxy StartOnDemandAuditTask
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartOnDemandAuditTask)))
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 ->
          Maybe Text -> Int -> StartOnDemandAuditTaskResponse
StartOnDemandAuditTaskResponse'
            (Maybe Text -> Int -> StartOnDemandAuditTaskResponse)
-> Either String (Maybe Text)
-> Either String (Int -> StartOnDemandAuditTaskResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"taskId")
            Either String (Int -> StartOnDemandAuditTaskResponse)
-> Either String Int
-> Either String StartOnDemandAuditTaskResponse
forall (f :: * -> *) a b. Applicative f => 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 StartOnDemandAuditTask

instance Prelude.NFData StartOnDemandAuditTask

instance Core.ToHeaders StartOnDemandAuditTask where
  toHeaders :: StartOnDemandAuditTask -> ResponseHeaders
toHeaders = ResponseHeaders -> StartOnDemandAuditTask -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON StartOnDemandAuditTask where
  toJSON :: StartOnDemandAuditTask -> Value
toJSON StartOnDemandAuditTask' {[Text]
targetCheckNames :: [Text]
$sel:targetCheckNames:StartOnDemandAuditTask' :: StartOnDemandAuditTask -> [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
"targetCheckNames" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
targetCheckNames)
          ]
      )

instance Core.ToPath StartOnDemandAuditTask where
  toPath :: StartOnDemandAuditTask -> ByteString
toPath = ByteString -> StartOnDemandAuditTask -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/audit/tasks"

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

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

-- |
-- Create a value of 'StartOnDemandAuditTaskResponse' 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:
--
-- 'taskId', 'startOnDemandAuditTaskResponse_taskId' - The ID of the on-demand audit you started.
--
-- 'httpStatus', 'startOnDemandAuditTaskResponse_httpStatus' - The response's http status code.
newStartOnDemandAuditTaskResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  StartOnDemandAuditTaskResponse
newStartOnDemandAuditTaskResponse :: Int -> StartOnDemandAuditTaskResponse
newStartOnDemandAuditTaskResponse Int
pHttpStatus_ =
  StartOnDemandAuditTaskResponse' :: Maybe Text -> Int -> StartOnDemandAuditTaskResponse
StartOnDemandAuditTaskResponse'
    { $sel:taskId:StartOnDemandAuditTaskResponse' :: Maybe Text
taskId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:StartOnDemandAuditTaskResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ID of the on-demand audit you started.
startOnDemandAuditTaskResponse_taskId :: Lens.Lens' StartOnDemandAuditTaskResponse (Prelude.Maybe Prelude.Text)
startOnDemandAuditTaskResponse_taskId :: (Maybe Text -> f (Maybe Text))
-> StartOnDemandAuditTaskResponse
-> f StartOnDemandAuditTaskResponse
startOnDemandAuditTaskResponse_taskId = (StartOnDemandAuditTaskResponse -> Maybe Text)
-> (StartOnDemandAuditTaskResponse
    -> Maybe Text -> StartOnDemandAuditTaskResponse)
-> Lens
     StartOnDemandAuditTaskResponse
     StartOnDemandAuditTaskResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartOnDemandAuditTaskResponse' {Maybe Text
taskId :: Maybe Text
$sel:taskId:StartOnDemandAuditTaskResponse' :: StartOnDemandAuditTaskResponse -> Maybe Text
taskId} -> Maybe Text
taskId) (\s :: StartOnDemandAuditTaskResponse
s@StartOnDemandAuditTaskResponse' {} Maybe Text
a -> StartOnDemandAuditTaskResponse
s {$sel:taskId:StartOnDemandAuditTaskResponse' :: Maybe Text
taskId = Maybe Text
a} :: StartOnDemandAuditTaskResponse)

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

instance
  Prelude.NFData
    StartOnDemandAuditTaskResponse