{-# 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.CloudDirectory.AttachPolicy
-- 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)
--
-- Attaches a policy object to a regular object. An object can have a
-- limited number of attached policies.
module Amazonka.CloudDirectory.AttachPolicy
  ( -- * Creating a Request
    AttachPolicy (..),
    newAttachPolicy,

    -- * Request Lenses
    attachPolicy_directoryArn,
    attachPolicy_policyReference,
    attachPolicy_objectReference,

    -- * Destructuring the Response
    AttachPolicyResponse (..),
    newAttachPolicyResponse,

    -- * Response Lenses
    attachPolicyResponse_httpStatus,
  )
where

import Amazonka.CloudDirectory.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

-- | /See:/ 'newAttachPolicy' smart constructor.
data AttachPolicy = AttachPolicy'
  { -- | The Amazon Resource Name (ARN) that is associated with the Directory
    -- where both objects reside. For more information, see arns.
    AttachPolicy -> Text
directoryArn :: Prelude.Text,
    -- | The reference that is associated with the policy object.
    AttachPolicy -> ObjectReference
policyReference :: ObjectReference,
    -- | The reference that identifies the object to which the policy will be
    -- attached.
    AttachPolicy -> ObjectReference
objectReference :: ObjectReference
  }
  deriving (AttachPolicy -> AttachPolicy -> Bool
(AttachPolicy -> AttachPolicy -> Bool)
-> (AttachPolicy -> AttachPolicy -> Bool) -> Eq AttachPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AttachPolicy -> AttachPolicy -> Bool
$c/= :: AttachPolicy -> AttachPolicy -> Bool
== :: AttachPolicy -> AttachPolicy -> Bool
$c== :: AttachPolicy -> AttachPolicy -> Bool
Prelude.Eq, ReadPrec [AttachPolicy]
ReadPrec AttachPolicy
Int -> ReadS AttachPolicy
ReadS [AttachPolicy]
(Int -> ReadS AttachPolicy)
-> ReadS [AttachPolicy]
-> ReadPrec AttachPolicy
-> ReadPrec [AttachPolicy]
-> Read AttachPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AttachPolicy]
$creadListPrec :: ReadPrec [AttachPolicy]
readPrec :: ReadPrec AttachPolicy
$creadPrec :: ReadPrec AttachPolicy
readList :: ReadS [AttachPolicy]
$creadList :: ReadS [AttachPolicy]
readsPrec :: Int -> ReadS AttachPolicy
$creadsPrec :: Int -> ReadS AttachPolicy
Prelude.Read, Int -> AttachPolicy -> ShowS
[AttachPolicy] -> ShowS
AttachPolicy -> String
(Int -> AttachPolicy -> ShowS)
-> (AttachPolicy -> String)
-> ([AttachPolicy] -> ShowS)
-> Show AttachPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AttachPolicy] -> ShowS
$cshowList :: [AttachPolicy] -> ShowS
show :: AttachPolicy -> String
$cshow :: AttachPolicy -> String
showsPrec :: Int -> AttachPolicy -> ShowS
$cshowsPrec :: Int -> AttachPolicy -> ShowS
Prelude.Show, (forall x. AttachPolicy -> Rep AttachPolicy x)
-> (forall x. Rep AttachPolicy x -> AttachPolicy)
-> Generic AttachPolicy
forall x. Rep AttachPolicy x -> AttachPolicy
forall x. AttachPolicy -> Rep AttachPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AttachPolicy x -> AttachPolicy
$cfrom :: forall x. AttachPolicy -> Rep AttachPolicy x
Prelude.Generic)

-- |
-- Create a value of 'AttachPolicy' 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:
--
-- 'directoryArn', 'attachPolicy_directoryArn' - The Amazon Resource Name (ARN) that is associated with the Directory
-- where both objects reside. For more information, see arns.
--
-- 'policyReference', 'attachPolicy_policyReference' - The reference that is associated with the policy object.
--
-- 'objectReference', 'attachPolicy_objectReference' - The reference that identifies the object to which the policy will be
-- attached.
newAttachPolicy ::
  -- | 'directoryArn'
  Prelude.Text ->
  -- | 'policyReference'
  ObjectReference ->
  -- | 'objectReference'
  ObjectReference ->
  AttachPolicy
newAttachPolicy :: Text -> ObjectReference -> ObjectReference -> AttachPolicy
newAttachPolicy
  Text
pDirectoryArn_
  ObjectReference
pPolicyReference_
  ObjectReference
pObjectReference_ =
    AttachPolicy' :: Text -> ObjectReference -> ObjectReference -> AttachPolicy
