{-# 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.CloudWatchLogs.PutDestination
-- 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)
--
-- Creates or updates a destination. This operation is used only to create
-- destinations for cross-account subscriptions.
--
-- A destination encapsulates a physical resource (such as an Amazon
-- Kinesis stream) and enables you to subscribe to a real-time stream of
-- log events for a different account, ingested using
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html PutLogEvents>.
--
-- Through an access policy, a destination controls what is written to it.
-- By default, @PutDestination@ does not set any access policy with the
-- destination, which means a cross-account user cannot call
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutSubscriptionFilter.html PutSubscriptionFilter>
-- against this destination. To enable this, the destination owner must
-- call
-- <https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutDestinationPolicy.html PutDestinationPolicy>
-- after @PutDestination@.
--
-- To perform a @PutDestination@ operation, you must also have the
-- @iam:PassRole@ permission.
module Amazonka.CloudWatchLogs.PutDestination
  ( -- * Creating a Request
    PutDestination (..),
    newPutDestination,

    -- * Request Lenses
    putDestination_destinationName,
    putDestination_targetArn,
    putDestination_roleArn,

    -- * Destructuring the Response
    PutDestinationResponse (..),
    newPutDestinationResponse,

    -- * Response Lenses
    putDestinationResponse_destination,
    putDestinationResponse_httpStatus,
  )
where

import Amazonka.CloudWatchLogs.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:/ 'newPutDestination' smart constructor.
data PutDestination = PutDestination'
  { -- | A name for the destination.
    PutDestination -> Text
destinationName :: Prelude.Text,
    -- | The ARN of an Amazon Kinesis stream to which to deliver matching log
    -- events.
    PutDestination -> Text
targetArn :: Prelude.Text,
    -- | The ARN of an IAM role that grants CloudWatch Logs permissions to call
    -- the Amazon Kinesis @PutRecord@ operation on the destination stream.
    PutDestination -> Text
roleArn :: Prelude.Text
  }
  deriving (PutDestination -> PutDestination -> Bool
(PutDestination -> PutDestination -> Bool)
-> (PutDestination -> PutDestination -> Bool) -> Eq PutDestination
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutDestination -> PutDestination -> Bool
$c/= :: PutDestination -> PutDestination -> Bool
== :: PutDestination -> PutDestination -> Bool
$c== :: PutDestination -> PutDestination -> Bool
Prelude.Eq, ReadPrec [PutDestination]
ReadPrec PutDestination
Int -> ReadS PutDestination
ReadS [PutDestination]
(Int -> ReadS PutDestination)
-> ReadS [PutDestination]
-> ReadPrec PutDestination
-> ReadPrec [PutDestination]
-> Read PutDestination
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutDestination]
$creadListPrec :: ReadPrec [PutDestination]
readPrec :: ReadPrec PutDestination
$creadPrec :: ReadPrec PutDestination
readList :: ReadS [PutDestination]
$creadList :: ReadS [PutDestination]
readsPrec :: Int -> ReadS PutDestination
$creadsPrec :: Int -> ReadS PutDestination
Prelude.Read, Int -> PutDestination -> ShowS
[PutDestination] -> ShowS
PutDestination -> String
(Int -> PutDestination -> ShowS)
-> (PutDestination -> String)
-> ([PutDestination] -> ShowS)
-> Show PutDestination
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutDestination] -> ShowS
$cshowList :: [PutDestination] -> ShowS
show :: PutDestination -> String
$cshow :: PutDestination -> String
showsPrec :: Int -> PutDestination -> ShowS
$cshowsPrec :: Int -> PutDestination -> ShowS
Prelude.Show, (forall x. PutDestination -> Rep PutDestination x)
-> (forall x. Rep PutDestination x -> PutDestination)
-> Generic PutDestination
forall x. Rep PutDestination x -> PutDestination
forall x. PutDestination -> Rep PutDestination x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutDestination x -> PutDestination
$cfrom :: forall x. PutDestination -> Rep PutDestination x
Prelude.Generic)

-- |
-- Create a value of 'PutDestination' 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:
--
-- 'destinationName', 'putDestination_destinationName' - A name for the destination.
--
-- 'targetArn', 'putDestination_targetArn' - The ARN of an Amazon Kinesis stream to which to deliver matching log
-- events.
--
-- 'roleArn', 'putDestination_roleArn' - The ARN of an IAM role that grants CloudWatch Logs permissions to call
-- the Amazon Kinesis @PutRecord@ operation on the destination stream.
newPutDestination ::
  -- | 'destinationName'
  Prelude.Text ->
  -- | 'targetArn'
  Prelude.Text ->
  -- | 'roleArn'
  Prelude.Text ->
  PutDestination
newPutDestination :: Text -> Text -> Text -> PutDestination
newPutDestination
  Text
pDestinationName_
  Text
pTargetArn_
  Text
pRoleArn_ =
    PutDestination' :: Text -> Text -> Text -> PutDestination
