{-# 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.AccessAnalyzer.CreateArchiveRule
-- 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 an archive rule for the specified analyzer. Archive rules
-- automatically archive new findings that meet the criteria you define
-- when you create the rule.
--
-- To learn about filter keys that you can use to create an archive rule,
-- see
-- <https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-reference-filter-keys.html IAM Access Analyzer filter keys>
-- in the __IAM User Guide__.
module Amazonka.AccessAnalyzer.CreateArchiveRule
  ( -- * Creating a Request
    CreateArchiveRule (..),
    newCreateArchiveRule,

    -- * Request Lenses
    createArchiveRule_clientToken,
    createArchiveRule_analyzerName,
    createArchiveRule_filter,
    createArchiveRule_ruleName,

    -- * Destructuring the Response
    CreateArchiveRuleResponse (..),
    newCreateArchiveRuleResponse,
  )
where

import Amazonka.AccessAnalyzer.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Creates an archive rule.
--
-- /See:/ 'newCreateArchiveRule' smart constructor.
data CreateArchiveRule = CreateArchiveRule'
  { -- | A client token.
    CreateArchiveRule -> Maybe Text
clientToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the created analyzer.
    CreateArchiveRule -> Text
analyzerName :: Prelude.Text,
    -- | The criteria for the rule.
    CreateArchiveRule -> HashMap Text Criterion
filter' :: Prelude.HashMap Prelude.Text Criterion,
    -- | The name of the rule to create.
    CreateArchiveRule -> Text
ruleName :: Prelude.Text
  }
  deriving (CreateArchiveRule -> CreateArchiveRule -> Bool
(CreateArchiveRule -> CreateArchiveRule -> Bool)
-> (CreateArchiveRule -> CreateArchiveRule -> Bool)
-> Eq CreateArchiveRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateArchiveRule -> CreateArchiveRule -> Bool
$c/= :: CreateArchiveRule -> CreateArchiveRule -> Bool
== :: CreateArchiveRule -> CreateArchiveRule -> Bool
$c== :: CreateArchiveRule -> CreateArchiveRule -> Bool
Prelude.Eq, ReadPrec [CreateArchiveRule]
ReadPrec CreateArchiveRule
Int -> ReadS CreateArchiveRule
ReadS [CreateArchiveRule]
(Int -> ReadS CreateArchiveRule)
-> ReadS [CreateArchiveRule]
-> ReadPrec CreateArchiveRule
-> ReadPrec [CreateArchiveRule]
-> Read CreateArchiveRule
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateArchiveRule]
$creadListPrec :: ReadPrec [CreateArchiveRule]
readPrec :: ReadPrec CreateArchiveRule
$creadPrec :: ReadPrec CreateArchiveRule
readList :: ReadS [CreateArchiveRule]
$creadList :: ReadS [CreateArchiveRule]
readsPrec :: Int -> ReadS CreateArchiveRule
$creadsPrec :: Int -> ReadS CreateArchiveRule
Prelude.Read, Int -> CreateArchiveRule -> ShowS
[CreateArchiveRule] -> ShowS
CreateArchiveRule -> String
(Int -> CreateArchiveRule -> ShowS)
-> (CreateArchiveRule -> String)
-> ([CreateArchiveRule] -> ShowS)
-> Show CreateArchiveRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateArchiveRule] -> ShowS
$cshowList :: [CreateArchiveRule] -> ShowS
show :: CreateArchiveRule -> String
$cshow :: CreateArchiveRule -> String
showsPrec :: Int -> CreateArchiveRule -> ShowS
$cshowsPrec :: Int -> CreateArchiveRule -> ShowS
Prelude.Show, (forall x. CreateArchiveRule -> Rep CreateArchiveRule x)
-> (forall x. Rep CreateArchiveRule x -> CreateArchiveRule)
-> Generic CreateArchiveRule
forall x. Rep CreateArchiveRule x -> CreateArchiveRule
forall x. CreateArchiveRule -> Rep CreateArchiveRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateArchiveRule x -> CreateArchiveRule
$cfrom :: forall x. CreateArchiveRule -> Rep CreateArchiveRule x
Prelude.Generic)

