{-# 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.IVS.CreateStreamKey
-- 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 a stream key, used to initiate a stream, for the specified
-- channel ARN.
--
-- Note that CreateChannel creates a stream key. If you subsequently use
-- CreateStreamKey on the same channel, it will fail because a stream key
-- already exists and there is a limit of 1 stream key per channel. To
-- reset the stream key on a channel, use DeleteStreamKey and then
-- CreateStreamKey.
module Amazonka.IVS.CreateStreamKey
  ( -- * Creating a Request
    CreateStreamKey (..),
    newCreateStreamKey,

    -- * Request Lenses
    createStreamKey_tags,
    createStreamKey_channelArn,

    -- * Destructuring the Response
    CreateStreamKeyResponse (..),
    newCreateStreamKeyResponse,

    -- * Response Lenses
    createStreamKeyResponse_streamKey,
    createStreamKeyResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IVS.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:/ 'newCreateStreamKey' smart constructor.
data CreateStreamKey = CreateStreamKey'
  { -- | Array of 1-50 maps, each of the form @string:string (key:value)@.
    CreateStreamKey -> Maybe (HashMap Text Text)
tags :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | ARN of the channel for which to create the stream key.
    CreateStreamKey -> Text
channelArn :: Prelude.Text
  }
  deriving (CreateStreamKey -> CreateStreamKey -> Bool
(CreateStreamKey -> CreateStreamKey -> Bool)
-> (CreateStreamKey -> CreateStreamKey -> Bool)
-> Eq CreateStreamKey
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateStreamKey -> CreateStreamKey -> Bool
$c/= :: CreateStreamKey -> CreateStreamKey -> Bool
== :: CreateStreamKey -> CreateStreamKey -> Bool
$c== :: CreateStreamKey -> CreateStreamKey -> Bool
Prelude.Eq, ReadPrec [CreateStreamKey]
ReadPrec CreateStreamKey
Int -> ReadS CreateStreamKey
ReadS [CreateStreamKey]
(Int -> ReadS CreateStreamKey)
-> ReadS [CreateStreamKey]
-> ReadPrec CreateStreamKey
-> ReadPrec [CreateStreamKey]
-> Read CreateStreamKey
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateStreamKey]
$creadListPrec :: ReadPrec [CreateStreamKey]
readPrec :: ReadPrec CreateStreamKey
$creadPrec :: ReadPrec CreateStreamKey
readList :: ReadS [CreateStreamKey]
$creadList :: ReadS [CreateStreamKey]
readsPrec :: Int -> ReadS CreateStreamKey
$creadsPrec :: Int -> ReadS CreateStreamKey
Prelude.Read, Int -> CreateStreamKey -> ShowS
[CreateStreamKey] -> ShowS
CreateStreamKey -> String
(Int -> CreateStreamKey -> ShowS)
-> (CreateStreamKey -> String)
-> ([CreateStreamKey] -> ShowS)
-> Show CreateStreamKey
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateStreamKey] -> ShowS
$cshowList :: [CreateStreamKey] -> ShowS
show :: CreateStreamKey -> String
$cshow :: CreateStreamKey -> String
showsPrec :: Int -> CreateStreamKey -> ShowS
$cshowsPrec :: Int -> CreateStreamKey -> ShowS
Prelude.Show, (forall x. CreateStreamKey -> Rep CreateStreamKey x)
-> (forall x. Rep CreateStreamKey x -> CreateStreamKey)
-> Generic CreateStreamKey
forall x. Rep CreateStreamKey x -> CreateStreamKey
forall x. CreateStreamKey -> Rep CreateStreamKey x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateStreamKey x -> CreateStreamKey
$cfrom :: forall x. CreateStreamKey -> Rep CreateStreamKey x
Prelude.Generic)

-- |
-- Create a value of 'CreateStreamKey' 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:
--
-- 'tags', 'createStreamKey_tags' - Array of 1-50 maps, each of the form @string:string (key:value)@.
--
-- 'channelArn', 'createStreamKey_channelArn' - ARN of the channel for which to create the stream key.
newCreateStreamKey ::
  -- | 'channelArn'
  Prelude.Text ->
  CreateStreamKey
newCreateStreamKey :: Text -> CreateStreamKey
newCreateStreamKey Text
pChannelArn_ =
  CreateStreamKey' :: Maybe (HashMap Text Text) -> Text -> CreateStreamKey
CreateStreamKey'
    { $sel:tags:CreateStreamKey' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:channelArn:CreateStreamKey' :: Text
channelArn = Text
pChannelArn_
    }

-- | Array of 1-50 maps, each of the form @string:string (key:value)@.
createStreamKey_tags :: Lens.Lens' CreateStreamKey (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
createStreamKey_tags :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateStreamKey -> f CreateStreamKey
createStreamKey_tags = (CreateStreamKey -> Maybe (HashMap Text Text))
-> (CreateStreamKey
    -> Maybe (HashMap Text Text) -> CreateStreamKey)
