{-# 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.UpdateRulesOfIpGroup
-- 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)
--
-- Replaces the current rules of the specified IP access control group with
-- the specified rules.
module Amazonka.WorkSpaces.UpdateRulesOfIpGroup
  ( -- * Creating a Request
    UpdateRulesOfIpGroup (..),
    newUpdateRulesOfIpGroup,

    -- * Request Lenses
    updateRulesOfIpGroup_groupId,
    updateRulesOfIpGroup_userRules,

    -- * Destructuring the Response
    UpdateRulesOfIpGroupResponse (..),
    newUpdateRulesOfIpGroupResponse,

    -- * Response Lenses
    updateRulesOfIpGroupResponse_httpStatus,
  )
where

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
import Amazonka.WorkSpaces.Types

-- | /See:/ 'newUpdateRulesOfIpGroup' smart constructor.
data UpdateRulesOfIpGroup = UpdateRulesOfIpGroup'
  { -- | The identifier of the group.
    UpdateRulesOfIpGroup -> Text
groupId :: Prelude.Text,
    -- | One or more rules.
    UpdateRulesOfIpGroup -> [IpRuleItem]
userRules :: [IpRuleItem]
  }
  deriving (UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool
(UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool)
-> (UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool)
-> Eq UpdateRulesOfIpGroup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool
$c/= :: UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool
== :: UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool
$c== :: UpdateRulesOfIpGroup -> UpdateRulesOfIpGroup -> Bool
Prelude.Eq, ReadPrec [UpdateRulesOfIpGroup]
ReadPrec UpdateRulesOfIpGroup
Int -> ReadS UpdateRulesOfIpGroup
ReadS [UpdateRulesOfIpGroup]
(Int -> ReadS UpdateRulesOfIpGroup)
-> ReadS [UpdateRulesOfIpGroup]
-> ReadPrec UpdateRulesOfIpGroup
-> ReadPrec [UpdateRulesOfIpGroup]
-> Read UpdateRulesOfIpGroup
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateRulesOfIpGroup]
$creadListPrec :: ReadPrec [UpdateRulesOfIpGroup]
readPrec :: ReadPrec UpdateRulesOfIpGroup
$creadPrec :: ReadPrec UpdateRulesOfIpGroup
readList :: ReadS [UpdateRulesOfIpGroup]
$creadList :: ReadS [UpdateRulesOfIpGroup]
readsPrec :: Int -> ReadS UpdateRulesOfIpGroup
$creadsPrec :: Int -> ReadS UpdateRulesOfIpGroup
Prelude.Read, Int -> UpdateRulesOfIpGroup -> ShowS
[UpdateRulesOfIpGroup] -> ShowS
UpdateRulesOfIpGroup -> String
(Int -> UpdateRulesOfIpGroup -> ShowS)
-> (UpdateRulesOfIpGroup -> String)
-> ([UpdateRulesOfIpGroup] -> ShowS)
-> Show UpdateRulesOfIpGroup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateRulesOfIpGroup] -> ShowS
$cshowList :: [UpdateRulesOfIpGroup] -> ShowS
show :: UpdateRulesOfIpGroup -> String
$cshow :: UpdateRulesOfIpGroup -> String
showsPrec :: Int -> UpdateRulesOfIpGroup -> ShowS
$cshowsPrec :: Int -> UpdateRulesOfIpGroup -> ShowS
Prelude.Show, (forall x. UpdateRulesOfIpGroup -> Rep UpdateRulesOfIpGroup x)
-> (forall x. Rep UpdateRulesOfIpGroup x -> UpdateRulesOfIpGroup)
-> Generic UpdateRulesOfIpGroup
forall x. Rep UpdateRulesOfIpGroup x -> UpdateRulesOfIpGroup
forall x. UpdateRulesOfIpGroup -> Rep UpdateRulesOfIpGroup x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateRulesOfIpGroup x -> UpdateRulesOfIpGroup
$cfrom :: forall x. UpdateRulesOfIpGroup -> Rep UpdateRulesOfIpGroup x
Prelude.Generic)

-- |
-- Create a value of 'UpdateRulesOfIpGroup' 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', 'updateRulesOfIpGroup_groupId' - The identifier of the group.
--
-- 'userRules', 'updateRulesOfIpGroup_userRules' - One or more rules.
newUpdateRulesOfIpGroup ::
  -- | 'groupId'
  Prelude.Text ->
  UpdateRulesOfIpGroup