-- |
-- Create a value of 'CreateArchiveRule' 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:
--
-- 'clientToken', 'createArchiveRule_clientToken' - A client token.
--
-- 'analyzerName', 'createArchiveRule_analyzerName' - The name of the created analyzer.
--
-- 'filter'', 'createArchiveRule_filter' - The criteria for the rule.
--
-- 'ruleName', 'createArchiveRule_ruleName' - The name of the rule to create.
newCreateArchiveRule ::
  -- | 'analyzerName'
  Prelude.Text ->
  -- | 'ruleName'
  Prelude.Text ->
  CreateArchiveRule
newCreateArchiveRule :: Text -> Text -> CreateArchiveRule
newCreateArchiveRule Text
pAnalyzerName_ Text
pRuleName_ =
  CreateArchiveRule' :: Maybe Text
-> Text -> HashMap Text Criterion -> Text -> CreateArchiveRule
CreateArchiveRule'
    { $sel:clientToken:CreateArchiveRule' :: Maybe Text
clientToken = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:analyzerName:CreateArchiveRule' :: Text
analyzerName = Text
pAnalyzerName_,
      $sel:filter':CreateArchiveRule' :: HashMap Text Criterion
filter' = HashMap Text Criterion
forall a. Monoid a => a
Prelude.mempty,
      $sel:ruleName:CreateArchiveRule' :: Text
ruleName = Text
pRuleName_
    }

-- | A client token.
createArchiveRule_clientToken :: Lens.Lens' CreateArchiveRule (Prelude.Maybe Prelude.Text)
createArchiveRule_clientToken :: (Maybe Text -> f (Maybe Text))
-> CreateArchiveRule -> f CreateArchiveRule
createArchiveRule_clientToken = (CreateArchiveRule -> Maybe Text)
-> (CreateArchiveRule -> Maybe Text -> CreateArchiveRule)
-> Lens
     CreateArchiveRule CreateArchiveRule (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateArchiveRule' {Maybe Text
clientToken :: Maybe Text
$sel:clientToken:CreateArchiveRule' :: CreateArchiveRule -> Maybe Text
clientToken} -> Maybe Text
clientToken) (\s :: CreateArchiveRule
s@CreateArchiveRule' {} Maybe Text
a -> CreateArchiveRule
s {$sel:clientToken:CreateArchiveRule' :: Maybe Text
clientToken = Maybe Text
a} :: CreateArchiveRule)

-- | The name of the created analyzer.
createArchiveRule_analyzerName :: Lens.Lens' CreateArchiveRule Prelude.Text
createArchiveRule_analyzerName :: (Text -> f Text) -> CreateArchiveRule -> f CreateArchiveRule
createArchiveRule_analyzerName = (CreateArchiveRule -> Text)
-> (CreateArchiveRule -> Text -> CreateArchiveRule)
-> Lens CreateArchiveRule CreateArchiveRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateArchiveRule' {Text
analyzerName :: Text
$sel:analyzerName:CreateArchiveRule' :: CreateArchiveRule -> Text
analyzerName} -> Text
analyzerName) (\s :: CreateArchiveRule
s@CreateArchiveRule' {} Text
a -> CreateArchiveRule
s {$sel:analyzerName:CreateArchiveRule' :: Text
analyzerName = Text
a} :: CreateArchiveRule)

-- | The criteria for the rule.
createArchiveRule_filter :: Lens.Lens' CreateArchiveRule (Prelude.HashMap Prelude.Text Criterion)
createArchiveRule_filter :: (HashMap Text Criterion -> f (HashMap Text Criterion))
-> CreateArchiveRule -> f CreateArchiveRule
createArchiveRule_filter = (CreateArchiveRule -> HashMap Text Criterion)
-> (CreateArchiveRule
    -> HashMap Text Criterion -> CreateArchiveRule)
