{-# 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-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 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 Amazonka.Inspector.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:/ '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
(StartAssessmentRun -> StartAssessmentRun -> Bool)
-> (StartAssessmentRun -> StartAssessmentRun -> Bool)
-> Eq StartAssessmentRun
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]
(Int -> ReadS StartAssessmentRun)
-> ReadS [StartAssessmentRun]
-> ReadPrec StartAssessmentRun
-> ReadPrec [StartAssessmentRun]
-> Read 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
(Int -> StartAssessmentRun -> ShowS)
-> (StartAssessmentRun -> String)
-> ([StartAssessmentRun] -> ShowS)
-> Show StartAssessmentRun
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. StartAssessmentRun -> Rep StartAssessmentRun x)
-> (forall x. Rep StartAssessmentRun x -> StartAssessmentRun)
-> Generic StartAssessmentRun
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' :: Maybe Text -> Text -> StartAssessmentRun
StartAssessmentRun'
    { $sel:assessmentRunName:StartAssessmentRun' :: Maybe Text
assessmentRunName =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> StartAssessmentRun -> f StartAssessmentRun
startAssessmentRun_assessmentRunName = (StartAssessmentRun -> Maybe Text)
-> (StartAssessmentRun -> Maybe Text -> StartAssessmentRun)
-> Lens
     StartAssessmentRun StartAssessmentRun (Maybe Text) (Maybe Text)
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 :: (Text -> f Text) -> StartAssessmentRun -> f StartAssessmentRun
startAssessmentRun_assessmentTemplateArn = (StartAssessmentRun -> Text)
-> (StartAssessmentRun -> Text -> StartAssessmentRun)
-> Lens StartAssessmentRun StartAssessmentRun Text Text
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 :: StartAssessmentRun -> Request StartAssessmentRun
request = Service -> StartAssessmentRun -> Request StartAssessmentRun
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy StartAssessmentRun
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartAssessmentRun)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse StartAssessmentRun))
-> Logger
-> Service
-> Proxy StartAssessmentRun
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse StartAssessmentRun)))
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 -> StartAssessmentRunResponse
StartAssessmentRunResponse'
            (Int -> Text -> StartAssessmentRunResponse)
-> Either String Int
-> Either String (Text -> StartAssessmentRunResponse)
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 -> StartAssessmentRunResponse)
-> Either String Text -> Either String StartAssessmentRunResponse
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
"assessmentRunArn")
      )

instance Prelude.Hashable StartAssessmentRun

instance Prelude.NFData StartAssessmentRun

instance Core.ToHeaders StartAssessmentRun where
  toHeaders :: StartAssessmentRun -> ResponseHeaders
toHeaders =
    ResponseHeaders -> StartAssessmentRun -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"InspectorService.StartAssessmentRun" ::
                          Prelude.ByteString
                      ),
            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 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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"assessmentRunName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
assessmentRunName,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"assessmentTemplateArn"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
assessmentTemplateArn
              )
          ]
      )

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

instance Core.ToQuery StartAssessmentRun where
  toQuery :: StartAssessmentRun -> QueryString
toQuery = QueryString -> StartAssessmentRun -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(StartAssessmentRunResponse -> StartAssessmentRunResponse -> Bool)
-> (StartAssessmentRunResponse
    -> StartAssessmentRunResponse -> Bool)
-> Eq StartAssessmentRunResponse
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]
(Int -> ReadS StartAssessmentRunResponse)
-> ReadS [StartAssessmentRunResponse]
-> ReadPrec StartAssessmentRunResponse
-> ReadPrec [StartAssessmentRunResponse]
-> Read 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
(Int -> StartAssessmentRunResponse -> ShowS)
-> (StartAssessmentRunResponse -> String)
-> ([StartAssessmentRunResponse] -> ShowS)
-> Show StartAssessmentRunResponse
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.
 StartAssessmentRunResponse -> Rep StartAssessmentRunResponse x)
-> (forall x.
    Rep StartAssessmentRunResponse x -> StartAssessmentRunResponse)
-> Generic StartAssessmentRunResponse
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' :: Int -> Text -> StartAssessmentRunResponse
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 :: (Int -> f Int)
-> StartAssessmentRunResponse -> f StartAssessmentRunResponse
startAssessmentRunResponse_httpStatus = (StartAssessmentRunResponse -> Int)
-> (StartAssessmentRunResponse
    -> Int -> StartAssessmentRunResponse)
-> Lens
     StartAssessmentRunResponse StartAssessmentRunResponse Int Int
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 :: (Text -> f Text)
-> StartAssessmentRunResponse -> f StartAssessmentRunResponse
startAssessmentRunResponse_assessmentRunArn = (StartAssessmentRunResponse -> Text)
-> (StartAssessmentRunResponse
    -> Text -> StartAssessmentRunResponse)
-> Lens
     StartAssessmentRunResponse StartAssessmentRunResponse Text Text
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