{-# 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.CloudWatchEvents.DescribeEventBus
-- 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)
--
-- Displays details about an event bus in your account. This can include
-- the external Amazon Web Services accounts that are permitted to write
-- events to your default event bus, and the associated policy. For custom
-- event buses and partner event buses, it displays the name, ARN, policy,
-- state, and creation time.
--
-- To enable your account to receive events from other accounts on its
-- default event bus, use
-- <https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutPermission.html PutPermission>.
--
-- For more information about partner event buses, see
-- <https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_CreateEventBus.html CreateEventBus>.
module Amazonka.CloudWatchEvents.DescribeEventBus
  ( -- * Creating a Request
    DescribeEventBus (..),
    newDescribeEventBus,

    -- * Request Lenses
    describeEventBus_name,

    -- * Destructuring the Response
    DescribeEventBusResponse (..),
    newDescribeEventBusResponse,

    -- * Response Lenses
    describeEventBusResponse_arn,
    describeEventBusResponse_name,
    describeEventBusResponse_policy,
    describeEventBusResponse_httpStatus,
  )
where

import Amazonka.CloudWatchEvents.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:/ 'newDescribeEventBus' smart constructor.
data DescribeEventBus = DescribeEventBus'
  { -- | The name or ARN of the event bus to show details for. If you omit this,
    -- the default event bus is displayed.
    DescribeEventBus -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (DescribeEventBus -> DescribeEventBus -> Bool
(DescribeEventBus -> DescribeEventBus -> Bool)
-> (DescribeEventBus -> DescribeEventBus -> Bool)
-> Eq DescribeEventBus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeEventBus -> DescribeEventBus -> Bool
$c/= :: DescribeEventBus -> DescribeEventBus -> Bool
== :: DescribeEventBus -> DescribeEventBus -> Bool
$c== :: DescribeEventBus -> DescribeEventBus -> Bool
Prelude.Eq, ReadPrec [DescribeEventBus]
ReadPrec DescribeEventBus
Int -> ReadS DescribeEventBus
ReadS [DescribeEventBus]
(Int -> ReadS DescribeEventBus)
-> ReadS [DescribeEventBus]
-> ReadPrec DescribeEventBus
-> ReadPrec [DescribeEventBus]
-> Read DescribeEventBus
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeEventBus]
$creadListPrec :: ReadPrec [DescribeEventBus]
readPrec :: ReadPrec DescribeEventBus
$creadPrec :: ReadPrec DescribeEventBus
readList :: ReadS [DescribeEventBus]
$creadList :: ReadS [DescribeEventBus]
readsPrec :: Int -> ReadS DescribeEventBus
$creadsPrec :: Int -> ReadS DescribeEventBus
Prelude.Read, Int -> DescribeEventBus -> ShowS
[DescribeEventBus] -> ShowS
DescribeEventBus -> String
(Int -> DescribeEventBus -> ShowS)
-> (DescribeEventBus -> String)
-> ([DescribeEventBus] -> ShowS)
-> Show DescribeEventBus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeEventBus] -> ShowS
$cshowList :: [DescribeEventBus] -> ShowS
show :: DescribeEventBus -> String
$cshow :: DescribeEventBus -> String
showsPrec :: Int -> DescribeEventBus -> ShowS
$cshowsPrec :: Int -> DescribeEventBus -> ShowS
Prelude.Show, (forall x. DescribeEventBus -> Rep DescribeEventBus x)
-> (forall x. Rep DescribeEventBus x -> DescribeEventBus)
-> Generic DescribeEventBus
forall x. Rep DescribeEventBus x -> DescribeEventBus
forall x. DescribeEventBus -> Rep DescribeEventBus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DescribeEventBus x -> DescribeEventBus
$cfrom :: forall x. DescribeEventBus -> Rep DescribeEventBus x
Prelude.Generic)

-- |
-- Create a value of 'DescribeEventBus' 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:
--
-- 'name', 'describeEventBus_name' - The name or ARN of the event bus to show details for. If you omit this,
-- the default event bus is displayed.
newDescribeEventBus ::
  DescribeEventBus
newDescribeEventBus :: DescribeEventBus
newDescribeEventBus =
  DescribeEventBus' :: Maybe Text -> DescribeEventBus
DescribeEventBus' {$sel:name:DescribeEventBus' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing}

