{-# 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-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)
--
-- 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_requestId,
    putComponentPolicyResponse_componentArn,
    putComponentPolicyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.ImageBuilder.Types
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:/ '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
(PutComponentPolicy -> PutComponentPolicy -> Bool)
-> (PutComponentPolicy -> PutComponentPolicy -> Bool)
-> Eq PutComponentPolicy
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]
(Int -> ReadS PutComponentPolicy)
-> ReadS [PutComponentPolicy]
-> ReadPrec PutComponentPolicy
-> ReadPrec [PutComponentPolicy]
-> Read 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
(Int -> PutComponentPolicy -> ShowS)
-> (PutComponentPolicy -> String)
-> ([PutComponentPolicy] -> ShowS)
-> Show PutComponentPolicy
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. PutComponentPolicy -> Rep PutComponentPolicy x)
-> (forall x. Rep PutComponentPolicy x -> PutComponentPolicy)
-> Generic PutComponentPolicy
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' :: Text -> Text -> PutComponentPolicy
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 :: (Text -> f Text) -> PutComponentPolicy -> f PutComponentPolicy
putComponentPolicy_componentArn = (PutComponentPolicy -> Text)
-> (PutComponentPolicy -> Text -> PutComponentPolicy)
-> Lens PutComponentPolicy PutComponentPolicy Text Text
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 :: (Text -> f Text) -> PutComponentPolicy -> f PutComponentPolicy
putComponentPolicy_policy = (PutComponentPolicy -> Text)
-> (PutComponentPolicy -> Text -> PutComponentPolicy)
-> Lens PutComponentPolicy PutComponentPolicy Text Text
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 :: PutComponentPolicy -> Request PutComponentPolicy
request = Service -> PutComponentPolicy -> Request PutComponentPolicy
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.putJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy PutComponentPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutComponentPolicy)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutComponentPolicy))
-> Logger
-> Service
-> Proxy PutComponentPolicy
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse PutComponentPolicy)))
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 Text -> Maybe Text -> Int -> PutComponentPolicyResponse
PutComponentPolicyResponse'
            (Maybe Text -> Maybe Text -> Int -> PutComponentPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> PutComponentPolicyResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"requestId")
            Either String (Maybe Text -> Int -> PutComponentPolicyResponse)
-> Either String (Maybe Text)
-> Either String (Int -> PutComponentPolicyResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"componentArn")
            Either String (Int -> PutComponentPolicyResponse)
-> Either String Int -> Either String PutComponentPolicyResponse
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 PutComponentPolicy

instance Prelude.NFData PutComponentPolicy

instance Core.ToHeaders PutComponentPolicy where
  toHeaders :: PutComponentPolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutComponentPolicy -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ 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 PutComponentPolicy where
  toJSON :: PutComponentPolicy -> Value
toJSON PutComponentPolicy' {Text
policy :: Text
componentArn :: Text
$sel:policy:PutComponentPolicy' :: PutComponentPolicy -> Text
$sel:componentArn:PutComponentPolicy' :: PutComponentPolicy -> 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
"componentArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
componentArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"policy" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
policy)
          ]
      )

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

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

-- | /See:/ 'newPutComponentPolicyResponse' smart constructor.
data PutComponentPolicyResponse = PutComponentPolicyResponse'
  { -- | The request ID that uniquely identifies this request.
    PutComponentPolicyResponse -> Maybe Text
requestId :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the component that this policy was
    -- applied to.
    PutComponentPolicyResponse -> Maybe Text
componentArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    PutComponentPolicyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool
(PutComponentPolicyResponse -> PutComponentPolicyResponse -> Bool)
-> (PutComponentPolicyResponse
    -> PutComponentPolicyResponse -> Bool)
-> Eq PutComponentPolicyResponse
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]
(Int -> ReadS PutComponentPolicyResponse)
-> ReadS [PutComponentPolicyResponse]
-> ReadPrec PutComponentPolicyResponse
-> ReadPrec [PutComponentPolicyResponse]
-> Read 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
(Int -> PutComponentPolicyResponse -> ShowS)
-> (PutComponentPolicyResponse -> String)
-> ([PutComponentPolicyResponse] -> ShowS)
-> Show PutComponentPolicyResponse
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.
 PutComponentPolicyResponse -> Rep PutComponentPolicyResponse x)
-> (forall x.
    Rep PutComponentPolicyResponse x -> PutComponentPolicyResponse)
-> Generic PutComponentPolicyResponse
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:
--
-- 'requestId', 'putComponentPolicyResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'componentArn', 'putComponentPolicyResponse_componentArn' - The Amazon Resource Name (ARN) of the component that this policy was
-- applied to.
--
-- 'httpStatus', 'putComponentPolicyResponse_httpStatus' - The response's http status code.
newPutComponentPolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutComponentPolicyResponse
newPutComponentPolicyResponse :: Int -> PutComponentPolicyResponse
newPutComponentPolicyResponse Int
pHttpStatus_ =
  PutComponentPolicyResponse' :: Maybe Text -> Maybe Text -> Int -> PutComponentPolicyResponse
PutComponentPolicyResponse'
    { $sel:requestId:PutComponentPolicyResponse' :: Maybe Text
requestId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:componentArn:PutComponentPolicyResponse' :: Maybe Text
componentArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutComponentPolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The request ID that uniquely identifies this request.
putComponentPolicyResponse_requestId :: Lens.Lens' PutComponentPolicyResponse (Prelude.Maybe Prelude.Text)
putComponentPolicyResponse_requestId :: (Maybe Text -> f (Maybe Text))
-> PutComponentPolicyResponse -> f PutComponentPolicyResponse
putComponentPolicyResponse_requestId = (PutComponentPolicyResponse -> Maybe Text)
-> (PutComponentPolicyResponse
    -> Maybe Text -> PutComponentPolicyResponse)
-> Lens
     PutComponentPolicyResponse
     PutComponentPolicyResponse
     (Maybe Text)
     (Maybe Text)
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 Amazon Resource Name (ARN) of the component that this policy was
-- applied to.
putComponentPolicyResponse_componentArn :: Lens.Lens' PutComponentPolicyResponse (Prelude.Maybe Prelude.Text)
putComponentPolicyResponse_componentArn :: (Maybe Text -> f (Maybe Text))
-> PutComponentPolicyResponse -> f PutComponentPolicyResponse
putComponentPolicyResponse_componentArn = (PutComponentPolicyResponse -> Maybe Text)
-> (PutComponentPolicyResponse
    -> Maybe Text -> PutComponentPolicyResponse)
-> Lens
     PutComponentPolicyResponse
     PutComponentPolicyResponse
     (Maybe Text)
     (Maybe Text)
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 response's http status code.
putComponentPolicyResponse_httpStatus :: Lens.Lens' PutComponentPolicyResponse Prelude.Int
putComponentPolicyResponse_httpStatus :: (Int -> f Int)
-> PutComponentPolicyResponse -> f PutComponentPolicyResponse
putComponentPolicyResponse_httpStatus = (PutComponentPolicyResponse -> Int)
-> (PutComponentPolicyResponse
    -> Int -> PutComponentPolicyResponse)
-> Lens
     PutComponentPolicyResponse PutComponentPolicyResponse Int Int
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