{-# 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.WorkSpaces.CreateIpGroup
-- 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 an IP access control group.
--
-- An IP access control group provides you with the ability to control the
-- IP addresses from which users are allowed to access their WorkSpaces. To
-- specify the CIDR address ranges, add rules to your IP access control
-- group and then associate the group with your directory. You can add
-- rules when you create the group or at any time using AuthorizeIpRules.
--
-- There is a default IP access control group associated with your
-- directory. If you don\'t associate an IP access control group with your
-- directory, the default group is used. The default group includes a
-- default rule that allows users to access their WorkSpaces from anywhere.
-- You cannot modify the default IP access control group for your
-- directory.
module Amazonka.WorkSpaces.CreateIpGroup
  ( -- * Creating a Request
    CreateIpGroup (..),
    newCreateIpGroup,

    -- * Request Lenses
    createIpGroup_groupDesc,
    createIpGroup_tags,
    createIpGroup_userRules,
    createIpGroup_groupName,

    -- * Destructuring the Response
    CreateIpGroupResponse (..),
    newCreateIpGroupResponse,

    -- * Response Lenses
    createIpGroupResponse_groupId,
    createIpGroupResponse_httpStatus,
  )
where

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

-- | /See:/ 'newCreateIpGroup' smart constructor.
data CreateIpGroup = CreateIpGroup'
  { -- | The description of the group.
    CreateIpGroup -> Maybe Text
groupDesc :: Prelude.Maybe Prelude.Text,
    -- | The tags. Each WorkSpaces resource can have a maximum of 50 tags.
    CreateIpGroup -> Maybe [Tag]
tags :: Prelude.Maybe [Tag],
    -- | The rules to add to the group.
    CreateIpGroup -> Maybe [IpRuleItem]
userRules :: Prelude.Maybe [IpRuleItem],
    -- | The name of the group.
    CreateIpGroup -> Text
groupName :: Prelude.Text
  }
  deriving (CreateIpGroup -> CreateIpGroup -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateIpGroup -> CreateIpGroup -> Bool
$c/= :: CreateIpGroup -> CreateIpGroup -> Bool
== :: CreateIpGroup -> CreateIpGroup -> Bool
$c== :: CreateIpGroup -> CreateIpGroup -> Bool
Prelude.Eq, ReadPrec [CreateIpGroup]
ReadPrec CreateIpGroup
Int -> ReadS CreateIpGroup
ReadS [CreateIpGroup]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateIpGroup]
$creadListPrec :: ReadPrec [CreateIpGroup]
readPrec :: ReadPrec CreateIpGroup
$creadPrec :: ReadPrec CreateIpGroup
readList :: ReadS [CreateIpGroup]
$creadList :: ReadS [CreateIpGroup]
readsPrec :: Int -> ReadS CreateIpGroup
$creadsPrec :: Int -> ReadS CreateIpGroup
Prelude.Read, Int -> CreateIpGroup -> ShowS
[CreateIpGroup] -> ShowS
CreateIpGroup -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateIpGroup] -> ShowS
$cshowList :: [CreateIpGroup] -> ShowS
show :: CreateIpGroup -> String
$cshow :: CreateIpGroup -> String
showsPrec :: Int -> CreateIpGroup -> ShowS
$cshowsPrec :: Int -> CreateIpGroup -> ShowS
Prelude.Show, forall x. Rep CreateIpGroup x -> CreateIpGroup
forall x. CreateIpGroup -> Rep CreateIpGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateIpGroup x -> CreateIpGroup
$cfrom :: forall x. CreateIpGroup -> Rep CreateIpGroup x
Prelude.Generic)

-- |
-- Create a value of 'CreateIpGroup' 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:
--
-- 'groupDesc', 'createIpGroup_groupDesc' - The description of the group.
--
-- 'tags', 'createIpGroup_tags' - The tags. Each WorkSpaces resource can have a maximum of 50 tags.
--
-- 'userRules', 'createIpGroup_userRules' - The rules to add to the group.
--
-- 'groupName', 'createIpGroup_groupName' - The name of the group.
newCreateIpGroup ::
  -- | 'groupName'
  Prelude.Text ->
  CreateIpGroup
