{-# 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.ImageBuilder.PutComponentPolicy
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Applies a policy to a component. We recommend that you call the RAM API
-- <https://docs.aws.amazon.com/ram/latest/APIReference/API_CreateResourceShare.html CreateResourceShare>
-- to share resources. If you call the Image Builder API
-- @PutComponentPolicy@, you must also call the RAM API
-- <https://docs.aws.amazon.com/ram/latest/APIReference/API_PromoteResourceShareCreatedFromPolicy.html PromoteResourceShareCreatedFromPolicy>
-- in order for the resource to be visible to all principals with whom the
-- resource is shared.
module Amazonka.ImageBuilder.PutComponentPolicy
  ( -- * Creating a Request
    PutComponentPolicy (..),
    newPutComponentPolicy,

    -- * Request Lenses
    putComponentPolicy_componentArn,
    putComponentPolicy_policy,

    -- * Destructuring the Response
    PutComponentPolicyResponse (..),
    newPutComponentPolicyResponse,

    -- * Response Lenses
    putComponentPolicyResponse_componentArn,
    putComponentPolicyResponse_requestId,
    putComponentPolicyResponse_httpStatus,
  )
where

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

-- | /See:/ 'newPutComponentPolicy' smart constructor.
data PutComponentPolicy = PutComponentPolicy'
  { -- | The Amazon Resource Name (ARN) of the component that this policy should
    -- be applied to.
    PutComponentPolicy -> Text
componentArn :: Prelude.Text,
    -- | The policy to apply.
    PutComponentPolicy -> Text
policy :: Prelude.Text
  }
  deriving (PutComponentPolicy -> PutComponentPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutComponentPolicy -> PutComponentPolicy -> Bool
$c/= :: PutComponentPolicy -> PutComponentPolicy -> Bool
== :: PutComponentPolicy -> PutComponentPolicy -> Bool
$c== :: PutComponentPolicy -> PutComponentPolicy -> Bool
Prelude.Eq, ReadPrec [PutComponentPolicy]
ReadPrec PutComponentPolicy
Int -> ReadS PutComponentPolicy
ReadS [PutComponentPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutComponentPolicy]
$creadListPrec :: ReadPrec [PutComponentPolicy]
readPrec :: ReadPrec PutComponentPolicy
$creadPrec :: ReadPrec PutComponentPolicy
readList :: ReadS [PutComponentPolicy]
$creadList :: ReadS [PutComponentPolicy]
readsPrec :: Int -> ReadS PutComponentPolicy
$creadsPrec :: Int -> ReadS PutComponentPolicy
Prelude.Read, Int -> PutComponentPolicy -> ShowS
[PutComponentPolicy] -> ShowS
PutComponentPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutComponentPolicy] -> ShowS
$cshowList :: [PutComponentPolicy] -> ShowS
show :: PutComponentPolicy -> String
$cshow :: PutComponentPolicy -> String
showsPrec :: Int -> PutComponentPolicy -> ShowS
$cshowsPrec :: Int -> PutComponentPolicy -> ShowS
Prelude.Show, forall x. Rep PutComponentPolicy x -> PutComponentPolicy
forall x. PutComponentPolicy -> Rep PutComponentPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutComponentPolicy x -> PutComponentPolicy
$cfrom :: forall x. PutComponentPolicy -> Rep PutComponentPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutComponentPolicy' 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:
--
-- 'componentArn', 'putComponentPolicy_componentArn' - The Amazon Resource Name (ARN) of the component that this policy should
-- be applied to.
--
-- 'policy', 'putComponentPolicy_policy' - The policy to apply.
newPutComponentPolicy ::
  -- | 'componentArn'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  PutComponentPolicy
newPutComponentPolicy :: Text -> Text -> PutComponentPolicy
newPutComponentPolicy Text
pComponentArn_ Text
pPolicy_ =
  PutComponentPolicy'
    { $sel:componentArn:PutComponentPolicy' :: Text
componentArn = Text
pComponentArn_,
      $sel:policy:PutComponentPolicy' :: Text
policy = Text
pPolicy_
    }

-- | The Amazon Resource Name (ARN) of the component that this policy should
-- be applied to.
putComponentPolicy_componentArn :: Lens.Lens' PutComponentPolicy Prelude.Text
putComponentPolicy_componentArn :: Lens' PutComponentPolicy Text
putComponentPolicy_componentArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutComponentPolicy' {Text
componentArn :: Text
$sel:componentArn:PutComponentPolicy' :: PutComponentPolicy -> Text
componentArn} -> Text
componentArn) (\s :: PutComponentPolicy
s@PutComponentPolicy' {} Text
a -> PutComponentPolicy
s {$sel:componentArn:PutComponentPolicy' :: Text
componentArn = Text
a} :: PutComponentPolicy)

