{-# 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.CreateAssessmentTarget
-- 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 new assessment target using the ARN of the resource group that
-- is generated by CreateResourceGroup. If resourceGroupArn is not
-- specified, all EC2 instances in the current AWS account and region are
-- included in the assessment target. If the
-- <https://docs.aws.amazon.com/inspector/latest/userguide/inspector_slr.html service-linked role>
-- isn’t already registered, this action also creates and registers a
-- service-linked role to grant Amazon Inspector access to AWS Services
-- needed to perform security assessments. You can create up to 50
-- assessment targets per AWS account. You can run up to 500 concurrent
-- agents per AWS account. For more information, see
-- <https://docs.aws.amazon.com/inspector/latest/userguide/inspector_applications.html Amazon Inspector Assessment Targets>.
module Amazonka.Inspector.CreateAssessmentTarget
  ( -- * Creating a Request
    CreateAssessmentTarget (..),
    newCreateAssessmentTarget,

    -- * Request Lenses
    createAssessmentTarget_resourceGroupArn,
    createAssessmentTarget_assessmentTargetName,

    -- * Destructuring the Response
    CreateAssessmentTargetResponse (..),
    newCreateAssessmentTargetResponse,

    -- * Response Lenses
    createAssessmentTargetResponse_httpStatus,
    createAssessmentTargetResponse_assessmentTargetArn,
  )
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:/ 'newCreateAssessmentTarget' smart constructor.
data CreateAssessmentTarget = CreateAssessmentTarget'
  { -- | The ARN that specifies the resource group that is used to create the
    -- assessment target. If resourceGroupArn is not specified, all EC2
    -- instances in the current AWS account and region are included in the
    -- assessment target.
    CreateAssessmentTarget -> Maybe Text
resourceGroupArn :: Prelude.Maybe Prelude.Text,
    -- | The user-defined name that identifies the assessment target that you
    -- want to create. The name must be unique within the AWS account.
    CreateAssessmentTarget -> Text
assessmentTargetName :: Prelude.Text
  }
  deriving (CreateAssessmentTarget -> CreateAssessmentTarget -> Bool
(CreateAssessmentTarget -> CreateAssessmentTarget -> Bool)
-> (CreateAssessmentTarget -> CreateAssessmentTarget -> Bool)
-> Eq CreateAssessmentTarget
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateAssessmentTarget -> CreateAssessmentTarget -> Bool
$c/= :: CreateAssessmentTarget -> CreateAssessmentTarget -> Bool
== :: CreateAssessmentTarget -> CreateAssessmentTarget -> Bool
$c== :: CreateAssessmentTarget -> CreateAssessmentTarget -> Bool
Prelude.Eq, ReadPrec [CreateAssessmentTarget]
ReadPrec CreateAssessmentTarget
Int -> ReadS CreateAssessmentTarget
ReadS [CreateAssessmentTarget]
(Int -> ReadS CreateAssessmentTarget)
-> ReadS [CreateAssessmentTarget]
-> ReadPrec CreateAssessmentTarget
-> ReadPrec [CreateAssessmentTarget]
-> Read CreateAssessmentTarget
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateAssessmentTarget]
$creadListPrec :: ReadPrec [CreateAssessmentTarget]
readPrec :: ReadPrec CreateAssessmentTarget
$creadPrec :: ReadPrec CreateAssessmentTarget
readList :: ReadS [CreateAssessmentTarget]
$creadList :: ReadS [CreateAssessmentTarget]
readsPrec :: Int -> ReadS CreateAssessmentTarget
$creadsPrec :: Int -> ReadS CreateAssessmentTarget
Prelude.Read, Int -> CreateAssessmentTarget -> ShowS
[CreateAssessmentTarget] -> ShowS
CreateAssessmentTarget -> String
(Int -> CreateAssessmentTarget -> ShowS)
-> (CreateAssessmentTarget -> String)
-> ([CreateAssessmentTarget] -> ShowS)
-> Show CreateAssessmentTarget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateAssessmentTarget] -> ShowS
$cshowList :: [CreateAssessmentTarget] -> ShowS
show :: CreateAssessmentTarget -> String
$cshow :: CreateAssessmentTarget -> String
showsPrec :: Int -> CreateAssessmentTarget -> ShowS
$cshowsPrec :: Int -> CreateAssessmentTarget -> ShowS
Prelude.Show, (forall x. CreateAssessmentTarget -> Rep CreateAssessmentTarget x)
-> (forall x.
    Rep CreateAssessmentTarget x -> CreateAssessmentTarget)
