{-# 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.Route53Resolver.PutResolverRulePolicy
-- 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)
--
-- Specifies an Amazon Web Services rule that you want to share with
-- another account, the account that you want to share the rule with, and
-- the operations that you want the account to be able to perform on the
-- rule.
module Amazonka.Route53Resolver.PutResolverRulePolicy
  ( -- * Creating a Request
    PutResolverRulePolicy (..),
    newPutResolverRulePolicy,

    -- * Request Lenses
    putResolverRulePolicy_arn,
    putResolverRulePolicy_resolverRulePolicy,

    -- * Destructuring the Response
    PutResolverRulePolicyResponse (..),
    newPutResolverRulePolicyResponse,

    -- * Response Lenses
    putResolverRulePolicyResponse_returnValue,
    putResolverRulePolicyResponse_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.Route53Resolver.Types

-- | /See:/ 'newPutResolverRulePolicy' smart constructor.
data PutResolverRulePolicy = PutResolverRulePolicy'
  { -- | The Amazon Resource Name (ARN) of the rule that you want to share with
    -- another account.
    PutResolverRulePolicy -> Text
arn :: Prelude.Text,
    -- | An Identity and Access Management policy statement that lists the rules
    -- that you want to share with another Amazon Web Services account and the
    -- operations that you want the account to be able to perform. You can
    -- specify the following operations in the @Action@ section of the
    -- statement:
    --
    -- -   @route53resolver:GetResolverRule@
    --
    -- -   @route53resolver:AssociateResolverRule@
    --
    -- -   @route53resolver:DisassociateResolverRule@
    --
    -- -   @route53resolver:ListResolverRules@
    --
    -- -   @route53resolver:ListResolverRuleAssociations@
    --
    -- In the @Resource@ section of the statement, specify the ARN for the rule
    -- that you want to share with another account. Specify the same ARN that
    -- you specified in @Arn@.
    PutResolverRulePolicy -> Text
resolverRulePolicy :: Prelude.Text
  }
  deriving (PutResolverRulePolicy -> PutResolverRulePolicy -> Bool
(PutResolverRulePolicy -> PutResolverRulePolicy -> Bool)
-> (PutResolverRulePolicy -> PutResolverRulePolicy -> Bool)
-> Eq PutResolverRulePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutResolverRulePolicy -> PutResolverRulePolicy -> Bool
$c/= :: PutResolverRulePolicy -> PutResolverRulePolicy -> Bool
== :: PutResolverRulePolicy -> PutResolverRulePolicy -> Bool
$c== :: PutResolverRulePolicy -> PutResolverRulePolicy -> Bool
Prelude.Eq, ReadPrec [PutResolverRulePolicy]
ReadPrec PutResolverRulePolicy
Int -> ReadS PutResolverRulePolicy
ReadS [PutResolverRulePolicy]
(Int -> ReadS PutResolverRulePolicy)
-> ReadS [PutResolverRulePolicy]
-> ReadPrec PutResolverRulePolicy
-> ReadPrec [PutResolverRulePolicy]
-> Read PutResolverRulePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutResolverRulePolicy]
$creadListPrec :: ReadPrec [PutResolverRulePolicy]
readPrec :: ReadPrec PutResolverRulePolicy
$creadPrec :: ReadPrec PutResolverRulePolicy
readList :: ReadS [PutResolverRulePolicy]
$creadList :: ReadS [PutResolverRulePolicy]
readsPrec :: Int -> ReadS PutResolverRulePolicy
$creadsPrec :: Int -> ReadS PutResolverRulePolicy
Prelude.Read, Int -> PutResolverRulePolicy -> ShowS
[PutResolverRulePolicy] -> ShowS
PutResolverRulePolicy -> String
(Int -> PutResolverRulePolicy -> ShowS)
-> (PutResolverRulePolicy -> String)
-> ([PutResolverRulePolicy] -> ShowS)
-> Show PutResolverRulePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutResolverRulePolicy] -> ShowS
$cshowList :: [PutResolverRulePolicy] -> ShowS
show :: PutResolverRulePolicy -> String
$cshow :: PutResolverRulePolicy -> String
showsPrec :: Int -> PutResolverRulePolicy -> ShowS
$cshowsPrec :: Int -> PutResolverRulePolicy -> ShowS
Prelude.Show, (forall x. PutResolverRulePolicy -> Rep PutResolverRulePolicy x)
-> (forall x. Rep PutResolverRulePolicy x -> PutResolverRulePolicy)
-> Generic PutResolverRulePolicy
forall x. Rep PutResolverRulePolicy x -> PutResolverRulePolicy
forall x. PutResolverRulePolicy -> Rep PutResolverRulePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutResolverRulePolicy x -> PutResolverRulePolicy
$cfrom :: forall x. PutResolverRulePolicy -> Rep PutResolverRulePolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutResolverRulePolicy' 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:
--
-- 'arn', 'putResolverRulePolicy_arn' - The Amazon Resource Name (ARN) of the rule that you want to share with
-- another account.
--
-- 'resolverRulePolicy', 'putResolverRulePolicy_resolverRulePolicy' - An Identity and Access Management policy statement that lists the rules
-- that you want to share with another Amazon Web Services account and the
-- operations that you want the account to be able to perform. You can
-- specify the following operations in the @Action@ section of the
-- statement:
--
-- -   @route53resolver:GetResolverRule@
--
-- -   @route53resolver:AssociateResolverRule@
--
-- -   @route53resolver:DisassociateResolverRule@
--
-- -   @route53resolver:ListResolverRules@
--
-- -   @route53resolver:ListResolverRuleAssociations@
--
-- In the @Resource@ section of the statement, specify the ARN for the rule
-- that you want to share with another account. Specify the same ARN that
-- you specified in @Arn@.
newPutResolverRulePolicy ::
  -- | 'arn'
  Prelude.Text ->
  -- | 'resolverRulePolicy'
  Prelude.Text ->
  PutResolverRulePolicy