-> Lens
     CreateArchiveRule
     CreateArchiveRule
     (HashMap Text Criterion)
     (HashMap Text Criterion)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateArchiveRule' {HashMap Text Criterion
filter' :: HashMap Text Criterion
$sel:filter':CreateArchiveRule' :: CreateArchiveRule -> HashMap Text Criterion
filter'} -> HashMap Text Criterion
filter') (\s :: CreateArchiveRule
s@CreateArchiveRule' {} HashMap Text Criterion
a -> CreateArchiveRule
s {$sel:filter':CreateArchiveRule' :: HashMap Text Criterion
filter' = HashMap Text Criterion
a} :: CreateArchiveRule) ((HashMap Text Criterion -> f (HashMap Text Criterion))
 -> CreateArchiveRule -> f CreateArchiveRule)
-> ((HashMap Text Criterion -> f (HashMap Text Criterion))
    -> HashMap Text Criterion -> f (HashMap Text Criterion))
-> (HashMap Text Criterion -> f (HashMap Text Criterion))
-> CreateArchiveRule
-> f CreateArchiveRule
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Criterion -> f (HashMap Text Criterion))
-> HashMap Text Criterion -> f (HashMap Text Criterion)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the rule to create.
createArchiveRule_ruleName :: Lens.Lens' CreateArchiveRule Prelude.Text
createArchiveRule_ruleName :: (Text -> f Text) -> CreateArchiveRule -> f CreateArchiveRule
createArchiveRule_ruleName = (CreateArchiveRule -> Text)
-> (CreateArchiveRule -> Text -> CreateArchiveRule)
-> Lens CreateArchiveRule CreateArchiveRule Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateArchiveRule' {Text
ruleName :: Text
$sel:ruleName:CreateArchiveRule' :: CreateArchiveRule -> Text
ruleName} -> Text
ruleName) (\s :: CreateArchiveRule
s@CreateArchiveRule' {} Text
a -> CreateArchiveRule
s {$sel:ruleName:CreateArchiveRule' :: Text
ruleName = Text
a} :: CreateArchiveRule)

instance Core.AWSRequest CreateArchiveRule where
  type
    AWSResponse CreateArchiveRule =
      CreateArchiveRuleResponse
  request :: CreateArchiveRule -> Request CreateArchiveRule
request = Service -> CreateArchiveRule -> Request CreateArchiveRule
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateArchiveRule
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateArchiveRule)))
response =
    AWSResponse CreateArchiveRule
-> Logger
-> Service
-> Proxy CreateArchiveRule
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateArchiveRule)))
forall (m :: * -> *) a.
MonadResource m =>
AWSResponse a
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveNull AWSResponse CreateArchiveRule
CreateArchiveRuleResponse
CreateArchiveRuleResponse'

instance Prelude.Hashable CreateArchiveRule

instance Prelude.NFData CreateArchiveRule

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

instance Core.ToJSON CreateArchiveRule where
  toJSON :: CreateArchiveRule -> Value
toJSON CreateArchiveRule' {Maybe Text
Text
HashMap Text Criterion
ruleName :: Text
filter' :: HashMap Text Criterion
analyzerName :: Text
clientToken :: Maybe Text
$sel:ruleName:CreateArchiveRule' :: CreateArchiveRule -> Text
$sel:filter':CreateArchiveRule' :: CreateArchiveRule -> HashMap Text Criterion
$sel:analyzerName:CreateArchiveRule' :: CreateArchiveRule -> Text
$sel:clientToken:CreateArchiveRule' :: CreateArchiveRule -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"clientToken" 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
clientToken,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"filter" Text -> HashMap Text Criterion -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Criterion
filter'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"ruleName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
ruleName)
          ]
      )

instance Core.ToPath CreateArchiveRule where
  toPath :: CreateArchiveRule -> ByteString
