{-# 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.Detective.CreateGraph
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Creates a new behavior graph for the calling account, and sets that
-- account as the administrator account. This operation is called by the
-- account that is enabling Detective.
--
-- Before you try to enable Detective, make sure that your account has been
-- enrolled in Amazon GuardDuty for at least 48 hours. If you do not meet
-- this requirement, you cannot enable Detective. If you do meet the
-- GuardDuty prerequisite, then when you make the request to enable
-- Detective, it checks whether your data volume is within the Detective
-- quota. If it exceeds the quota, then you cannot enable Detective.
--
-- The operation also enables Detective for the calling account in the
-- currently selected Region. It returns the ARN of the new behavior graph.
--
-- @CreateGraph@ triggers a process to create the corresponding data tables
-- for the new behavior graph.
--
-- An account can only be the administrator account for one behavior graph
-- within a Region. If the same account calls @CreateGraph@ with the same
-- administrator account, it always returns the same behavior graph ARN. It
-- does not create a new behavior graph.
module Amazonka.Detective.CreateGraph
  ( -- * Creating a Request
    CreateGraph (..),
    newCreateGraph,

    -- * Request Lenses
    createGraph_tags,

    -- * Destructuring the Response
    CreateGraphResponse (..),
    newCreateGraphResponse,

    -- * Response Lenses
    createGraphResponse_graphArn,
    createGraphResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateGraph' smart constructor.
data CreateGraph = CreateGraph'
  { -- | The tags to assign to the new behavior graph. You can add up to 50 tags.
    -- For each tag, you provide the tag key and the tag value. Each tag key
    -- can contain up to 128 characters. Each tag value can contain up to 256
    -- characters.
    CreateGraph -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (CreateGraph -> CreateGraph -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateGraph -> CreateGraph -> Bool
$c/= :: CreateGraph -> CreateGraph -> Bool
== :: CreateGraph -> CreateGraph -> Bool
$c== :: CreateGraph -> CreateGraph -> Bool
Prelude.Eq, ReadPrec [CreateGraph]
ReadPrec CreateGraph
Int -> ReadS CreateGraph
ReadS [CreateGraph]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateGraph]
$creadListPrec :: ReadPrec [CreateGraph]
readPrec :: ReadPrec CreateGraph
$creadPrec :: ReadPrec CreateGraph
readList :: ReadS [CreateGraph]
$creadList :: ReadS [CreateGraph]
readsPrec :: Int -> ReadS CreateGraph
$creadsPrec :: Int -> ReadS CreateGraph
Prelude.Read, Int -> CreateGraph -> ShowS
[CreateGraph] -> ShowS
CreateGraph -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateGraph] -> ShowS
$cshowList :: [CreateGraph] -> ShowS
show :: CreateGraph -> String
$cshow :: CreateGraph -> String
showsPrec :: Int -> CreateGraph -> ShowS
$cshowsPrec :: Int -> CreateGraph -> ShowS
Prelude.Show, forall x. Rep CreateGraph x -> CreateGraph
forall x. CreateGraph -> Rep CreateGraph x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateGraph x -> CreateGraph
$cfrom :: forall x. CreateGraph -> Rep CreateGraph x
Prelude.Generic)

-- |
-- Create a value of 'CreateGraph' 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:
--
-- 'tags', 'createGraph_tags' - The tags to assign to the new behavior graph. You can add up to 50 tags.
-- For each tag, you provide the tag key and the tag value. Each tag key
-- can contain up to 128 characters. Each tag value can contain up to 256
-- characters.
newCreateGraph ::
  CreateGraph
newCreateGraph :: CreateGraph
newCreateGraph = CreateGraph' {$sel:tags:CreateGraph' :: Maybe (HashMap Text Text)
tags = forall a. Maybe a
Prelude.Nothing}

-- | The tags to assign to the new behavior graph. You can add up to 50 tags.
-- For each tag, you provide the tag key and the tag value. Each tag key
-- can contain up to 128 characters. Each tag value can contain up to 256
-- characters.
createGraph_tags :: Lens.Lens' CreateGraph (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createGraph_tags :: Lens' CreateGraph (Maybe (HashMap Text Text))
createGraph_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGraph' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateGraph' :: CreateGraph -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateGraph
s@CreateGraph' {} Maybe (HashMap Text Text)
a -> CreateGraph
s {$sel:tags:CreateGraph' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateGraph) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest CreateGraph where
  type AWSResponse CreateGraph = CreateGraphResponse
  request :: (Service -> Service) -> CreateGraph -> Request CreateGraph
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 CreateGraph
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateGraph)))
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 ->
          Maybe Text -> Int -> CreateGraphResponse
CreateGraphResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"GraphArn")
            forall (f :: * -> *) a b. Applicative f => 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))
      )

instance Prelude.Hashable CreateGraph where
  hashWithSalt :: Int -> CreateGraph -> Int
hashWithSalt Int
_salt CreateGraph' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateGraph' :: CreateGraph -> Maybe (HashMap Text Text)
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
tags

instance Prelude.NFData CreateGraph where
  rnf :: CreateGraph -> ()
rnf CreateGraph' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateGraph' :: CreateGraph -> Maybe (HashMap Text Text)
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
tags

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

instance Data.ToJSON CreateGraph where
  toJSON :: CreateGraph -> Value
toJSON CreateGraph' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateGraph' :: CreateGraph -> Maybe (HashMap Text Text)
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"Tags" 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 (HashMap Text Text)
tags]
      )

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

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

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

-- |
-- Create a value of 'CreateGraphResponse' 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:
--
-- 'graphArn', 'createGraphResponse_graphArn' - The ARN of the new behavior graph.
--
-- 'httpStatus', 'createGraphResponse_httpStatus' - The response's http status code.
newCreateGraphResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateGraphResponse
newCreateGraphResponse :: Int -> CreateGraphResponse
newCreateGraphResponse Int
pHttpStatus_ =
  CreateGraphResponse'
    { $sel:graphArn:CreateGraphResponse' :: Maybe Text
graphArn = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateGraphResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The ARN of the new behavior graph.
createGraphResponse_graphArn :: Lens.Lens' CreateGraphResponse (Prelude.Maybe Prelude.Text)
createGraphResponse_graphArn :: Lens' CreateGraphResponse (Maybe Text)
createGraphResponse_graphArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateGraphResponse' {Maybe Text
graphArn :: Maybe Text
$sel:graphArn:CreateGraphResponse' :: CreateGraphResponse -> Maybe Text
graphArn} -> Maybe Text
graphArn) (\s :: CreateGraphResponse
s@CreateGraphResponse' {} Maybe Text
a -> CreateGraphResponse
s {$sel:graphArn:CreateGraphResponse' :: Maybe Text
graphArn = Maybe Text
a} :: CreateGraphResponse)

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

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