{-# 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.IoT.SetDefaultAuthorizer
-- 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)
--
-- Sets the default authorizer. This will be used if a websocket connection
-- is made without specifying an authorizer.
--
-- Requires permission to access the
-- <https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions SetDefaultAuthorizer>
-- action.
module Amazonka.IoT.SetDefaultAuthorizer
  ( -- * Creating a Request
    SetDefaultAuthorizer (..),
    newSetDefaultAuthorizer,

    -- * Request Lenses
    setDefaultAuthorizer_authorizerName,

    -- * Destructuring the Response
    SetDefaultAuthorizerResponse (..),
    newSetDefaultAuthorizerResponse,

    -- * Response Lenses
    setDefaultAuthorizerResponse_authorizerName,
    setDefaultAuthorizerResponse_authorizerArn,
    setDefaultAuthorizerResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.IoT.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:/ 'newSetDefaultAuthorizer' smart constructor.
data SetDefaultAuthorizer = SetDefaultAuthorizer'
  { -- | The authorizer name.
    SetDefaultAuthorizer -> Text
authorizerName :: Prelude.Text
  }
  deriving (SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool
(SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool)
-> (SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool)
-> Eq SetDefaultAuthorizer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool
$c/= :: SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool
== :: SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool
$c== :: SetDefaultAuthorizer -> SetDefaultAuthorizer -> Bool
Prelude.Eq, ReadPrec [SetDefaultAuthorizer]
ReadPrec SetDefaultAuthorizer
Int -> ReadS SetDefaultAuthorizer
ReadS [SetDefaultAuthorizer]
(Int -> ReadS SetDefaultAuthorizer)
-> ReadS [SetDefaultAuthorizer]
-> ReadPrec SetDefaultAuthorizer
-> ReadPrec [SetDefaultAuthorizer]
-> Read SetDefaultAuthorizer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetDefaultAuthorizer]
$creadListPrec :: ReadPrec [SetDefaultAuthorizer]
readPrec :: ReadPrec SetDefaultAuthorizer
$creadPrec :: ReadPrec SetDefaultAuthorizer
readList :: ReadS [SetDefaultAuthorizer]
$creadList :: ReadS [SetDefaultAuthorizer]
readsPrec :: Int -> ReadS SetDefaultAuthorizer
$creadsPrec :: Int -> ReadS SetDefaultAuthorizer
Prelude.Read, Int -> SetDefaultAuthorizer -> ShowS
[SetDefaultAuthorizer] -> ShowS
SetDefaultAuthorizer -> String
(Int -> SetDefaultAuthorizer -> ShowS)
-> (SetDefaultAuthorizer -> String)
-> ([SetDefaultAuthorizer] -> ShowS)
-> Show SetDefaultAuthorizer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetDefaultAuthorizer] -> ShowS
$cshowList :: [SetDefaultAuthorizer] -> ShowS
show :: SetDefaultAuthorizer -> String
$cshow :: SetDefaultAuthorizer -> String
showsPrec :: Int -> SetDefaultAuthorizer -> ShowS
$cshowsPrec :: Int -> SetDefaultAuthorizer -> ShowS
Prelude.Show, (forall x. SetDefaultAuthorizer -> Rep SetDefaultAuthorizer x)
-> (forall x. Rep SetDefaultAuthorizer x -> SetDefaultAuthorizer)
-> Generic SetDefaultAuthorizer
forall x. Rep SetDefaultAuthorizer x -> SetDefaultAuthorizer
forall x. SetDefaultAuthorizer -> Rep SetDefaultAuthorizer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetDefaultAuthorizer x -> SetDefaultAuthorizer
$cfrom :: forall x. SetDefaultAuthorizer -> Rep SetDefaultAuthorizer x
Prelude.Generic)

-- |
-- Create a value of 'SetDefaultAuthorizer' 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:
--
-- 'authorizerName', 'setDefaultAuthorizer_authorizerName' - The authorizer name.
newSetDefaultAuthorizer ::
  -- | 'authorizerName'
  Prelude.Text ->
  SetDefaultAuthorizer
newSetDefaultAuthorizer :: Text -> SetDefaultAuthorizer
newSetDefaultAuthorizer Text
pAuthorizerName_ =
  SetDefaultAuthorizer' :: Text -> SetDefaultAuthorizer
SetDefaultAuthorizer'
    { $sel:authorizerName:SetDefaultAuthorizer' :: Text
authorizerName =
        Text
pAuthorizerName_
    }

-- | The authorizer name.
setDefaultAuthorizer_authorizerName :: Lens.Lens' SetDefaultAuthorizer Prelude.Text
setDefaultAuthorizer_authorizerName :: (Text -> f Text) -> SetDefaultAuthorizer -> f SetDefaultAuthorizer
setDefaultAuthorizer_authorizerName = (SetDefaultAuthorizer -> Text)
-> (SetDefaultAuthorizer -> Text -> SetDefaultAuthorizer)
-> Lens SetDefaultAuthorizer SetDefaultAuthorizer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDefaultAuthorizer' {Text
authorizerName :: Text
$sel:authorizerName:SetDefaultAuthorizer' :: SetDefaultAuthorizer -> Text
authorizerName} -> Text
authorizerName) (\s :: SetDefaultAuthorizer
s@SetDefaultAuthorizer' {} Text
a -> SetDefaultAuthorizer
s {$sel:authorizerName:SetDefaultAuthorizer' :: Text
authorizerName = Text
a} :: SetDefaultAuthorizer)

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