PutDestination'
      { $sel:destinationName:PutDestination' :: Text
destinationName =
          Text
pDestinationName_,
        $sel:targetArn:PutDestination' :: Text
targetArn = Text
pTargetArn_,
        $sel:roleArn:PutDestination' :: Text
roleArn = Text
pRoleArn_
      }

-- | A name for the destination.
putDestination_destinationName :: Lens.Lens' PutDestination Prelude.Text
putDestination_destinationName :: (Text -> f Text) -> PutDestination -> f PutDestination
putDestination_destinationName = (PutDestination -> Text)
-> (PutDestination -> Text -> PutDestination)
-> Lens PutDestination PutDestination Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestination' {Text
destinationName :: Text
$sel:destinationName:PutDestination' :: PutDestination -> Text
destinationName} -> Text
destinationName) (\s :: PutDestination
s@PutDestination' {} Text
a -> PutDestination
s {$sel:destinationName:PutDestination' :: Text
destinationName = Text
a} :: PutDestination)

-- | The ARN of an Amazon Kinesis stream to which to deliver matching log
-- events.
putDestination_targetArn :: Lens.Lens' PutDestination Prelude.Text
putDestination_targetArn :: (Text -> f Text) -> PutDestination -> f PutDestination
putDestination_targetArn = (PutDestination -> Text)
-> (PutDestination -> Text -> PutDestination)
-> Lens PutDestination PutDestination Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestination' {Text
targetArn :: Text
$sel:targetArn:PutDestination' :: PutDestination -> Text
targetArn} -> Text
targetArn) (\s :: PutDestination
s@PutDestination' {} Text
a -> PutDestination
s {$sel:targetArn:PutDestination' :: Text
targetArn = Text
a} :: PutDestination)

-- | The ARN of an IAM role that grants CloudWatch Logs permissions to call
-- the Amazon Kinesis @PutRecord@ operation on the destination stream.
putDestination_roleArn :: Lens.Lens' PutDestination Prelude.Text
putDestination_roleArn :: (Text -> f Text) -> PutDestination -> f PutDestination
putDestination_roleArn = (PutDestination -> Text)
-> (PutDestination -> Text -> PutDestination)
-> Lens PutDestination PutDestination Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestination' {Text
roleArn :: Text
$sel:roleArn:PutDestination' :: PutDestination -> Text
roleArn} -> Text
roleArn) (\s :: PutDestination
s@PutDestination' {} Text
a -> PutDestination
s {$sel:roleArn:PutDestination' :: Text
roleArn = Text
a} :: PutDestination)

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

instance Prelude.NFData PutDestination

instance Core.ToHeaders PutDestination where
  toHeaders :: PutDestination -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutDestination -> 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
"Logs_20140328.PutDestination" ::
                          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 PutDestination where
  toJSON :: PutDestination -> Value
toJSON PutDestination' {Text
roleArn :: Text
targetArn :: Text
destinationName :: Text
$sel:roleArn:PutDestination' :: PutDestination -> Text
$sel:targetArn:PutDestination' :: PutDestination -> Text
$sel:destinationName:PutDestination' :: PutDestination -> 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
"destinationName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
destinationName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"targetArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
targetArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"roleArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
roleArn)
          ]
      )

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

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

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

-- |
-- Create a value of 'PutDestinationResponse' 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:
--
-- 'destination', 'putDestinationResponse_destination' - The destination.
--
-- 'httpStatus', 'putDestinationResponse_httpStatus' - The response's http status code.
newPutDestinationResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  PutDestinationResponse
newPutDestinationResponse :: Int -> PutDestinationResponse
newPutDestinationResponse Int
pHttpStatus_ =
  PutDestinationResponse' :: Maybe Destination -> Int -> PutDestinationResponse
PutDestinationResponse'
    { $sel:destination:PutDestinationResponse' :: Maybe Destination
destination =
        Maybe Destination
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:PutDestinationResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The destination.
putDestinationResponse_destination :: Lens.Lens' PutDestinationResponse (Prelude.Maybe Destination)
putDestinationResponse_destination :: (Maybe Destination -> f (Maybe Destination))
-> PutDestinationResponse -> f PutDestinationResponse
putDestinationResponse_destination = (PutDestinationResponse -> Maybe Destination)
-> (PutDestinationResponse
    -> Maybe Destination -> PutDestinationResponse)
-> Lens
     PutDestinationResponse
     PutDestinationResponse
     (Maybe Destination)
     (Maybe Destination)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutDestinationResponse' {Maybe Destination
destination :: Maybe Destination
$sel:destination:PutDestinationResponse' :: PutDestinationResponse -> Maybe Destination
destination} -> Maybe Destination
destination) (\s :: PutDestinationResponse
s@PutDestinationResponse' {} Maybe Destination
a -> PutDestinationResponse
s {$sel:destination:PutDestinationResponse' :: Maybe Destination
destination = Maybe Destination
a} :: PutDestinationResponse)

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

instance Prelude.NFData PutDestinationResponse