toPath CreateArchiveRule' {Maybe Text
Text
HashMap Text Criterion
ruleName :: Text
filter' :: HashMap Text Criterion
analyzerName :: Text
clientToken :: Maybe Text
$sel:ruleName:CreateArchiveRule' :: CreateArchiveRule -> Text
$sel:filter':CreateArchiveRule' :: CreateArchiveRule -> HashMap Text Criterion
$sel:analyzerName:CreateArchiveRule' :: CreateArchiveRule -> Text
$sel:clientToken:CreateArchiveRule' :: CreateArchiveRule -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/analyzer/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
analyzerName,
        ByteString
"/archive-rule"
      ]

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

-- | /See:/ 'newCreateArchiveRuleResponse' smart constructor.
data CreateArchiveRuleResponse = CreateArchiveRuleResponse'
  {
  }
  deriving (CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool
(CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool)
-> (CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool)
-> Eq CreateArchiveRuleResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool
$c/= :: CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool
== :: CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool
$c== :: CreateArchiveRuleResponse -> CreateArchiveRuleResponse -> Bool
Prelude.Eq, ReadPrec [CreateArchiveRuleResponse]
ReadPrec CreateArchiveRuleResponse
Int -> ReadS CreateArchiveRuleResponse
ReadS [CreateArchiveRuleResponse]
(Int -> ReadS CreateArchiveRuleResponse)
-> ReadS [CreateArchiveRuleResponse]
-> ReadPrec CreateArchiveRuleResponse
-> ReadPrec [CreateArchiveRuleResponse]
-> Read CreateArchiveRuleResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateArchiveRuleResponse]
$creadListPrec :: ReadPrec [CreateArchiveRuleResponse]
readPrec :: ReadPrec CreateArchiveRuleResponse
$creadPrec :: ReadPrec CreateArchiveRuleResponse
readList :: ReadS [CreateArchiveRuleResponse]
$creadList :: ReadS [CreateArchiveRuleResponse]
readsPrec :: Int -> ReadS CreateArchiveRuleResponse
$creadsPrec :: Int -> ReadS CreateArchiveRuleResponse
Prelude.Read, Int -> CreateArchiveRuleResponse -> ShowS
[CreateArchiveRuleResponse] -> ShowS
CreateArchiveRuleResponse -> String
(Int -> CreateArchiveRuleResponse -> ShowS)
-> (CreateArchiveRuleResponse -> String)
-> ([CreateArchiveRuleResponse] -> ShowS)
-> Show CreateArchiveRuleResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateArchiveRuleResponse] -> ShowS
$cshowList :: [CreateArchiveRuleResponse] -> ShowS
show :: CreateArchiveRuleResponse -> String
$cshow :: CreateArchiveRuleResponse -> String
showsPrec :: Int -> CreateArchiveRuleResponse -> ShowS
$cshowsPrec :: Int -> CreateArchiveRuleResponse -> ShowS
Prelude.Show, (forall x.
 CreateArchiveRuleResponse -> Rep CreateArchiveRuleResponse x)
-> (forall x.
    Rep CreateArchiveRuleResponse x -> CreateArchiveRuleResponse)
-> Generic CreateArchiveRuleResponse
forall x.
Rep CreateArchiveRuleResponse x -> CreateArchiveRuleResponse
forall x.
CreateArchiveRuleResponse -> Rep CreateArchiveRuleResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreateArchiveRuleResponse x -> CreateArchiveRuleResponse
$cfrom :: forall x.
CreateArchiveRuleResponse -> Rep CreateArchiveRuleResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateArchiveRuleResponse' 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.
newCreateArchiveRuleResponse ::
  CreateArchiveRuleResponse
newCreateArchiveRuleResponse :: CreateArchiveRuleResponse
newCreateArchiveRuleResponse =
  CreateArchiveRuleResponse
CreateArchiveRuleResponse'

instance Prelude.NFData CreateArchiveRuleResponse