AttachPolicy'
      { $sel:directoryArn:AttachPolicy' :: Text
directoryArn = Text
pDirectoryArn_,
        $sel:policyReference:AttachPolicy' :: ObjectReference
policyReference = ObjectReference
pPolicyReference_,
        $sel:objectReference:AttachPolicy' :: ObjectReference
objectReference = ObjectReference
pObjectReference_
      }

-- | The Amazon Resource Name (ARN) that is associated with the Directory
-- where both objects reside. For more information, see arns.
attachPolicy_directoryArn :: Lens.Lens' AttachPolicy Prelude.Text
attachPolicy_directoryArn :: (Text -> f Text) -> AttachPolicy -> f AttachPolicy
attachPolicy_directoryArn = (AttachPolicy -> Text)
-> (AttachPolicy -> Text -> AttachPolicy)
-> Lens AttachPolicy AttachPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachPolicy' {Text
directoryArn :: Text
$sel:directoryArn:AttachPolicy' :: AttachPolicy -> Text
directoryArn} -> Text
directoryArn) (\s :: AttachPolicy
s@AttachPolicy' {} Text
a -> AttachPolicy
s {$sel:directoryArn:AttachPolicy' :: Text
directoryArn = Text
a} :: AttachPolicy)

-- | The reference that is associated with the policy object.
attachPolicy_policyReference :: Lens.Lens' AttachPolicy ObjectReference
attachPolicy_policyReference :: (ObjectReference -> f ObjectReference)
-> AttachPolicy -> f AttachPolicy
attachPolicy_policyReference = (AttachPolicy -> ObjectReference)
-> (AttachPolicy -> ObjectReference -> AttachPolicy)
-> Lens AttachPolicy AttachPolicy ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachPolicy' {ObjectReference
policyReference :: ObjectReference
$sel:policyReference:AttachPolicy' :: AttachPolicy -> ObjectReference
policyReference} -> ObjectReference
policyReference) (\s :: AttachPolicy
s@AttachPolicy' {} ObjectReference
a -> AttachPolicy
s {$sel:policyReference:AttachPolicy' :: ObjectReference
policyReference = ObjectReference
a} :: AttachPolicy)

-- | The reference that identifies the object to which the policy will be
-- attached.
attachPolicy_objectReference :: Lens.Lens' AttachPolicy ObjectReference
attachPolicy_objectReference :: (ObjectReference -> f ObjectReference)
-> AttachPolicy -> f AttachPolicy
attachPolicy_objectReference = (AttachPolicy -> ObjectReference)
-> (AttachPolicy -> ObjectReference -> AttachPolicy)
-> Lens AttachPolicy AttachPolicy ObjectReference ObjectReference
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AttachPolicy' {ObjectReference
objectReference :: ObjectReference
$sel:objectReference:AttachPolicy' :: AttachPolicy -> ObjectReference
objectReference} -> ObjectReference
objectReference) (\s :: AttachPolicy
s@AttachPolicy' {} ObjectReference
a -> AttachPolicy
s {$sel:objectReference:AttachPolicy' :: ObjectReference
objectReference = ObjectReference
a} :: AttachPolicy)

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

instance Prelude.NFData AttachPolicy

instance Core.ToHeaders AttachPolicy where
  toHeaders :: AttachPolicy -> ResponseHeaders
toHeaders AttachPolicy' {Text
ObjectReference
objectReference :: ObjectReference
policyReference :: ObjectReference
directoryArn :: Text
$sel:objectReference:AttachPolicy' :: AttachPolicy -> ObjectReference
$sel:policyReference:AttachPolicy' :: AttachPolicy -> ObjectReference
$sel:directoryArn:AttachPolicy' :: AttachPolicy -> Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [HeaderName
"x-amz-data-partition" HeaderName -> Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Text
directoryArn]

instance Core.ToJSON AttachPolicy where
  toJSON :: AttachPolicy -> Value
toJSON AttachPolicy' {Text
ObjectReference
objectReference :: ObjectReference
policyReference :: ObjectReference
directoryArn :: Text
$sel:objectReference:AttachPolicy' :: AttachPolicy -> ObjectReference
$sel:policyReference:AttachPolicy' :: AttachPolicy -> ObjectReference
$sel:directoryArn:AttachPolicy' :: AttachPolicy -> 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
"PolicyReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
policyReference),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ObjectReference" Text -> ObjectReference -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ObjectReference
objectReference)
          ]
      )

instance Core.ToPath AttachPolicy where
  toPath :: AttachPolicy -> ByteString
toPath =
    ByteString -> AttachPolicy -> ByteString
forall a b. a -> b -> a
Prelude.const
      ByteString
"/amazonclouddirectory/2017-01-11/policy/attach"

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

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

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

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

instance Prelude.NFData AttachPolicyResponse