newCreateIpGroup :: Text -> CreateIpGroup
newCreateIpGroup Text
pGroupName_ =
  CreateIpGroup'
    { $sel:groupDesc:CreateIpGroup' :: Maybe Text
groupDesc = forall a. Maybe a
Prelude.Nothing,
      $sel:tags:CreateIpGroup' :: Maybe [Tag]
tags = forall a. Maybe a
Prelude.Nothing,
      $sel:userRules:CreateIpGroup' :: Maybe [IpRuleItem]
userRules = forall a. Maybe a
Prelude.Nothing,
      $sel:groupName:CreateIpGroup' :: Text
groupName = Text
pGroupName_
    }

-- | The description of the group.
createIpGroup_groupDesc :: Lens.Lens' CreateIpGroup (Prelude.Maybe Prelude.Text)
createIpGroup_groupDesc :: Lens' CreateIpGroup (Maybe Text)
createIpGroup_groupDesc = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIpGroup' {Maybe Text
groupDesc :: Maybe Text
$sel:groupDesc:CreateIpGroup' :: CreateIpGroup -> Maybe Text
groupDesc} -> Maybe Text
groupDesc) (\s :: CreateIpGroup
s@CreateIpGroup' {} Maybe Text
a -> CreateIpGroup
s {$sel:groupDesc:CreateIpGroup' :: Maybe Text
groupDesc = Maybe Text
a} :: CreateIpGroup)

-- | The tags. Each WorkSpaces resource can have a maximum of 50 tags.
createIpGroup_tags :: Lens.Lens' CreateIpGroup (Prelude.Maybe [Tag])
createIpGroup_tags :: Lens' CreateIpGroup (Maybe [Tag])
createIpGroup_tags = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIpGroup' {Maybe [Tag]
tags :: Maybe [Tag]
$sel:tags:CreateIpGroup' :: CreateIpGroup -> Maybe [Tag]
tags} -> Maybe [Tag]
tags) (\s :: CreateIpGroup
s@CreateIpGroup' {} Maybe [Tag]
a -> CreateIpGroup
s {$sel:tags:CreateIpGroup' :: Maybe [Tag]
tags = Maybe [Tag]
a} :: CreateIpGroup) 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

-- | The rules to add to the group.
createIpGroup_userRules :: Lens.Lens' CreateIpGroup (Prelude.Maybe [IpRuleItem])
createIpGroup_userRules :: Lens' CreateIpGroup (Maybe [IpRuleItem])
createIpGroup_userRules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIpGroup' {Maybe [IpRuleItem]
userRules :: Maybe [IpRuleItem]
$sel:userRules:CreateIpGroup' :: CreateIpGroup -> Maybe [IpRuleItem]
userRules} -> Maybe [IpRuleItem]
userRules) (\s :: CreateIpGroup
s@CreateIpGroup' {} Maybe [IpRuleItem]
a -> CreateIpGroup
s {$sel:userRules:CreateIpGroup' :: Maybe [IpRuleItem]
userRules = Maybe [IpRuleItem]
a} :: CreateIpGroup) 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

-- | The name of the group.
createIpGroup_groupName :: Lens.Lens' CreateIpGroup Prelude.Text
createIpGroup_groupName :: Lens' CreateIpGroup Text
createIpGroup_groupName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIpGroup' {Text
groupName :: Text
$sel:groupName:CreateIpGroup' :: CreateIpGroup -> Text
groupName} -> Text
groupName) (\s :: CreateIpGroup
s@CreateIpGroup' {} Text
a -> CreateIpGroup
s {$sel:groupName:CreateIpGroup' :: Text
groupName = Text
a} :: CreateIpGroup)

instance Core.AWSRequest CreateIpGroup where
  type
    AWSResponse CreateIpGroup =
      CreateIpGroupResponse
  request :: (Service -> Service) -> CreateIpGroup -> Request CreateIpGroup
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 CreateIpGroup
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateIpGroup)))
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 -> CreateIpGroupResponse
CreateIpGroupResponse'
            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
