{-# 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.WorkDocs.GetCurrentUser
-- 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)
--
-- Retrieves details of the current user for whom the authentication token
-- was generated. This is not a valid action for SigV4 (administrative API)
-- clients.
--
-- This action requires an authentication token. To get an authentication
-- token, register an application with Amazon WorkDocs. For more
-- information, see
-- <https://docs.aws.amazon.com/workdocs/latest/developerguide/wd-auth-user.html Authentication and Access Control for User Applications>
-- in the /Amazon WorkDocs Developer Guide/.
module Amazonka.WorkDocs.GetCurrentUser
  ( -- * Creating a Request
    GetCurrentUser (..),
    newGetCurrentUser,

    -- * Request Lenses
    getCurrentUser_authenticationToken,

    -- * Destructuring the Response
    GetCurrentUserResponse (..),
    newGetCurrentUserResponse,

    -- * Response Lenses
    getCurrentUserResponse_user,
    getCurrentUserResponse_httpStatus,
  )
where

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
import Amazonka.WorkDocs.Types

-- | /See:/ 'newGetCurrentUser' smart constructor.
data GetCurrentUser = GetCurrentUser'
  { -- | Amazon WorkDocs authentication token.
    GetCurrentUser -> Sensitive Text
authenticationToken :: Core.Sensitive Prelude.Text
  }
  deriving (GetCurrentUser -> GetCurrentUser -> Bool
(GetCurrentUser -> GetCurrentUser -> Bool)
-> (GetCurrentUser -> GetCurrentUser -> Bool) -> Eq GetCurrentUser
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetCurrentUser -> GetCurrentUser -> Bool
$c/= :: GetCurrentUser -> GetCurrentUser -> Bool
== :: GetCurrentUser -> GetCurrentUser -> Bool
$c== :: GetCurrentUser -> GetCurrentUser -> Bool
Prelude.Eq, Int -> GetCurrentUser -> ShowS
[GetCurrentUser] -> ShowS
GetCurrentUser -> String
(Int -> GetCurrentUser -> ShowS)
-> (GetCurrentUser -> String)
-> ([GetCurrentUser] -> ShowS)
-> Show GetCurrentUser
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetCurrentUser] -> ShowS
$cshowList :: [GetCurrentUser] -> ShowS
show :: GetCurrentUser -> String
$cshow :: GetCurrentUser -> String
showsPrec :: Int -> GetCurrentUser -> ShowS
$cshowsPrec :: Int -> GetCurrentUser -> ShowS
Prelude.Show, (forall x. GetCurrentUser -> Rep GetCurrentUser x)
-> (forall x. Rep GetCurrentUser x -> GetCurrentUser)
-> Generic GetCurrentUser
forall x. Rep GetCurrentUser x -> GetCurrentUser
forall x. GetCurrentUser -> Rep GetCurrentUser x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetCurrentUser x -> GetCurrentUser
$cfrom :: forall x. GetCurrentUser -> Rep GetCurrentUser x
Prelude.Generic)

-- |
-- Create a value of 'GetCurrentUser' 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:
--
-- 'authenticationToken', 'getCurrentUser_authenticationToken' - Amazon WorkDocs authentication token.
newGetCurrentUser ::
  -- | 'authenticationToken'
  Prelude.Text ->
  GetCurrentUser
newGetCurrentUser :: Text -> GetCurrentUser
newGetCurrentUser Text
pAuthenticationToken_ =
  GetCurrentUser' :: Sensitive Text -> GetCurrentUser
GetCurrentUser'
    { $sel:authenticationToken:GetCurrentUser' :: Sensitive Text
authenticationToken =
        Tagged Text (Identity Text)
-> Tagged (Sensitive Text) (Identity (Sensitive Text))
forall a. Iso' (Sensitive a) a
Core._Sensitive (Tagged Text (Identity Text)
 -> Tagged (Sensitive Text) (Identity (Sensitive Text)))
-> Text -> Sensitive Text
forall t b. AReview t b -> b -> t
Lens.# Text
pAuthenticationToken_
    }

