{-# 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.MQ.CreateUser
-- 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 ActiveMQ user.
module Amazonka.MQ.CreateUser
  ( -- * Creating a Request
    CreateUser (..),
    newCreateUser,

    -- * Request Lenses
    createUser_groups,
    createUser_consoleAccess,
    createUser_username,
    createUser_brokerId,
    createUser_password,

    -- * Destructuring the Response
    CreateUserResponse (..),
    newCreateUserResponse,

    -- * Response Lenses
    createUserResponse_httpStatus,
  )
where

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

-- | Creates a new ActiveMQ user.
--
-- /See:/ 'newCreateUser' smart constructor.
data CreateUser = CreateUser'
  { -- | The list of groups (20 maximum) to which the ActiveMQ user belongs. This
    -- value can contain only alphanumeric characters, dashes, periods,
    -- underscores, and tildes (- . _ ~). This value must be 2-100 characters
    -- long.
    CreateUser -> Maybe [Text]
groups :: Prelude.Maybe [Prelude.Text],
    -- | Enables access to the ActiveMQ Web Console for the ActiveMQ user.
    CreateUser -> Maybe Bool
consoleAccess :: Prelude.Maybe Prelude.Bool,
    -- | The username of the ActiveMQ user. This value can contain only
    -- alphanumeric characters, dashes, periods, underscores, and tildes (- . _
    -- ~). This value must be 2-100 characters long.
    CreateUser -> Text
username :: Prelude.Text,
    -- | The unique ID that Amazon MQ generates for the broker.
    CreateUser -> Text
brokerId :: Prelude.Text,
    -- | Required. The password of the user. This value must be at least 12
    -- characters long, must contain at least 4 unique characters, and must not
    -- contain commas, colons, or equal signs (,:=).
    CreateUser -> Text
password :: Prelude.Text
  }
  deriving (CreateUser -> CreateUser -> Bool
(CreateUser -> CreateUser -> Bool)
-> (CreateUser -> CreateUser -> Bool) -> Eq CreateUser
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateUser -> CreateUser -> Bool
$c/= :: CreateUser -> CreateUser -> Bool
== :: CreateUser -> CreateUser -> Bool
$c== :: CreateUser -> CreateUser -> Bool
Prelude.Eq, ReadPrec [CreateUser]
ReadPrec CreateUser
Int -> ReadS CreateUser
ReadS [CreateUser]
(Int -> ReadS CreateUser)
-> ReadS [CreateUser]
-> ReadPrec CreateUser
-> ReadPrec [CreateUser]
-> Read CreateUser
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateUser]
$creadListPrec :: ReadPrec [CreateUser]
readPrec :: ReadPrec CreateUser
$creadPrec :: ReadPrec CreateUser
readList :: ReadS [CreateUser]
$creadList :: ReadS [CreateUser]
readsPrec :: Int -> ReadS CreateUser
$creadsPrec :: Int -> ReadS CreateUser
Prelude.Read, Int -> CreateUser -> ShowS
[CreateUser] -> ShowS
CreateUser -> String
(Int -> CreateUser -> ShowS)
-> (CreateUser -> String)
-> ([CreateUser] -> ShowS)
-> Show CreateUser
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateUser] -> ShowS
$cshowList :: [CreateUser] -> ShowS
show :: CreateUser -> String
$cshow :: CreateUser -> String
showsPrec :: Int -> CreateUser -> ShowS
$cshowsPrec :: Int -> CreateUser -> ShowS
Prelude.Show, (forall x. CreateUser -> Rep CreateUser x)
-> (forall x. Rep CreateUser x -> CreateUser) -> Generic CreateUser
forall x. Rep CreateUser x -> CreateUser
forall x. CreateUser -> Rep CreateUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateUser x -> CreateUser
$cfrom :: forall x. CreateUser -> Rep CreateUser x
Prelude.Generic)