newPutResolverRulePolicy :: Text -> Text -> PutResolverRulePolicy
newPutResolverRulePolicy Text
pArn_ Text
pResolverRulePolicy_ =
  PutResolverRulePolicy' :: Text -> Text -> PutResolverRulePolicy
PutResolverRulePolicy'
    { $sel:arn:PutResolverRulePolicy' :: Text
arn = Text
pArn_,
      $sel:resolverRulePolicy:PutResolverRulePolicy' :: Text
resolverRulePolicy = Text
pResolverRulePolicy_
    }

-- | The Amazon Resource Name (ARN) of the rule that you want to share with
-- another account.
putResolverRulePolicy_arn :: Lens.Lens' PutResolverRulePolicy Prelude.Text
putResolverRulePolicy_arn :: (Text -> f Text)
-> PutResolverRulePolicy -> f PutResolverRulePolicy
putResolverRulePolicy_arn = (PutResolverRulePolicy -> Text)
-> (PutResolverRulePolicy -> Text -> PutResolverRulePolicy)
-> Lens PutResolverRulePolicy PutResolverRulePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutResolverRulePolicy' {Text
arn :: Text
$sel:arn:PutResolverRulePolicy' :: PutResolverRulePolicy -> Text
arn} -> Text
arn) (\s :: PutResolverRulePolicy
s@PutResolverRulePolicy' {} Text
a -> PutResolverRulePolicy
s {$sel:arn:PutResolverRulePolicy' :: Text
arn = Text
a} :: PutResolverRulePolicy)

-- | An Identity and Access Management policy statement that lists the rules
-- that you want to share with another Amazon Web Services account and the
-- operations that you want the account to be able to perform. You can
-- specify the following operations in the @Action@ section of the
-- statement:
--
-- -   @route53resolver:GetResolverRule@
--
-- -   @route53resolver:AssociateResolverRule@
--
-- -   @route53resolver:DisassociateResolverRule@
--
-- -   @route53resolver:ListResolverRules@
--
-- -   @route53resolver:ListResolverRuleAssociations@
--
-- In the @Resource@ section of the statement, specify the ARN for the rule
-- that you want to share with another account. Specify the same ARN that
-- you specified in @Arn@.
putResolverRulePolicy_resolverRulePolicy :: Lens.Lens' PutResolverRulePolicy Prelude.Text
putResolverRulePolicy_resolverRulePolicy :: (Text -> f Text)
-> PutResolverRulePolicy -> f PutResolverRulePolicy
putResolverRulePolicy_resolverRulePolicy = (PutResolverRulePolicy -> Text)
-> (PutResolverRulePolicy -> Text -> PutResolverRulePolicy)
-> Lens PutResolverRulePolicy PutResolverRulePolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutResolverRulePolicy' {Text
resolverRulePolicy :: Text
$sel:resolverRulePolicy:PutResolverRulePolicy' :: PutResolverRulePolicy -> Text
resolverRulePolicy} -> Text
resolverRulePolicy) (\s :: PutResolverRulePolicy
s@PutResolverRulePolicy' {} Text
a -> PutResolverRulePolicy
s {$sel:resolverRulePolicy:PutResolverRulePolicy' :: Text
resolverRulePolicy = Text
a} :: PutResolverRulePolicy)