-- | The name or ARN of the event bus to show details for. If you omit this,
-- the default event bus is displayed.
describeEventBus_name :: Lens.Lens' DescribeEventBus (Prelude.Maybe Prelude.Text)
describeEventBus_name :: (Maybe Text -> f (Maybe Text))
-> DescribeEventBus -> f DescribeEventBus
describeEventBus_name = (DescribeEventBus -> Maybe Text)
-> (DescribeEventBus -> Maybe Text -> DescribeEventBus)
-> Lens DescribeEventBus DescribeEventBus (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEventBus' {Maybe Text
name :: Maybe Text
$sel:name:DescribeEventBus' :: DescribeEventBus -> Maybe Text
name} -> Maybe Text
name) (\s :: DescribeEventBus
s@DescribeEventBus' {} Maybe Text
a -> DescribeEventBus
s {$sel:name:DescribeEventBus' :: Maybe Text
name = Maybe Text
a} :: DescribeEventBus)

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

instance Prelude.NFData DescribeEventBus

instance Core.ToHeaders DescribeEventBus where
  toHeaders :: DescribeEventBus -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DescribeEventBus -> 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
"AWSEvents.DescribeEventBus" :: 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 DescribeEventBus where
  toJSON :: DescribeEventBus -> Value
toJSON DescribeEventBus' {Maybe Text
name :: Maybe Text
$sel:name:DescribeEventBus' :: DescribeEventBus -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name]
      )

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

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

-- | /See:/ 'newDescribeEventBusResponse' smart constructor.
data DescribeEventBusResponse = DescribeEventBusResponse'
  { -- | The Amazon Resource Name (ARN) of the account permitted to write events
    -- to the current account.
    DescribeEventBusResponse -> Maybe Text
arn :: Prelude.Maybe Prelude.Text,
    -- | The name of the event bus. Currently, this is always @default@.
    DescribeEventBusResponse -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The policy that enables the external account to send events to your
    -- account.
    DescribeEventBusResponse -> Maybe Text
policy :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DescribeEventBusResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (DescribeEventBusResponse -> DescribeEventBusResponse -> Bool
(DescribeEventBusResponse -> DescribeEventBusResponse -> Bool)
-> (DescribeEventBusResponse -> DescribeEventBusResponse -> Bool)
-> Eq DescribeEventBusResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DescribeEventBusResponse -> DescribeEventBusResponse -> Bool
$c/= :: DescribeEventBusResponse -> DescribeEventBusResponse -> Bool
== :: DescribeEventBusResponse -> DescribeEventBusResponse -> Bool
$c== :: DescribeEventBusResponse -> DescribeEventBusResponse -> Bool
Prelude.Eq, ReadPrec [DescribeEventBusResponse]
ReadPrec DescribeEventBusResponse
Int -> ReadS DescribeEventBusResponse
ReadS [DescribeEventBusResponse]
(Int -> ReadS DescribeEventBusResponse)
-> ReadS [DescribeEventBusResponse]
-> ReadPrec DescribeEventBusResponse
-> ReadPrec [DescribeEventBusResponse]
-> Read DescribeEventBusResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DescribeEventBusResponse]
$creadListPrec :: ReadPrec [DescribeEventBusResponse]
readPrec :: ReadPrec DescribeEventBusResponse
$creadPrec :: ReadPrec DescribeEventBusResponse
readList :: ReadS [DescribeEventBusResponse]
$creadList :: ReadS [DescribeEventBusResponse]
readsPrec :: Int -> ReadS DescribeEventBusResponse
$creadsPrec :: Int -> ReadS DescribeEventBusResponse
Prelude.Read, Int -> DescribeEventBusResponse -> ShowS
[DescribeEventBusResponse] -> ShowS
DescribeEventBusResponse -> String
(Int -> DescribeEventBusResponse -> ShowS)
-> (DescribeEventBusResponse -> String)
-> ([DescribeEventBusResponse] -> ShowS)
-> Show DescribeEventBusResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DescribeEventBusResponse] -> ShowS
$cshowList :: [DescribeEventBusResponse] -> ShowS
show :: DescribeEventBusResponse -> String
$cshow :: DescribeEventBusResponse -> String
showsPrec :: Int -> DescribeEventBusResponse -> ShowS
$cshowsPrec :: Int -> DescribeEventBusResponse -> ShowS
Prelude.Show, (forall x.
 DescribeEventBusResponse -> Rep DescribeEventBusResponse x)
-> (forall x.
    Rep DescribeEventBusResponse x -> DescribeEventBusResponse)
-> Generic DescribeEventBusResponse
forall x.
Rep DescribeEventBusResponse x -> DescribeEventBusResponse
forall x.
DescribeEventBusResponse -> Rep DescribeEventBusResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep DescribeEventBusResponse x -> DescribeEventBusResponse
$cfrom :: forall x.
DescribeEventBusResponse -> Rep DescribeEventBusResponse x
Prelude.Generic)

