{-# 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.Inspector.StartAssessmentRun
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts the assessment run specified by the ARN of the assessment
-- template. For this API to function properly, you must not exceed the
-- limit of running up to 500 concurrent agents per AWS account.
module Amazonka.Inspector.StartAssessmentRun
  ( -- * Creating a Request
    StartAssessmentRun (..),
    newStartAssessmentRun,

    -- * Request Lenses
    startAssessmentRun_assessmentRunName,
    startAssessmentRun_assessmentTemplateArn,

    -- * Destructuring the Response
    StartAssessmentRunResponse (..),
    newStartAssessmentRunResponse,

    -- * Response Lenses
    startAssessmentRunResponse_httpStatus,
    startAssessmentRunResponse_assessmentRunArn,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Inspector.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newStartAssessmentRun' smart constructor.
data StartAssessmentRun = StartAssessmentRun'
  { -- | You can specify the name for the assessment run. The name must be unique
    -- for the assessment template whose ARN is used to start the assessment
    -- run.
    StartAssessmentRun -> Maybe Text
assessmentRunName :: Prelude.Maybe Prelude.Text,
    -- | The ARN of the assessment template of the assessment run that you want
    -- to start.
    StartAssessmentRun -> Text
assessmentTemplateArn :: Prelude.Text
  }
  deriving (StartAssessmentRun -> StartAssessmentRun -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StartAssessmentRun -> StartAssessmentRun -> Bool
$c/= :: StartAssessmentRun -> StartAssessmentRun -> Bool
== :: StartAssessmentRun -> StartAssessmentRun -> Bool
$c== :: StartAssessmentRun -> StartAssessmentRun -> Bool
Prelude.Eq, ReadPrec [StartAssessmentRun]
ReadPrec StartAssessmentRun
Int -> ReadS StartAssessmentRun
ReadS [StartAssessmentRun]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StartAssessmentRun]
$creadListPrec :: ReadPrec [StartAssessmentRun]
readPrec :: ReadPrec StartAssessmentRun
$creadPrec :: ReadPrec StartAssessmentRun
readList :: ReadS [StartAssessmentRun]
$creadList :: ReadS [StartAssessmentRun]
readsPrec :: Int -> ReadS StartAssessmentRun
$creadsPrec :: Int -> ReadS StartAssessmentRun
Prelude.Read, Int -> StartAssessmentRun -> ShowS
[StartAssessmentRun] -> ShowS
StartAssessmentRun -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StartAssessmentRun] -> ShowS
$cshowList :: [StartAssessmentRun] -> ShowS
show :: StartAssessmentRun -> String
$cshow :: StartAssessmentRun -> String
showsPrec :: Int -> StartAssessmentRun -> ShowS
$cshowsPrec :: Int -> StartAssessmentRun -> ShowS
Prelude.Show, forall x. Rep StartAssessmentRun x -> StartAssessmentRun
forall x. StartAssessmentRun -> Rep StartAssessmentRun x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StartAssessmentRun x -> StartAssessmentRun
$cfrom :: forall x. StartAssessmentRun -> Rep StartAssessmentRun x
Prelude.Generic)

-- |
-- Create a value of 'StartAssessmentRun' 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:
--
-- 'assessmentRunName', 'startAssessmentRun_assessmentRunName' - You can specify the name for the assessment run. The name must be unique
-- for the assessment template whose ARN is used to start the assessment
-- run.
--
-- 'assessmentTemplateArn', 'startAssessmentRun_assessmentTemplateArn' - The ARN of the assessment template of the assessment run that you want
-- to start.
newStartAssessmentRun ::
  -- | 'assessmentTemplateArn'
  Prelude.Text ->
  StartAssessmentRun
newStartAssessmentRun :: Text -> StartAssessmentRun
newStartAssessmentRun Text
pAssessmentTemplateArn_ =
  StartAssessmentRun'
    { $sel:assessmentRunName:StartAssessmentRun' :: Maybe Text
assessmentRunName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:assessmentTemplateArn:StartAssessmentRun' :: Text
assessmentTemplateArn = Text
pAssessmentTemplateArn_
    }

-- | You can specify the name for the assessment run. The name must be unique
-- for the assessment template whose ARN is used to start the assessment
-- run.
startAssessmentRun_assessmentRunName :: Lens.Lens' StartAssessmentRun (Prelude.Maybe Prelude.Text)
startAssessmentRun_assessmentRunName :: Lens' StartAssessmentRun (Maybe Text)
startAssessmentRun_assessmentRunName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartAssessmentRun' {Maybe Text
assessmentRunName :: Maybe Text
$sel:assessmentRunName:StartAssessmentRun' :: StartAssessmentRun -> Maybe Text
assessmentRunName} -> Maybe Text
assessmentRunName) (\s :: StartAssessmentRun
s@StartAssessmentRun' {} Maybe Text
a -> StartAssessmentRun
s {$sel:assessmentRunName:StartAssessmentRun' :: Maybe Text
assessmentRunName = Maybe Text
a} :: StartAssessmentRun)