-- | The policy to apply.
putComponentPolicy_policy :: Lens.Lens' PutComponentPolicy Prelude.Text
putComponentPolicy_policy :: Lens' PutComponentPolicy Text
putComponentPolicy_policy = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutComponentPolicy' {Text
policy :: Text
$sel:policy:PutComponentPolicy' :: PutComponentPolicy -> Text
policy} -> Text
policy) (\s :: PutComponentPolicy
s@PutComponentPolicy' {} Text
a -> PutComponentPolicy
s {$sel:policy:PutComponentPolicy' :: Text
policy = Text
a} :: PutComponentPolicy)

instance Core.AWSRequest PutComponentPolicy where
  type
    AWSResponse PutComponentPolicy =
      PutComponentPolicyResponse
  request :: (Service -> Service)
-> PutComponentPolicy -> Request PutComponentPolicy
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy PutComponentPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutComponentPolicy)))
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 -> Maybe Text -> Int -> PutComponentPolicyResponse
PutComponentPolicyResponse'
            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
"componentArn")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"requestId")
            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 PutComponentPolicy where
  hashWithSalt :: Int -> PutComponentPolicy -> Int
hashWithSalt Int
_salt PutComponentPolicy' {Text
policy :: Text
componentArn :: Text
$sel:policy:PutComponentPolicy' :: PutComponentPolicy -> Text
$sel:componentArn:PutComponentPolicy' :: PutComponentPolicy -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
componentArn
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
policy

instance Prelude.NFData PutComponentPolicy where
  rnf :: PutComponentPolicy -> ()
rnf PutComponentPolicy' {Text
policy :: Text
componentArn :: Text
$sel:policy:PutComponentPolicy' :: PutComponentPolicy -> Text
$sel:componentArn:PutComponentPolicy' :: PutComponentPolicy -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
componentArn
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
policy

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

instance Data.ToJSON PutComponentPolicy where
  toJSON :: PutComponentPolicy -> Value
toJSON PutComponentPolicy' {Text
policy :: Text
componentArn :: Text
$sel:policy:PutComponentPolicy' :: PutComponentPolicy -> Text
$sel:componentArn:PutComponentPolicy' :: PutComponentPolicy -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"componentArn" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
componentArn),
            forall a. a -> Maybe a
Prelude.Just (Key
"policy" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
policy)
          ]
      )

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

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