-> Lens
     CreateStreamKey
     CreateStreamKey
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStreamKey' {Maybe (HashMap Text Text)
tags :: Maybe (HashMap Text Text)
$sel:tags:CreateStreamKey' :: CreateStreamKey -> Maybe (HashMap Text Text)
tags} -> Maybe (HashMap Text Text)
tags) (\s :: CreateStreamKey
s@CreateStreamKey' {} Maybe (HashMap Text Text)
a -> CreateStreamKey
s {$sel:tags:CreateStreamKey' :: Maybe (HashMap Text Text)
tags = Maybe (HashMap Text Text)
a} :: CreateStreamKey) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> CreateStreamKey -> f CreateStreamKey)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> CreateStreamKey
-> f CreateStreamKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | ARN of the channel for which to create the stream key.
createStreamKey_channelArn :: Lens.Lens' CreateStreamKey Prelude.Text
createStreamKey_channelArn :: (Text -> f Text) -> CreateStreamKey -> f CreateStreamKey
createStreamKey_channelArn = (CreateStreamKey -> Text)
-> (CreateStreamKey -> Text -> CreateStreamKey)
-> Lens CreateStreamKey CreateStreamKey Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStreamKey' {Text
channelArn :: Text
$sel:channelArn:CreateStreamKey' :: CreateStreamKey -> Text
channelArn} -> Text
channelArn) (\s :: CreateStreamKey
s@CreateStreamKey' {} Text
a -> CreateStreamKey
s {$sel:channelArn:CreateStreamKey' :: Text
channelArn = Text
a} :: CreateStreamKey)

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

instance Prelude.NFData CreateStreamKey

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

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

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

-- | /See:/ 'newCreateStreamKeyResponse' smart constructor.
data CreateStreamKeyResponse = CreateStreamKeyResponse'
  { -- | Stream key used to authenticate an RTMPS stream for ingestion.
    CreateStreamKeyResponse -> Maybe StreamKey
streamKey :: Prelude.Maybe StreamKey,
    -- | The response's http status code.
    CreateStreamKeyResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
(CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool)
-> (CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool)
-> Eq CreateStreamKeyResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
$c/= :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
== :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
$c== :: CreateStreamKeyResponse -> CreateStreamKeyResponse -> Bool
Prelude.Eq, Int -> CreateStreamKeyResponse -> ShowS
[CreateStreamKeyResponse] -> ShowS
CreateStreamKeyResponse -> String
(Int -> CreateStreamKeyResponse -> ShowS)
-> (CreateStreamKeyResponse -> String)
-> ([CreateStreamKeyResponse] -> ShowS)
-> Show CreateStreamKeyResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateStreamKeyResponse] -> ShowS
$cshowList :: [CreateStreamKeyResponse] -> ShowS
show :: CreateStreamKeyResponse -> String
$cshow :: CreateStreamKeyResponse -> String
showsPrec :: Int -> CreateStreamKeyResponse -> ShowS
$cshowsPrec :: Int -> CreateStreamKeyResponse -> ShowS
Prelude.Show, (forall x.
 CreateStreamKeyResponse -> Rep CreateStreamKeyResponse x)
-> (forall x.
    Rep CreateStreamKeyResponse x -> CreateStreamKeyResponse)
-> Generic CreateStreamKeyResponse
forall x. Rep CreateStreamKeyResponse x -> CreateStreamKeyResponse
forall x. CreateStreamKeyResponse -> Rep CreateStreamKeyResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateStreamKeyResponse x -> CreateStreamKeyResponse
$cfrom :: forall x. CreateStreamKeyResponse -> Rep CreateStreamKeyResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreateStreamKeyResponse' 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:
--
-- 'streamKey', 'createStreamKeyResponse_streamKey' - Stream key used to authenticate an RTMPS stream for ingestion.
--
-- 'httpStatus', 'createStreamKeyResponse_httpStatus' - The response's http status code.
newCreateStreamKeyResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreateStreamKeyResponse
newCreateStreamKeyResponse :: Int -> CreateStreamKeyResponse
newCreateStreamKeyResponse Int
pHttpStatus_ =
  CreateStreamKeyResponse' :: Maybe StreamKey -> Int -> CreateStreamKeyResponse
CreateStreamKeyResponse'
    { $sel:streamKey:CreateStreamKeyResponse' :: Maybe StreamKey
streamKey =
        Maybe StreamKey
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreateStreamKeyResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Stream key used to authenticate an RTMPS stream for ingestion.
createStreamKeyResponse_streamKey :: Lens.Lens' CreateStreamKeyResponse (Prelude.Maybe StreamKey)
createStreamKeyResponse_streamKey :: (Maybe StreamKey -> f (Maybe StreamKey))
-> CreateStreamKeyResponse -> f CreateStreamKeyResponse
createStreamKeyResponse_streamKey = (CreateStreamKeyResponse -> Maybe StreamKey)
-> (CreateStreamKeyResponse
    -> Maybe StreamKey -> CreateStreamKeyResponse)
-> Lens
     CreateStreamKeyResponse
     CreateStreamKeyResponse
     (Maybe StreamKey)
     (Maybe StreamKey)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateStreamKeyResponse' {Maybe StreamKey
streamKey :: Maybe StreamKey
$sel:streamKey:CreateStreamKeyResponse' :: CreateStreamKeyResponse -> Maybe StreamKey
streamKey} -> Maybe StreamKey
streamKey) (\s :: CreateStreamKeyResponse
s@CreateStreamKeyResponse' {} Maybe StreamKey
a -> CreateStreamKeyResponse
s {$sel:streamKey:CreateStreamKeyResponse' :: Maybe StreamKey
streamKey = Maybe StreamKey
a} :: CreateStreamKeyResponse)

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

instance Prelude.NFData CreateStreamKeyResponse