-> Generic CreateAssessmentTarget
forall x. Rep CreateAssessmentTarget x -> CreateAssessmentTarget
forall x. CreateAssessmentTarget -> Rep CreateAssessmentTarget x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateAssessmentTarget x -> CreateAssessmentTarget
$cfrom :: forall x. CreateAssessmentTarget -> Rep CreateAssessmentTarget x
Prelude.Generic)

-- |
-- Create a value of 'CreateAssessmentTarget' 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:
--
-- 'resourceGroupArn', 'createAssessmentTarget_resourceGroupArn' - The ARN that specifies the resource group that is used to create the
-- assessment target. If resourceGroupArn is not specified, all EC2
-- instances in the current AWS account and region are included in the
-- assessment target.
--
-- 'assessmentTargetName', 'createAssessmentTarget_assessmentTargetName' - The user-defined name that identifies the assessment target that you
-- want to create. The name must be unique within the AWS account.
newCreateAssessmentTarget ::
  -- | 'assessmentTargetName'
  Prelude.Text ->
  CreateAssessmentTarget
newCreateAssessmentTarget :: Text -> CreateAssessmentTarget
newCreateAssessmentTarget Text
pAssessmentTargetName_ =
  CreateAssessmentTarget' :: Maybe Text -> Text -> CreateAssessmentTarget
CreateAssessmentTarget'
    { $sel:resourceGroupArn:CreateAssessmentTarget' :: Maybe Text
resourceGroupArn =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:assessmentTargetName:CreateAssessmentTarget' :: Text
assessmentTargetName = Text
pAssessmentTargetName_
    }

-- | The ARN that specifies the resource group that is used to create the
-- assessment target. If resourceGroupArn is not specified, all EC2
-- instances in the current AWS account and region are included in the
-- assessment target.
createAssessmentTarget_resourceGroupArn :: Lens.Lens' CreateAssessmentTarget (Prelude.Maybe Prelude.Text)
createAssessmentTarget_resourceGroupArn :: (Maybe Text -> f (Maybe Text))
-> CreateAssessmentTarget -> f CreateAssessmentTarget
createAssessmentTarget_resourceGroupArn = (CreateAssessmentTarget -> Maybe Text)
-> (CreateAssessmentTarget -> Maybe Text -> CreateAssessmentTarget)
-> Lens
     CreateAssessmentTarget
     CreateAssessmentTarget
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAssessmentTarget' {Maybe Text
resourceGroupArn :: Maybe Text
$sel:resourceGroupArn:CreateAssessmentTarget' :: CreateAssessmentTarget -> Maybe Text
resourceGroupArn} -> Maybe Text
resourceGroupArn) (\s :: CreateAssessmentTarget
s@CreateAssessmentTarget' {} Maybe Text
a -> CreateAssessmentTarget
s {$sel:resourceGroupArn:CreateAssessmentTarget' :: Maybe Text
resourceGroupArn = Maybe Text
a} :: CreateAssessmentTarget)

-- | The user-defined name that identifies the assessment target that you
-- want to create. The name must be unique within the AWS account.
createAssessmentTarget_assessmentTargetName :: Lens.Lens' CreateAssessmentTarget Prelude.Text
createAssessmentTarget_assessmentTargetName :: (Text -> f Text)
-> CreateAssessmentTarget -> f CreateAssessmentTarget
createAssessmentTarget_assessmentTargetName = (CreateAssessmentTarget -> Text)
-> (CreateAssessmentTarget -> Text -> CreateAssessmentTarget)
-> Lens CreateAssessmentTarget CreateAssessmentTarget Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAssessmentTarget' {Text
assessmentTargetName :: Text
$sel:assessmentTargetName:CreateAssessmentTarget' :: CreateAssessmentTarget -> Text
assessmentTargetName} -> Text
assessmentTargetName) (\s :: CreateAssessmentTarget
s@CreateAssessmentTarget' {} Text
a -> CreateAssessmentTarget
s {$sel:assessmentTargetName:CreateAssessmentTarget' :: Text
assessmentTargetName = Text
a} :: CreateAssessmentTarget)