-- |
-- Create a value of 'CreateUser' 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:
--
-- 'groups', 'createUser_groups' - The list of groups (20 maximum) to which the ActiveMQ user belongs. This
-- value can contain only alphanumeric characters, dashes, periods,
-- underscores, and tildes (- . _ ~). This value must be 2-100 characters
-- long.
--
-- 'consoleAccess', 'createUser_consoleAccess' - Enables access to the ActiveMQ Web Console for the ActiveMQ user.
--
-- 'username', 'createUser_username' - The username of the ActiveMQ user. This value can contain only
-- alphanumeric characters, dashes, periods, underscores, and tildes (- . _
-- ~). This value must be 2-100 characters long.
--
-- 'brokerId', 'createUser_brokerId' - The unique ID that Amazon MQ generates for the broker.
--
-- 'password', 'createUser_password' - Required. The password of the user. This value must be at least 12
-- characters long, must contain at least 4 unique characters, and must not
-- contain commas, colons, or equal signs (,:=).
newCreateUser ::
  -- | 'username'
  Prelude.Text ->
  -- | 'brokerId'
  Prelude.Text ->
  -- | 'password'
  Prelude.Text ->
  CreateUser
newCreateUser :: Text -> Text -> Text -> CreateUser
newCreateUser Text
pUsername_ Text
pBrokerId_ Text
pPassword_ =
  CreateUser' :: Maybe [Text] -> Maybe Bool -> Text -> Text -> Text -> CreateUser
CreateUser'
    { $sel:groups:CreateUser' :: Maybe [Text]
groups = Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:consoleAccess:CreateUser' :: Maybe Bool
consoleAccess = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:username:CreateUser' :: Text
username = Text
pUsername_,
      $sel:brokerId:CreateUser' :: Text
brokerId = Text
pBrokerId_,
      $sel:password:CreateUser' :: Text
password = Text
pPassword_
    }

-- | The list of groups (20 maximum) to which the ActiveMQ user belongs. This
-- value can contain only alphanumeric characters, dashes, periods,
-- underscores, and tildes (- . _ ~). This value must be 2-100 characters
-- long.
createUser_groups :: Lens.Lens' CreateUser (Prelude.Maybe [Prelude.Text])
createUser_groups :: (Maybe [Text] -> f (Maybe [Text])) -> CreateUser -> f CreateUser
createUser_groups = (CreateUser -> Maybe [Text])
-> (CreateUser -> Maybe [Text] -> CreateUser)
-> Lens CreateUser CreateUser (Maybe [Text]) (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUser' {Maybe [Text]
groups :: Maybe [Text]
$sel:groups:CreateUser' :: CreateUser -> Maybe [Text]
groups} -> Maybe [Text]
groups) (\s :: CreateUser
s@CreateUser' {} Maybe [Text]
a -> CreateUser
s {$sel:groups:CreateUser' :: Maybe [Text]
groups = Maybe [Text]
a} :: CreateUser) ((Maybe [Text] -> f (Maybe [Text])) -> CreateUser -> f CreateUser)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> CreateUser
-> f CreateUser
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [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 [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Enables access to the ActiveMQ Web Console for the ActiveMQ user.
createUser_consoleAccess :: Lens.Lens' CreateUser (Prelude.Maybe Prelude.Bool)
createUser_consoleAccess :: (Maybe Bool -> f (Maybe Bool)) -> CreateUser -> f CreateUser
createUser_consoleAccess = (CreateUser -> Maybe Bool)
-> (CreateUser -> Maybe Bool -> CreateUser)
-> Lens CreateUser CreateUser (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUser' {Maybe Bool
consoleAccess :: Maybe Bool
$sel:consoleAccess:CreateUser' :: CreateUser -> Maybe Bool
consoleAccess} -> Maybe Bool
consoleAccess) (\s :: CreateUser
s@CreateUser' {} Maybe Bool
a -> CreateUser
s {$sel:consoleAccess:CreateUser' :: Maybe Bool
consoleAccess = Maybe Bool
a} :: CreateUser)

-- | The username of the ActiveMQ user. This value can contain only
-- alphanumeric characters, dashes, periods, underscores, and tildes (- . _
-- ~). This value must be 2-100 characters long.
createUser_username :: Lens.Lens' CreateUser Prelude.Text
createUser_username :: (Text -> f Text) -> CreateUser -> f CreateUser
createUser_username = (CreateUser -> Text)
-> (CreateUser -> Text -> CreateUser)
-> Lens CreateUser CreateUser Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUser' {Text
username :: Text
$sel:username:CreateUser' :: CreateUser -> Text
username} -> Text
username) (\s :: CreateUser
s@CreateUser' {} Text
a -> CreateUser
s {$sel:username:CreateUser' :: Text
username = Text
a} :: CreateUser)