-- | Amazon WorkDocs authentication token.
getCurrentUser_authenticationToken :: Lens.Lens' GetCurrentUser Prelude.Text
getCurrentUser_authenticationToken :: (Text -> f Text) -> GetCurrentUser -> f GetCurrentUser
getCurrentUser_authenticationToken = (GetCurrentUser -> Sensitive Text)
-> (GetCurrentUser -> Sensitive Text -> GetCurrentUser)
-> Lens
     GetCurrentUser GetCurrentUser (Sensitive Text) (Sensitive Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCurrentUser' {Sensitive Text
authenticationToken :: Sensitive Text
$sel:authenticationToken:GetCurrentUser' :: GetCurrentUser -> Sensitive Text
authenticationToken} -> Sensitive Text
authenticationToken) (\s :: GetCurrentUser
s@GetCurrentUser' {} Sensitive Text
a -> GetCurrentUser
s {$sel:authenticationToken:GetCurrentUser' :: Sensitive Text
authenticationToken = Sensitive Text
a} :: GetCurrentUser) ((Sensitive Text -> f (Sensitive Text))
 -> GetCurrentUser -> f GetCurrentUser)
-> ((Text -> f Text) -> Sensitive Text -> f (Sensitive Text))
-> (Text -> f Text)
-> GetCurrentUser
-> f GetCurrentUser
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (Text -> f Text) -> Sensitive Text -> f (Sensitive Text)
forall a. Iso' (Sensitive a) a
Core._Sensitive

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

instance Prelude.NFData GetCurrentUser

instance Core.ToHeaders GetCurrentUser where
  toHeaders :: GetCurrentUser -> ResponseHeaders
toHeaders GetCurrentUser' {Sensitive Text
authenticationToken :: Sensitive Text
$sel:authenticationToken:GetCurrentUser' :: GetCurrentUser -> Sensitive Text
..} =
    [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ HeaderName
"Authentication" HeaderName -> Sensitive Text -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# Sensitive Text
authenticationToken,
        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.ToPath GetCurrentUser where
  toPath :: GetCurrentUser -> ByteString
toPath = ByteString -> GetCurrentUser -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/api/v1/me"

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

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

-- |
-- Create a value of 'GetCurrentUserResponse' 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:
--
-- 'user', 'getCurrentUserResponse_user' - Metadata of the user.
--
-- 'httpStatus', 'getCurrentUserResponse_httpStatus' - The response's http status code.
newGetCurrentUserResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetCurrentUserResponse
newGetCurrentUserResponse :: Int -> GetCurrentUserResponse
newGetCurrentUserResponse Int
pHttpStatus_ =
  GetCurrentUserResponse' :: Maybe User -> Int -> GetCurrentUserResponse
GetCurrentUserResponse'
    { $sel:user:GetCurrentUserResponse' :: Maybe User
user = Maybe User
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetCurrentUserResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Metadata of the user.
getCurrentUserResponse_user :: Lens.Lens' GetCurrentUserResponse (Prelude.Maybe User)
getCurrentUserResponse_user :: (Maybe User -> f (Maybe User))
-> GetCurrentUserResponse -> f GetCurrentUserResponse
getCurrentUserResponse_user = (GetCurrentUserResponse -> Maybe User)
-> (GetCurrentUserResponse -> Maybe User -> GetCurrentUserResponse)
-> Lens
     GetCurrentUserResponse
     GetCurrentUserResponse
     (Maybe User)
     (Maybe User)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetCurrentUserResponse' {Maybe User
user :: Maybe User
$sel:user:GetCurrentUserResponse' :: GetCurrentUserResponse -> Maybe User
user} -> Maybe User
user) (\s :: GetCurrentUserResponse
s@GetCurrentUserResponse' {} Maybe User
a -> GetCurrentUserResponse
s {$sel:user:GetCurrentUserResponse' :: Maybe User
user = Maybe User
a} :: GetCurrentUserResponse)

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

instance Prelude.NFData GetCurrentUserResponse