-- |
-- Create a value of 'DescribeEventBusResponse' 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:
--
-- 'arn', 'describeEventBusResponse_arn' - The Amazon Resource Name (ARN) of the account permitted to write events
-- to the current account.
--
-- 'name', 'describeEventBusResponse_name' - The name of the event bus. Currently, this is always @default@.
--
-- 'policy', 'describeEventBusResponse_policy' - The policy that enables the external account to send events to your
-- account.
--
-- 'httpStatus', 'describeEventBusResponse_httpStatus' - The response's http status code.
newDescribeEventBusResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  DescribeEventBusResponse
newDescribeEventBusResponse :: Int -> DescribeEventBusResponse
newDescribeEventBusResponse Int
pHttpStatus_ =
  DescribeEventBusResponse' :: Maybe Text
-> Maybe Text -> Maybe Text -> Int -> DescribeEventBusResponse
DescribeEventBusResponse'
    { $sel:arn:DescribeEventBusResponse' :: Maybe Text
arn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:DescribeEventBusResponse' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:policy:DescribeEventBusResponse' :: Maybe Text
policy = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DescribeEventBusResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The Amazon Resource Name (ARN) of the account permitted to write events
-- to the current account.
describeEventBusResponse_arn :: Lens.Lens' DescribeEventBusResponse (Prelude.Maybe Prelude.Text)
describeEventBusResponse_arn :: (Maybe Text -> f (Maybe Text))
-> DescribeEventBusResponse -> f DescribeEventBusResponse
describeEventBusResponse_arn = (DescribeEventBusResponse -> Maybe Text)
-> (DescribeEventBusResponse
    -> Maybe Text -> DescribeEventBusResponse)
-> Lens
     DescribeEventBusResponse
     DescribeEventBusResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEventBusResponse' {Maybe Text
arn :: Maybe Text
$sel:arn:DescribeEventBusResponse' :: DescribeEventBusResponse -> Maybe Text
arn} -> Maybe Text
arn) (\s :: DescribeEventBusResponse
s@DescribeEventBusResponse' {} Maybe Text
a -> DescribeEventBusResponse
s {$sel:arn:DescribeEventBusResponse' :: Maybe Text
arn = Maybe Text
a} :: DescribeEventBusResponse)

-- | The name of the event bus. Currently, this is always @default@.
describeEventBusResponse_name :: Lens.Lens' DescribeEventBusResponse (Prelude.Maybe Prelude.Text)
describeEventBusResponse_name :: (Maybe Text -> f (Maybe Text))
-> DescribeEventBusResponse -> f DescribeEventBusResponse
describeEventBusResponse_name = (DescribeEventBusResponse -> Maybe Text)
-> (DescribeEventBusResponse
    -> Maybe Text -> DescribeEventBusResponse)
-> Lens
     DescribeEventBusResponse
     DescribeEventBusResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEventBusResponse' {Maybe Text
name :: Maybe Text
$sel:name:DescribeEventBusResponse' :: DescribeEventBusResponse -> Maybe Text
name} -> Maybe Text
name) (\s :: DescribeEventBusResponse
s@DescribeEventBusResponse' {} Maybe Text
a -> DescribeEventBusResponse
s {$sel:name:DescribeEventBusResponse' :: Maybe Text
name = Maybe Text
a} :: DescribeEventBusResponse)

-- | The policy that enables the external account to send events to your
-- account.
describeEventBusResponse_policy :: Lens.Lens' DescribeEventBusResponse (Prelude.Maybe Prelude.Text)
describeEventBusResponse_policy :: (Maybe Text -> f (Maybe Text))
-> DescribeEventBusResponse -> f DescribeEventBusResponse
describeEventBusResponse_policy = (DescribeEventBusResponse -> Maybe Text)
-> (DescribeEventBusResponse
    -> Maybe Text -> DescribeEventBusResponse)
-> Lens
     DescribeEventBusResponse
     DescribeEventBusResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DescribeEventBusResponse' {Maybe Text
policy :: Maybe Text
$sel:policy:DescribeEventBusResponse' :: DescribeEventBusResponse -> Maybe Text
policy} -> Maybe Text
policy) (\s :: DescribeEventBusResponse
s@DescribeEventBusResponse' {} Maybe Text
a -> DescribeEventBusResponse
s {$sel:policy:DescribeEventBusResponse' :: Maybe Text
policy = Maybe Text
a} :: DescribeEventBusResponse)

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

instance Prelude.NFData DescribeEventBusResponse