instance Prelude.NFData SetDefaultAuthorizer

instance Core.ToHeaders SetDefaultAuthorizer where
  toHeaders :: SetDefaultAuthorizer -> ResponseHeaders
toHeaders = ResponseHeaders -> SetDefaultAuthorizer -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const ResponseHeaders
forall a. Monoid a => a
Prelude.mempty

instance Core.ToJSON SetDefaultAuthorizer where
  toJSON :: SetDefaultAuthorizer -> Value
toJSON SetDefaultAuthorizer' {Text
authorizerName :: Text
$sel:authorizerName:SetDefaultAuthorizer' :: SetDefaultAuthorizer -> 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
"authorizerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
authorizerName)
          ]
      )

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

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

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

-- |
-- Create a value of 'SetDefaultAuthorizerResponse' 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:
--
-- 'authorizerName', 'setDefaultAuthorizerResponse_authorizerName' - The authorizer name.
--
-- 'authorizerArn', 'setDefaultAuthorizerResponse_authorizerArn' - The authorizer ARN.
--
-- 'httpStatus', 'setDefaultAuthorizerResponse_httpStatus' - The response's http status code.
newSetDefaultAuthorizerResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  SetDefaultAuthorizerResponse
newSetDefaultAuthorizerResponse :: Int -> SetDefaultAuthorizerResponse
newSetDefaultAuthorizerResponse Int
pHttpStatus_ =
  SetDefaultAuthorizerResponse' :: Maybe Text -> Maybe Text -> Int -> SetDefaultAuthorizerResponse
SetDefaultAuthorizerResponse'
    { $sel:authorizerName:SetDefaultAuthorizerResponse' :: Maybe Text
authorizerName =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:authorizerArn:SetDefaultAuthorizerResponse' :: Maybe Text
authorizerArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:SetDefaultAuthorizerResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The authorizer name.
setDefaultAuthorizerResponse_authorizerName :: Lens.Lens' SetDefaultAuthorizerResponse (Prelude.Maybe Prelude.Text)
setDefaultAuthorizerResponse_authorizerName :: (Maybe Text -> f (Maybe Text))
-> SetDefaultAuthorizerResponse -> f SetDefaultAuthorizerResponse
setDefaultAuthorizerResponse_authorizerName = (SetDefaultAuthorizerResponse -> Maybe Text)
-> (SetDefaultAuthorizerResponse
    -> Maybe Text -> SetDefaultAuthorizerResponse)
-> Lens
     SetDefaultAuthorizerResponse
     SetDefaultAuthorizerResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDefaultAuthorizerResponse' {Maybe Text
authorizerName :: Maybe Text
$sel:authorizerName:SetDefaultAuthorizerResponse' :: SetDefaultAuthorizerResponse -> Maybe Text
authorizerName} -> Maybe Text
authorizerName) (\s :: SetDefaultAuthorizerResponse
s@SetDefaultAuthorizerResponse' {} Maybe Text
a -> SetDefaultAuthorizerResponse
s {$sel:authorizerName:SetDefaultAuthorizerResponse' :: Maybe Text
authorizerName = Maybe Text
a} :: SetDefaultAuthorizerResponse)

-- | The authorizer ARN.
setDefaultAuthorizerResponse_authorizerArn :: Lens.Lens' SetDefaultAuthorizerResponse (Prelude.Maybe Prelude.Text)
setDefaultAuthorizerResponse_authorizerArn :: (Maybe Text -> f (Maybe Text))
-> SetDefaultAuthorizerResponse -> f SetDefaultAuthorizerResponse
setDefaultAuthorizerResponse_authorizerArn = (SetDefaultAuthorizerResponse -> Maybe Text)
-> (SetDefaultAuthorizerResponse
    -> Maybe Text -> SetDefaultAuthorizerResponse)
-> Lens
     SetDefaultAuthorizerResponse
     SetDefaultAuthorizerResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetDefaultAuthorizerResponse' {Maybe Text
authorizerArn :: Maybe Text
$sel:authorizerArn:SetDefaultAuthorizerResponse' :: SetDefaultAuthorizerResponse -> Maybe Text
authorizerArn} -> Maybe Text
authorizerArn) (\s :: SetDefaultAuthorizerResponse
s@SetDefaultAuthorizerResponse' {} Maybe Text
a -> SetDefaultAuthorizerResponse
s {$sel:authorizerArn:SetDefaultAuthorizerResponse' :: Maybe Text
authorizerArn = Maybe Text
a} :: SetDefaultAuthorizerResponse)

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

instance Prelude.NFData SetDefaultAuthorizerResponse