-- | /See:/ 'newPutComponentPolicyResponse' smart constructor.
data PutComponentPolicyResponse = PutComponentPolicyResponse'
  { -- | The Amazon Resource Name (ARN) of the component that this policy was
    -- applied to.
    PutComponentPolicyResponse -> Maybe Text
componentArn :: Prelude.Maybe Prelude.Text,
    -- | The request ID that uniquely identifies this request.
    PutComponentPolicyResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    PutComponentPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool
$c/= :: PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool
== :: PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool
$c== :: PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool
Prelude.Eq, ReadPrec [PutComponentPolicyResponse]
ReadPrec PutComponentPolicyResponse
Int -> ReadS PutComponentPolicyResponse
ReadS [PutComponentPolicyResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutComponentPolicyResponse]
$creadListPrec :: ReadPrec [PutComponentPolicyResponse]
readPrec :: ReadPrec PutComponentPolicyResponse
$creadPrec :: ReadPrec PutComponentPolicyResponse
readList :: ReadS [PutComponentPolicyResponse]
$creadList :: ReadS [PutComponentPolicyResponse]
readsPrec :: Int -> ReadS PutComponentPolicyResponse
$creadsPrec :: Int -> ReadS PutComponentPolicyResponse
Prelude.Read, Int -> PutComponentPolicyResponse -> ShowS
[PutComponentPolicyResponse] -> ShowS
PutComponentPolicyResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutComponentPolicyResponse] -> ShowS
$cshowList :: [PutComponentPolicyResponse] -> ShowS
show :: PutComponentPolicyResponse -> String
$cshow :: PutComponentPolicyResponse -> String
showsPrec :: Int -> PutComponentPolicyResponse -> ShowS
$cshowsPrec :: Int -> PutComponentPolicyResponse -> ShowS
Prelude.Show, forall x.
Rep PutComponentPolicyResponse x -> PutComponentPolicyResponse
forall x.
PutComponentPolicyResponse -> Rep PutComponentPolicyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PutComponentPolicyResponse x -> PutComponentPolicyResponse
$cfrom :: forall x.
PutComponentPolicyResponse -> Rep PutComponentPolicyResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutComponentPolicyResponse' 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:
--
-- 'componentArn', 'putComponentPolicyResponse_componentArn' - The Amazon Resource Name (ARN) of the component that this policy was
-- applied to.
--
-- 'requestId', 'putComponentPolicyResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'httpStatus', 'putComponentPolicyResponse_httpStatus' - The response's http status code.
newPutComponentPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutComponentPolicyResponse
newPutComponentPolicyResponse :: Int -> PutComponentPolicyResponse
newPutComponentPolicyResponse Int
pHttpStatus_ =
  PutComponentPolicyResponse'
    { $sel:componentArn:PutComponentPolicyResponse' :: Maybe Text
componentArn =
        forall a. Maybe a
Prelude.Nothing,
      $sel:requestId:PutComponentPolicyResponse' :: Maybe Text
requestId = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutComponentPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the component that this policy was
-- applied to.
putComponentPolicyResponse_componentArn :: Lens.Lens' PutComponentPolicyResponse (Prelude.Maybe Prelude.Text)
putComponentPolicyResponse_componentArn :: Lens' PutComponentPolicyResponse (Maybe Text)
putComponentPolicyResponse_componentArn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutComponentPolicyResponse' {Maybe Text
componentArn :: Maybe Text
$sel:componentArn:PutComponentPolicyResponse' :: PutComponentPolicyResponse -> Maybe Text
componentArn} -> Maybe Text
componentArn) (\s :: PutComponentPolicyResponse
s@PutComponentPolicyResponse' {} Maybe Text
a -> PutComponentPolicyResponse
s {$sel:componentArn:PutComponentPolicyResponse' :: Maybe Text
componentArn = Maybe Text
a} :: PutComponentPolicyResponse)

-- | The request ID that uniquely identifies this request.
putComponentPolicyResponse_requestId :: Lens.Lens' PutComponentPolicyResponse (Prelude.Maybe Prelude.Text)
putComponentPolicyResponse_requestId :: Lens' PutComponentPolicyResponse (Maybe Text)
putComponentPolicyResponse_requestId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutComponentPolicyResponse' {Maybe Text
requestId :: Maybe Text
$sel:requestId:PutComponentPolicyResponse' :: PutComponentPolicyResponse -> Maybe Text
requestId} -> Maybe Text
requestId) (\s :: PutComponentPolicyResponse
s@PutComponentPolicyResponse' {} Maybe Text
a -> PutComponentPolicyResponse
s {$sel:requestId:PutComponentPolicyResponse' :: Maybe Text
requestId = Maybe Text
a} :: PutComponentPolicyResponse)

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

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