instance Core.AWSRequest PutResolverRulePolicy where
  type
    AWSResponse PutResolverRulePolicy =
      PutResolverRulePolicyResponse
  request :: PutResolverRulePolicy -> Request PutResolverRulePolicy
request = Service -> PutResolverRulePolicy -> Request PutResolverRulePolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutResolverRulePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutResolverRulePolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutResolverRulePolicy))
-> Logger
-> Service
-> Proxy PutResolverRulePolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutResolverRulePolicy)))
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 Bool -> Int -> PutResolverRulePolicyResponse
PutResolverRulePolicyResponse'
            (Maybe Bool -> Int -> PutResolverRulePolicyResponse)
-> Either String (Maybe Bool)
-> Either String (Int -> PutResolverRulePolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ReturnValue")
            Either String (Int -> PutResolverRulePolicyResponse)
-> Either String Int -> Either String PutResolverRulePolicyResponse
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 PutResolverRulePolicy

instance Prelude.NFData PutResolverRulePolicy

instance Core.ToHeaders PutResolverRulePolicy where
  toHeaders :: PutResolverRulePolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutResolverRulePolicy -> 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
"Route53Resolver.PutResolverRulePolicy" ::
                          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 PutResolverRulePolicy where
  toJSON :: PutResolverRulePolicy -> Value
toJSON PutResolverRulePolicy' {Text
resolverRulePolicy :: Text
arn :: Text
$sel:resolverRulePolicy:PutResolverRulePolicy' :: PutResolverRulePolicy -> Text
$sel:arn:PutResolverRulePolicy' :: PutResolverRulePolicy -> 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
"Arn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
arn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ResolverRulePolicy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resolverRulePolicy)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutResolverRulePolicyResponse' 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:
--
-- 'returnValue', 'putResolverRulePolicyResponse_returnValue' - Whether the @PutResolverRulePolicy@ request was successful.
--
-- 'httpStatus', 'putResolverRulePolicyResponse_httpStatus' - The response's http status code.
newPutResolverRulePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutResolverRulePolicyResponse
newPutResolverRulePolicyResponse :: Int -> PutResolverRulePolicyResponse
newPutResolverRulePolicyResponse Int
pHttpStatus_ =
  PutResolverRulePolicyResponse' :: Maybe Bool -> Int -> PutResolverRulePolicyResponse
PutResolverRulePolicyResponse'
    { $sel:returnValue:PutResolverRulePolicyResponse' :: Maybe Bool
returnValue =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutResolverRulePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Whether the @PutResolverRulePolicy@ request was successful.
putResolverRulePolicyResponse_returnValue :: Lens.Lens' PutResolverRulePolicyResponse (Prelude.Maybe Prelude.Bool)
putResolverRulePolicyResponse_returnValue :: (Maybe Bool -> f (Maybe Bool))
-> PutResolverRulePolicyResponse -> f PutResolverRulePolicyResponse
putResolverRulePolicyResponse_returnValue = (PutResolverRulePolicyResponse -> Maybe Bool)
-> (PutResolverRulePolicyResponse
    -> Maybe Bool -> PutResolverRulePolicyResponse)
-> Lens
     PutResolverRulePolicyResponse
     PutResolverRulePolicyResponse
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutResolverRulePolicyResponse' {Maybe Bool
returnValue :: Maybe Bool
$sel:returnValue:PutResolverRulePolicyResponse' :: PutResolverRulePolicyResponse -> Maybe Bool
returnValue} -> Maybe Bool
returnValue) (\s :: PutResolverRulePolicyResponse
s@PutResolverRulePolicyResponse' {} Maybe Bool
a -> PutResolverRulePolicyResponse
s {$sel:returnValue:PutResolverRulePolicyResponse' :: Maybe Bool
returnValue = Maybe Bool
a} :: PutResolverRulePolicyResponse)

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

instance Prelude.NFData PutResolverRulePolicyResponse