-- | The ARN of the assessment template of the assessment run that you want
-- to start.
startAssessmentRun_assessmentTemplateArn :: Lens.Lens' StartAssessmentRun Prelude.Text
startAssessmentRun_assessmentTemplateArn :: Lens' StartAssessmentRun Text
startAssessmentRun_assessmentTemplateArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartAssessmentRun' {Text
assessmentTemplateArn :: Text
$sel:assessmentTemplateArn:StartAssessmentRun' :: StartAssessmentRun -> Text
assessmentTemplateArn} -> Text
assessmentTemplateArn) (\s :: StartAssessmentRun
s@StartAssessmentRun' {} Text
a -> StartAssessmentRun
s {$sel:assessmentTemplateArn:StartAssessmentRun' :: Text
assessmentTemplateArn = Text
a} :: StartAssessmentRun)

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

instance Prelude.Hashable StartAssessmentRun where
  hashWithSalt :: Int -> StartAssessmentRun -> Int
hashWithSalt Int
_salt StartAssessmentRun' {Maybe Text
Text
assessmentTemplateArn :: Text
assessmentRunName :: Maybe Text
$sel:assessmentTemplateArn:StartAssessmentRun' :: StartAssessmentRun -> Text
$sel:assessmentRunName:StartAssessmentRun' :: StartAssessmentRun -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
assessmentRunName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
assessmentTemplateArn

instance Prelude.NFData StartAssessmentRun where
  rnf :: StartAssessmentRun -> ()
rnf StartAssessmentRun' {Maybe Text
Text
assessmentTemplateArn :: Text
assessmentRunName :: Maybe Text
$sel:assessmentTemplateArn:StartAssessmentRun' :: StartAssessmentRun -> Text
$sel:assessmentRunName:StartAssessmentRun' :: StartAssessmentRun -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
assessmentRunName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
assessmentTemplateArn

instance Data.ToHeaders StartAssessmentRun where
  toHeaders :: StartAssessmentRun -> ResponseHeaders
toHeaders =
    forall a b. a -> b -> a
Prelude.const
      ( forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"InspectorService.StartAssessmentRun" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Data.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Data.ToJSON StartAssessmentRun where
  toJSON :: StartAssessmentRun -> Value
toJSON StartAssessmentRun' {Maybe Text
Text
assessmentTemplateArn :: Text
assessmentRunName :: Maybe Text
$sel:assessmentTemplateArn:StartAssessmentRun' :: StartAssessmentRun -> Text
$sel:assessmentRunName:StartAssessmentRun' :: StartAssessmentRun -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"assessmentRunName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
assessmentRunName,
            forall a. a -> Maybe a
Prelude.Just
              ( Key
"assessmentTemplateArn"
                  forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
assessmentTemplateArn
              )
          ]
      )

instance Data.ToPath StartAssessmentRun where
  toPath :: StartAssessmentRun -> ByteString
toPath = forall a b. a -> b -> a
Prelude.const ByteString
"/"

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

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

-- |
-- Create a value of 'StartAssessmentRunResponse' 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', 'startAssessmentRunResponse_httpStatus' - The response's http status code.
--
-- 'assessmentRunArn', 'startAssessmentRunResponse_assessmentRunArn' - The ARN of the assessment run that has been started.
newStartAssessmentRunResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'assessmentRunArn'
  Prelude.Text ->
  StartAssessmentRunResponse
newStartAssessmentRunResponse :: Int -> Text -> StartAssessmentRunResponse
newStartAssessmentRunResponse
  Int
pHttpStatus_
  Text
pAssessmentRunArn_ =
    StartAssessmentRunResponse'
      { $sel:httpStatus:StartAssessmentRunResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:assessmentRunArn:StartAssessmentRunResponse' :: Text
assessmentRunArn = Text
pAssessmentRunArn_
      }

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

-- | The ARN of the assessment run that has been started.
startAssessmentRunResponse_assessmentRunArn :: Lens.Lens' StartAssessmentRunResponse Prelude.Text
startAssessmentRunResponse_assessmentRunArn :: Lens' StartAssessmentRunResponse Text
startAssessmentRunResponse_assessmentRunArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StartAssessmentRunResponse' {Text
assessmentRunArn :: Text
$sel:assessmentRunArn:StartAssessmentRunResponse' :: StartAssessmentRunResponse -> Text
assessmentRunArn} -> Text
assessmentRunArn) (\s :: StartAssessmentRunResponse
s@StartAssessmentRunResponse' {} Text
a -> StartAssessmentRunResponse
s {$sel:assessmentRunArn:StartAssessmentRunResponse' :: Text
assessmentRunArn = Text
a} :: StartAssessmentRunResponse)

instance Prelude.NFData StartAssessmentRunResponse where
  rnf :: StartAssessmentRunResponse -> ()
rnf StartAssessmentRunResponse' {Int
Text
assessmentRunArn :: Text
httpStatus :: Int
$sel:assessmentRunArn:StartAssessmentRunResponse' :: StartAssessmentRunResponse -> Text
$sel:httpStatus:StartAssessmentRunResponse' :: StartAssessmentRunResponse -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
assessmentRunArn