{-# 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-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 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 Amazonka.Detective.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:/ '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
(CreateGraph -> CreateGraph -> Bool)
-> (CreateGraph -> CreateGraph -> Bool) -> Eq CreateGraph
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]
(Int -> ReadS CreateGraph)
-> ReadS [CreateGraph]
-> ReadPrec CreateGraph
-> ReadPrec [CreateGraph]
-> Read 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
(Int -> CreateGraph -> ShowS)
-> (CreateGraph -> String)
-> ([CreateGraph] -> ShowS)
-> Show CreateGraph
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. CreateGraph -> Rep CreateGraph x)
-> (forall x. Rep CreateGraph x -> CreateGraph)
-> Generic CreateGraph
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' :: Maybe (HashMap Text Text) -> CreateGraph
CreateGraph' {$sel:tags:CreateGraph' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
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 :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateGraph -> f CreateGraph
createGraph_tags = (CreateGraph -> Maybe (HashMap Text Text))
-> (CreateGraph -> Maybe (HashMap Text Text) -> CreateGraph)
-> Lens
     CreateGraph
     CreateGraph
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreateGraph -> f CreateGraph)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateGraph
-> f CreateGraph
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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 AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
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 :: CreateGraph -> Request CreateGraph
request = Service -> CreateGraph -> Request CreateGraph
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateGraph
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateGraph)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateGraph))
-> Logger
-> Service
-> Proxy CreateGraph
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateGraph)))
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 -> CreateGraphResponse
CreateGraphResponse'
            (Maybe Text -> Int -> CreateGraphResponse)
-> Either String (Maybe Text)
-> Either String (Int -> CreateGraphResponse)
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
"GraphArn")
            Either String (Int -> CreateGraphResponse)
-> Either String Int -> Either String CreateGraphResponse
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 CreateGraph

instance Prelude.NFData CreateGraph

instance Core.ToHeaders CreateGraph where
  toHeaders :: CreateGraph -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateGraph -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Text -> Pair)
-> Maybe (HashMap Text Text) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
tags]
      )

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

instance Core.ToQuery CreateGraph where
  toQuery :: CreateGraph -> QueryString
toQuery = QueryString -> CreateGraph -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
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
(CreateGraphResponse -> CreateGraphResponse -> Bool)
-> (CreateGraphResponse -> CreateGraphResponse -> Bool)
-> Eq CreateGraphResponse
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]
(Int -> ReadS CreateGraphResponse)
-> ReadS [CreateGraphResponse]
-> ReadPrec CreateGraphResponse
-> ReadPrec [CreateGraphResponse]
-> Read 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
(Int -> CreateGraphResponse -> ShowS)
-> (CreateGraphResponse -> String)
-> ([CreateGraphResponse] -> ShowS)
-> Show CreateGraphResponse
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. CreateGraphResponse -> Rep CreateGraphResponse x)
-> (forall x. Rep CreateGraphResponse x -> CreateGraphResponse)
-> Generic CreateGraphResponse
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' :: Maybe Text -> Int -> CreateGraphResponse
CreateGraphResponse'
    { $sel:graphArn:CreateGraphResponse' :: Maybe Text
graphArn = Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> CreateGraphResponse -> f CreateGraphResponse
createGraphResponse_graphArn = (CreateGraphResponse -> Maybe Text)
-> (CreateGraphResponse -> Maybe Text -> CreateGraphResponse)
-> Lens
     CreateGraphResponse CreateGraphResponse (Maybe Text) (Maybe Text)
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 :: (Int -> f Int) -> CreateGraphResponse -> f CreateGraphResponse
createGraphResponse_httpStatus = (CreateGraphResponse -> Int)
-> (CreateGraphResponse -> Int -> CreateGraphResponse)
-> Lens CreateGraphResponse CreateGraphResponse Int Int
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