newUpdateRulesOfIpGroup :: Text -> UpdateRulesOfIpGroup
newUpdateRulesOfIpGroup Text
pGroupId_ =
  UpdateRulesOfIpGroup' :: Text -> [IpRuleItem] -> UpdateRulesOfIpGroup
UpdateRulesOfIpGroup'
    { $sel:groupId:UpdateRulesOfIpGroup' :: Text
groupId = Text
pGroupId_,
      $sel:userRules:UpdateRulesOfIpGroup' :: [IpRuleItem]
userRules = [IpRuleItem]
forall a. Monoid a => a
Prelude.mempty
    }

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

-- | One or more rules.
updateRulesOfIpGroup_userRules :: Lens.Lens' UpdateRulesOfIpGroup [IpRuleItem]
updateRulesOfIpGroup_userRules :: ([IpRuleItem] -> f [IpRuleItem])
-> UpdateRulesOfIpGroup -> f UpdateRulesOfIpGroup
updateRulesOfIpGroup_userRules = (UpdateRulesOfIpGroup -> [IpRuleItem])
-> (UpdateRulesOfIpGroup -> [IpRuleItem] -> UpdateRulesOfIpGroup)
-> Lens
     UpdateRulesOfIpGroup UpdateRulesOfIpGroup [IpRuleItem] [IpRuleItem]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateRulesOfIpGroup' {[IpRuleItem]
userRules :: [IpRuleItem]
$sel:userRules:UpdateRulesOfIpGroup' :: UpdateRulesOfIpGroup -> [IpRuleItem]
userRules} -> [IpRuleItem]
userRules) (\s :: UpdateRulesOfIpGroup
s@UpdateRulesOfIpGroup' {} [IpRuleItem]
a -> UpdateRulesOfIpGroup
s {$sel:userRules:UpdateRulesOfIpGroup' :: [IpRuleItem]
userRules = [IpRuleItem]
a} :: UpdateRulesOfIpGroup) (([IpRuleItem] -> f [IpRuleItem])
 -> UpdateRulesOfIpGroup -> f UpdateRulesOfIpGroup)
-> (([IpRuleItem] -> f [IpRuleItem])
    -> [IpRuleItem] -> f [IpRuleItem])
-> ([IpRuleItem] -> f [IpRuleItem])
-> UpdateRulesOfIpGroup
-> f UpdateRulesOfIpGroup
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([IpRuleItem] -> f [IpRuleItem]) -> [IpRuleItem] -> f [IpRuleItem]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest UpdateRulesOfIpGroup where
  type
    AWSResponse UpdateRulesOfIpGroup =
      UpdateRulesOfIpGroupResponse
  request :: UpdateRulesOfIpGroup -> Request UpdateRulesOfIpGroup
request = Service -> UpdateRulesOfIpGroup -> Request UpdateRulesOfIpGroup
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateRulesOfIpGroup
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateRulesOfIpGroup)))
response =
    (Int
 -> ResponseHeaders
 -> ()
 -> Either String (AWSResponse UpdateRulesOfIpGroup))
-> Logger
-> Service
-> Proxy UpdateRulesOfIpGroup
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateRulesOfIpGroup)))
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 -> UpdateRulesOfIpGroupResponse
UpdateRulesOfIpGroupResponse'
            (Int -> UpdateRulesOfIpGroupResponse)
-> Either String Int -> Either String UpdateRulesOfIpGroupResponse
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 UpdateRulesOfIpGroup

instance Prelude.NFData UpdateRulesOfIpGroup

instance Core.ToHeaders UpdateRulesOfIpGroup where
  toHeaders :: UpdateRulesOfIpGroup -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateRulesOfIpGroup -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"WorkspacesService.UpdateRulesOfIpGroup" ::
                          Prelude.ByteString
                      ),
            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 UpdateRulesOfIpGroup where
  toJSON :: UpdateRulesOfIpGroup -> Value
toJSON UpdateRulesOfIpGroup' {[IpRuleItem]
Text
userRules :: [IpRuleItem]
groupId :: Text
$sel:userRules:UpdateRulesOfIpGroup' :: UpdateRulesOfIpGroup -> [IpRuleItem]
$sel:groupId:UpdateRulesOfIpGroup' :: UpdateRulesOfIpGroup -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"GroupId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
groupId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"UserRules" Text -> [IpRuleItem] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [IpRuleItem]
userRules)
          ]
      )

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

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

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

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

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

instance Prelude.NFData UpdateRulesOfIpGroupResponse