instance Core.AWSRequest CreateAssessmentTarget where
  type
    AWSResponse CreateAssessmentTarget =
      CreateAssessmentTargetResponse
  request :: CreateAssessmentTarget -> Request CreateAssessmentTarget
request = Service -> CreateAssessmentTarget -> Request CreateAssessmentTarget
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateAssessmentTarget
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAssessmentTarget)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateAssessmentTarget))
-> Logger
-> Service
-> Proxy CreateAssessmentTarget
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateAssessmentTarget)))
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 -> CreateAssessmentTargetResponse
CreateAssessmentTargetResponse'
            (Int -> Text -> CreateAssessmentTargetResponse)
-> Either String Int
-> Either String (Text -> CreateAssessmentTargetResponse)
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 -> CreateAssessmentTargetResponse)
-> Either String Text
-> Either String CreateAssessmentTargetResponse
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
"assessmentTargetArn")
      )

instance Prelude.Hashable CreateAssessmentTarget

instance Prelude.NFData CreateAssessmentTarget

instance Core.ToHeaders CreateAssessmentTarget where
  toHeaders :: CreateAssessmentTarget -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateAssessmentTarget -> 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.CreateAssessmentTarget" ::
                          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 CreateAssessmentTarget where
  toJSON :: CreateAssessmentTarget -> Value
toJSON CreateAssessmentTarget' {Maybe Text
Text
assessmentTargetName :: Text
resourceGroupArn :: Maybe Text
$sel:assessmentTargetName:CreateAssessmentTarget' :: CreateAssessmentTarget -> Text
$sel:resourceGroupArn:CreateAssessmentTarget' :: CreateAssessmentTarget -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"resourceGroupArn" 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
resourceGroupArn,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"assessmentTargetName"
                  Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
assessmentTargetName
              )
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateAssessmentTargetResponse' 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', 'createAssessmentTargetResponse_httpStatus' - The response's http status code.
--
-- 'assessmentTargetArn', 'createAssessmentTargetResponse_assessmentTargetArn' - The ARN that specifies the assessment target that is created.
newCreateAssessmentTargetResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'assessmentTargetArn'
  Prelude.Text ->
  CreateAssessmentTargetResponse
newCreateAssessmentTargetResponse :: Int -> Text -> CreateAssessmentTargetResponse
newCreateAssessmentTargetResponse
  Int
pHttpStatus_
  Text
pAssessmentTargetArn_ =
    CreateAssessmentTargetResponse' :: Int -> Text -> CreateAssessmentTargetResponse
CreateAssessmentTargetResponse'
      { $sel:httpStatus:CreateAssessmentTargetResponse' :: Int
httpStatus =
          Int
pHttpStatus_,
        $sel:assessmentTargetArn:CreateAssessmentTargetResponse' :: Text
assessmentTargetArn = Text
pAssessmentTargetArn_
      }

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

-- | The ARN that specifies the assessment target that is created.
createAssessmentTargetResponse_assessmentTargetArn :: Lens.Lens' CreateAssessmentTargetResponse Prelude.Text
createAssessmentTargetResponse_assessmentTargetArn :: (Text -> f Text)
-> CreateAssessmentTargetResponse
-> f CreateAssessmentTargetResponse
createAssessmentTargetResponse_assessmentTargetArn = (CreateAssessmentTargetResponse -> Text)
-> (CreateAssessmentTargetResponse
    -> Text -> CreateAssessmentTargetResponse)
-> Lens
     CreateAssessmentTargetResponse
     CreateAssessmentTargetResponse
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateAssessmentTargetResponse' {Text
assessmentTargetArn :: Text
$sel:assessmentTargetArn:CreateAssessmentTargetResponse' :: CreateAssessmentTargetResponse -> Text
assessmentTargetArn} -> Text
assessmentTargetArn) (\s :: CreateAssessmentTargetResponse
s@CreateAssessmentTargetResponse' {} Text
a -> CreateAssessmentTargetResponse
s {$sel:assessmentTargetArn:CreateAssessmentTargetResponse' :: Text
assessmentTargetArn = Text
a} :: CreateAssessmentTargetResponse)

instance
  Prelude.NFData
    CreateAssessmentTargetResponse