{-# 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.PutImagePolicy
-- 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 an image. 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 @PutImagePolicy@,
-- 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.PutImagePolicy
  ( -- * Creating a Request
    PutImagePolicy (..),
    newPutImagePolicy,

    -- * Request Lenses
    putImagePolicy_imageArn,
    putImagePolicy_policy,

    -- * Destructuring the Response
    PutImagePolicyResponse (..),
    newPutImagePolicyResponse,

    -- * Response Lenses
    putImagePolicyResponse_requestId,
    putImagePolicyResponse_imageArn,
    putImagePolicyResponse_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:/ 'newPutImagePolicy' smart constructor.
data PutImagePolicy = PutImagePolicy'
  { -- | The Amazon Resource Name (ARN) of the image that this policy should be
    -- applied to.
    PutImagePolicy -> Text
imageArn :: Prelude.Text,
    -- | The policy to apply.
    PutImagePolicy -> Text
policy :: Prelude.Text
  }
  deriving (PutImagePolicy -> PutImagePolicy -> Bool
(PutImagePolicy -> PutImagePolicy -> Bool)
-> (PutImagePolicy -> PutImagePolicy -> Bool) -> Eq PutImagePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutImagePolicy -> PutImagePolicy -> Bool
$c/= :: PutImagePolicy -> PutImagePolicy -> Bool
== :: PutImagePolicy -> PutImagePolicy -> Bool
$c== :: PutImagePolicy -> PutImagePolicy -> Bool
Prelude.Eq, ReadPrec [PutImagePolicy]
ReadPrec PutImagePolicy
Int -> ReadS PutImagePolicy
ReadS [PutImagePolicy]
(Int -> ReadS PutImagePolicy)
-> ReadS [PutImagePolicy]
-> ReadPrec PutImagePolicy
-> ReadPrec [PutImagePolicy]
-> Read PutImagePolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutImagePolicy]
$creadListPrec :: ReadPrec [PutImagePolicy]
readPrec :: ReadPrec PutImagePolicy
$creadPrec :: ReadPrec PutImagePolicy
readList :: ReadS [PutImagePolicy]
$creadList :: ReadS [PutImagePolicy]
readsPrec :: Int -> ReadS PutImagePolicy
$creadsPrec :: Int -> ReadS PutImagePolicy
Prelude.Read, Int -> PutImagePolicy -> ShowS
[PutImagePolicy] -> ShowS
PutImagePolicy -> String
(Int -> PutImagePolicy -> ShowS)
-> (PutImagePolicy -> String)
-> ([PutImagePolicy] -> ShowS)
-> Show PutImagePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutImagePolicy] -> ShowS
$cshowList :: [PutImagePolicy] -> ShowS
show :: PutImagePolicy -> String
$cshow :: PutImagePolicy -> String
showsPrec :: Int -> PutImagePolicy -> ShowS
$cshowsPrec :: Int -> PutImagePolicy -> ShowS
Prelude.Show, (forall x. PutImagePolicy -> Rep PutImagePolicy x)
-> (forall x. Rep PutImagePolicy x -> PutImagePolicy)
-> Generic PutImagePolicy
forall x. Rep PutImagePolicy x -> PutImagePolicy
forall x. PutImagePolicy -> Rep PutImagePolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutImagePolicy x -> PutImagePolicy
$cfrom :: forall x. PutImagePolicy -> Rep PutImagePolicy x
Prelude.Generic)

-- |
-- Create a value of 'PutImagePolicy' 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:
--
-- 'imageArn', 'putImagePolicy_imageArn' - The Amazon Resource Name (ARN) of the image that this policy should be
-- applied to.
--
-- 'policy', 'putImagePolicy_policy' - The policy to apply.
newPutImagePolicy ::
  -- | 'imageArn'
  Prelude.Text ->
  -- | 'policy'
  Prelude.Text ->
  PutImagePolicy
newPutImagePolicy :: Text -> Text -> PutImagePolicy
newPutImagePolicy Text
pImageArn_ Text
pPolicy_ =
  PutImagePolicy' :: Text -> Text -> PutImagePolicy
PutImagePolicy'
    { $sel:imageArn:PutImagePolicy' :: Text
imageArn = Text
pImageArn_,
      $sel:policy:PutImagePolicy' :: Text
policy = Text
pPolicy_
    }

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

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

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

instance Prelude.NFData PutImagePolicy

instance Core.ToHeaders PutImagePolicy where
  toHeaders :: PutImagePolicy -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutImagePolicy -> 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 PutImagePolicy where
  toJSON :: PutImagePolicy -> Value
toJSON PutImagePolicy' {Text
policy :: Text
imageArn :: Text
$sel:policy:PutImagePolicy' :: PutImagePolicy -> Text
$sel:imageArn:PutImagePolicy' :: PutImagePolicy -> 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
"imageArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
imageArn),
            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 PutImagePolicy where
  toPath :: PutImagePolicy -> ByteString
toPath = ByteString -> PutImagePolicy -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/PutImagePolicy"

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

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

-- |
-- Create a value of 'PutImagePolicyResponse' 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', 'putImagePolicyResponse_requestId' - The request ID that uniquely identifies this request.
--
-- 'imageArn', 'putImagePolicyResponse_imageArn' - The Amazon Resource Name (ARN) of the image that this policy was applied
-- to.
--
-- 'httpStatus', 'putImagePolicyResponse_httpStatus' - The response's http status code.
newPutImagePolicyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutImagePolicyResponse
newPutImagePolicyResponse :: Int -> PutImagePolicyResponse
newPutImagePolicyResponse Int
pHttpStatus_ =
  PutImagePolicyResponse' :: Maybe Text -> Maybe Text -> Int -> PutImagePolicyResponse
PutImagePolicyResponse'
    { $sel:requestId:PutImagePolicyResponse' :: Maybe Text
requestId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:imageArn:PutImagePolicyResponse' :: Maybe Text
imageArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutImagePolicyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

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

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

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

instance Prelude.NFData PutImagePolicyResponse