-- | The unique ID that Amazon MQ generates for the broker.
createUser_brokerId :: Lens.Lens' CreateUser Prelude.Text
createUser_brokerId :: (Text -> f Text) -> CreateUser -> f CreateUser
createUser_brokerId = (CreateUser -> Text)
-> (CreateUser -> Text -> CreateUser)
-> Lens CreateUser CreateUser Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUser' {Text
brokerId :: Text
$sel:brokerId:CreateUser' :: CreateUser -> Text
brokerId} -> Text
brokerId) (\s :: CreateUser
s@CreateUser' {} Text
a -> CreateUser
s {$sel:brokerId:CreateUser' :: Text
brokerId = Text
a} :: CreateUser)

-- | Required. The password of the user. This value must be at least 12
-- characters long, must contain at least 4 unique characters, and must not
-- contain commas, colons, or equal signs (,:=).
createUser_password :: Lens.Lens' CreateUser Prelude.Text
createUser_password :: (Text -> f Text) -> CreateUser -> f CreateUser
createUser_password = (CreateUser -> Text)
-> (CreateUser -> Text -> CreateUser)
-> Lens CreateUser CreateUser Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateUser' {Text
password :: Text
$sel:password:CreateUser' :: CreateUser -> Text
password} -> Text
password) (\s :: CreateUser
s@CreateUser' {} Text
a -> CreateUser
s {$sel:password:CreateUser' :: Text
password = Text
a} :: CreateUser)

instance Core.AWSRequest CreateUser where
  type AWSResponse CreateUser = CreateUserResponse
  request :: CreateUser -> Request CreateUser
request = Service -> CreateUser -> Request CreateUser
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateUser)))
response =
    (Int
 -> ResponseHeaders -> () -> Either String (AWSResponse CreateUser))
-> Logger
-> Service
-> Proxy CreateUser
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateUser)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> () -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveEmpty
      ( \Int
s ResponseHeaders
h ()
x ->
          Int -> CreateUserResponse
CreateUserResponse'
            (Int -> CreateUserResponse)
-> Either String Int -> Either String CreateUserResponse
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))
      )

instance Prelude.Hashable CreateUser

instance Prelude.NFData CreateUser

instance Core.ToHeaders CreateUser where
  toHeaders :: CreateUser -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateUser -> 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 CreateUser where
  toJSON :: CreateUser -> Value
toJSON CreateUser' {Maybe Bool
Maybe [Text]
Text
password :: Text
brokerId :: Text
username :: Text
consoleAccess :: Maybe Bool
groups :: Maybe [Text]
$sel:password:CreateUser' :: CreateUser -> Text
$sel:brokerId:CreateUser' :: CreateUser -> Text
$sel:username:CreateUser' :: CreateUser -> Text
$sel:consoleAccess:CreateUser' :: CreateUser -> Maybe Bool
$sel:groups:CreateUser' :: CreateUser -> Maybe [Text]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"groups" 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]
groups,
            (Text
"consoleAccess" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
consoleAccess,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"password" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
password)
          ]
      )

instance Core.ToPath CreateUser where
  toPath :: CreateUser -> ByteString
toPath CreateUser' {Maybe Bool
Maybe [Text]
Text
password :: Text
brokerId :: Text
username :: Text
consoleAccess :: Maybe Bool
groups :: Maybe [Text]
$sel:password:CreateUser' :: CreateUser -> Text
$sel:brokerId:CreateUser' :: CreateUser -> Text
$sel:username:CreateUser' :: CreateUser -> Text
$sel:consoleAccess:CreateUser' :: CreateUser -> Maybe Bool
$sel:groups:CreateUser' :: CreateUser -> Maybe [Text]
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/v1/brokers/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
brokerId,
        ByteString
"/users/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
username
      ]

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

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

-- |
-- Create a value of 'CreateUserResponse' 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', 'createUserResponse_httpStatus' - The response's http status code.
newCreateUserResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateUserResponse
newCreateUserResponse :: Int -> CreateUserResponse
newCreateUserResponse Int
pHttpStatus_ =
  CreateUserResponse' :: Int -> CreateUserResponse
CreateUserResponse' {$sel:httpStatus:CreateUserResponse' :: Int
httpStatus = Int
pHttpStatus_}

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

instance Prelude.NFData CreateUserResponse