"GroupId")
            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 CreateIpGroup where
  hashWithSalt :: Int -> CreateIpGroup -> Int
hashWithSalt Int
_salt CreateIpGroup' {Maybe [IpRuleItem]
Maybe [Tag]
Maybe Text
Text
groupName :: Text
userRules :: Maybe [IpRuleItem]
tags :: Maybe [Tag]
groupDesc :: Maybe Text
$sel:groupName:CreateIpGroup' :: CreateIpGroup -> Text
$sel:userRules:CreateIpGroup' :: CreateIpGroup -> Maybe [IpRuleItem]
$sel:tags:CreateIpGroup' :: CreateIpGroup -> Maybe [Tag]
$sel:groupDesc:CreateIpGroup' :: CreateIpGroup -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
groupDesc
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Tag]
tags
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [IpRuleItem]
userRules
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
groupName

instance Prelude.NFData CreateIpGroup where
  rnf :: CreateIpGroup -> ()
rnf CreateIpGroup' {Maybe [IpRuleItem]
Maybe [Tag]
Maybe Text
Text
groupName :: Text
userRules :: Maybe [IpRuleItem]
tags :: Maybe [Tag]
groupDesc :: Maybe Text
$sel:groupName:CreateIpGroup' :: CreateIpGroup -> Text
$sel:userRules:CreateIpGroup' :: CreateIpGroup -> Maybe [IpRuleItem]
$sel:tags:CreateIpGroup' :: CreateIpGroup -> Maybe [Tag]
$sel:groupDesc:CreateIpGroup' :: CreateIpGroup -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
groupDesc
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Tag]
tags
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [IpRuleItem]
userRules
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
groupName

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

instance Data.ToJSON CreateIpGroup where
  toJSON :: CreateIpGroup -> Value
toJSON CreateIpGroup' {Maybe [IpRuleItem]
Maybe [Tag]
Maybe Text
Text
groupName :: Text
userRules :: Maybe [IpRuleItem]
tags :: Maybe [Tag]
groupDesc :: Maybe Text
$sel:groupName:CreateIpGroup' :: CreateIpGroup -> Text
$sel:userRules:CreateIpGroup' :: CreateIpGroup -> Maybe [IpRuleItem]
$sel:tags:CreateIpGroup' :: CreateIpGroup -> Maybe [Tag]
$sel:groupDesc:CreateIpGroup' :: CreateIpGroup -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"GroupDesc" 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 Text
groupDesc,
            (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 [Tag]
tags,
            (Key
"UserRules" 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 [IpRuleItem]
userRules,
            forall a. a -> Maybe a
Prelude.Just (Key
"GroupName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
groupName)
          ]
      )

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

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

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

-- |
-- Create a value of 'CreateIpGroupResponse' 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:
--
-- 'groupId', 'createIpGroupResponse_groupId' - The identifier of the group.
--
-- 'httpStatus', 'createIpGroupResponse_httpStatus' - The response's http status code.
newCreateIpGroupResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateIpGroupResponse
newCreateIpGroupResponse :: Int -> CreateIpGroupResponse
newCreateIpGroupResponse Int
pHttpStatus_ =
  CreateIpGroupResponse'
    { $sel:groupId:CreateIpGroupResponse' :: Maybe Text
groupId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateIpGroupResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The identifier of the group.
createIpGroupResponse_groupId :: Lens.Lens' CreateIpGroupResponse (Prelude.Maybe Prelude.Text)
createIpGroupResponse_groupId :: Lens' CreateIpGroupResponse (Maybe Text)
createIpGroupResponse_groupId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateIpGroupResponse' {Maybe Text
groupId :: Maybe Text
$sel:groupId:CreateIpGroupResponse' :: CreateIpGroupResponse -> Maybe Text
groupId} -> Maybe Text
groupId) (\s :: CreateIpGroupResponse
s@CreateIpGroupResponse' {} Maybe Text
a -> CreateIpGroupResponse
s {$sel:groupId:CreateIpGroupResponse' :: Maybe Text
groupId = Maybe Text
a} :: CreateIpGroupResponse)

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

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