{-# 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.SecurityHub.GetMembers
-- 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)
--
-- Returns the details for the Security Hub member accounts for the
-- specified account IDs.
--
-- An administrator account can be either the delegated Security Hub
-- administrator account for an organization or an administrator account
-- that enabled Security Hub manually.
--
-- The results include both member accounts that are managed using
-- Organizations and accounts that were invited manually.
module Amazonka.SecurityHub.GetMembers
  ( -- * Creating a Request
    GetMembers (..),
    newGetMembers,

    -- * Request Lenses
    getMembers_accountIds,

    -- * Destructuring the Response
    GetMembersResponse (..),
    newGetMembersResponse,

    -- * Response Lenses
    getMembersResponse_members,
    getMembersResponse_unprocessedAccounts,
    getMembersResponse_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.SecurityHub.Types

-- | /See:/ 'newGetMembers' smart constructor.
data GetMembers = GetMembers'
  { -- | The list of account IDs for the Security Hub member accounts to return
    -- the details for.
    GetMembers -> [Text]
accountIds :: [Prelude.Text]
  }
  deriving (GetMembers -> GetMembers -> Bool
(GetMembers -> GetMembers -> Bool)
-> (GetMembers -> GetMembers -> Bool) -> Eq GetMembers
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetMembers -> GetMembers -> Bool
$c/= :: GetMembers -> GetMembers -> Bool
== :: GetMembers -> GetMembers -> Bool
$c== :: GetMembers -> GetMembers -> Bool
Prelude.Eq, ReadPrec [GetMembers]
ReadPrec GetMembers
Int -> ReadS GetMembers
ReadS [GetMembers]
(Int -> ReadS GetMembers)
-> ReadS [GetMembers]
-> ReadPrec GetMembers
-> ReadPrec [GetMembers]
-> Read GetMembers
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetMembers]
$creadListPrec :: ReadPrec [GetMembers]
readPrec :: ReadPrec GetMembers
$creadPrec :: ReadPrec GetMembers
readList :: ReadS [GetMembers]
$creadList :: ReadS [GetMembers]
readsPrec :: Int -> ReadS GetMembers
$creadsPrec :: Int -> ReadS GetMembers
Prelude.Read, Int -> GetMembers -> ShowS
[GetMembers] -> ShowS
GetMembers -> String
(Int -> GetMembers -> ShowS)
-> (GetMembers -> String)
-> ([GetMembers] -> ShowS)
-> Show GetMembers
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetMembers] -> ShowS
$cshowList :: [GetMembers] -> ShowS
show :: GetMembers -> String
$cshow :: GetMembers -> String
showsPrec :: Int -> GetMembers -> ShowS
$cshowsPrec :: Int -> GetMembers -> ShowS
Prelude.Show, (forall x. GetMembers -> Rep GetMembers x)
-> (forall x. Rep GetMembers x -> GetMembers) -> Generic GetMembers
forall x. Rep GetMembers x -> GetMembers
forall x. GetMembers -> Rep GetMembers x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetMembers x -> GetMembers
$cfrom :: forall x. GetMembers -> Rep GetMembers x
Prelude.Generic)

-- |
-- Create a value of 'GetMembers' 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:
--
-- 'accountIds', 'getMembers_accountIds' - The list of account IDs for the Security Hub member accounts to return
-- the details for.
newGetMembers ::
  GetMembers
newGetMembers :: GetMembers
newGetMembers =
  GetMembers' :: [Text] -> GetMembers
GetMembers' {$sel:accountIds:GetMembers' :: [Text]
accountIds = [Text]
forall a. Monoid a => a
Prelude.mempty}

-- | The list of account IDs for the Security Hub member accounts to return
-- the details for.
getMembers_accountIds :: Lens.Lens' GetMembers [Prelude.Text]
getMembers_accountIds :: ([Text] -> f [Text]) -> GetMembers -> f GetMembers
getMembers_accountIds = (GetMembers -> [Text])
-> (GetMembers -> [Text] -> GetMembers)
-> Lens GetMembers GetMembers [Text] [Text]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetMembers' {[Text]
accountIds :: [Text]
$sel:accountIds:GetMembers' :: GetMembers -> [Text]
accountIds} -> [Text]
accountIds) (\s :: GetMembers
s@GetMembers' {} [Text]
a -> GetMembers
s {$sel:accountIds:GetMembers' :: [Text]
accountIds = [Text]
a} :: GetMembers) (([Text] -> f [Text]) -> GetMembers -> f GetMembers)
-> (([Text] -> f [Text]) -> [Text] -> f [Text])
-> ([Text] -> f [Text])
-> GetMembers
-> f GetMembers
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Text] -> f [Text]) -> [Text] -> f [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.AWSRequest GetMembers where
  type AWSResponse GetMembers = GetMembersResponse
  request :: GetMembers -> Request GetMembers
request = Service -> GetMembers -> Request GetMembers
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy GetMembers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetMembers)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse GetMembers))
-> Logger
-> Service
-> Proxy GetMembers
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetMembers)))
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 [Member] -> Maybe [Result] -> Int -> GetMembersResponse
GetMembersResponse'
            (Maybe [Member] -> Maybe [Result] -> Int -> GetMembersResponse)
-> Either String (Maybe [Member])
-> Either String (Maybe [Result] -> Int -> GetMembersResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe (Maybe [Member]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Members" Either String (Maybe (Maybe [Member]))
-> Maybe [Member] -> Either String (Maybe [Member])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Member]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Maybe [Result] -> Int -> GetMembersResponse)
-> Either String (Maybe [Result])
-> Either String (Int -> GetMembersResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Either String (Maybe (Maybe [Result]))
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"UnprocessedAccounts"
                            Either String (Maybe (Maybe [Result]))
-> Maybe [Result] -> Either String (Maybe [Result])
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ Maybe [Result]
forall a. Monoid a => a
Prelude.mempty
                        )
            Either String (Int -> GetMembersResponse)
-> Either String Int -> Either String GetMembersResponse
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 GetMembers

instance Prelude.NFData GetMembers

instance Core.ToHeaders GetMembers where
  toHeaders :: GetMembers -> ResponseHeaders
toHeaders =
    ResponseHeaders -> GetMembers -> 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 GetMembers where
  toJSON :: GetMembers -> Value
toJSON GetMembers' {[Text]
accountIds :: [Text]
$sel:accountIds:GetMembers' :: GetMembers -> [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
"AccountIds" Text -> [Text] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [Text]
accountIds)]
      )

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

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

-- | /See:/ 'newGetMembersResponse' smart constructor.
data GetMembersResponse = GetMembersResponse'
  { -- | The list of details about the Security Hub member accounts.
    GetMembersResponse -> Maybe [Member]
members :: Prelude.Maybe [Member],
    -- | The list of Amazon Web Services accounts that could not be processed.
    -- For each account, the list includes the account ID and the email
    -- address.
    GetMembersResponse -> Maybe [Result]
unprocessedAccounts :: Prelude.Maybe [Result],
    -- | The response's http status code.
    GetMembersResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetMembersResponse -> GetMembersResponse -> Bool
(GetMembersResponse -> GetMembersResponse -> Bool)
-> (GetMembersResponse -> GetMembersResponse -> Bool)
-> Eq GetMembersResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetMembersResponse -> GetMembersResponse -> Bool
$c/= :: GetMembersResponse -> GetMembersResponse -> Bool
== :: GetMembersResponse -> GetMembersResponse -> Bool
$c== :: GetMembersResponse -> GetMembersResponse -> Bool
Prelude.Eq, ReadPrec [GetMembersResponse]
ReadPrec GetMembersResponse
Int -> ReadS GetMembersResponse
ReadS [GetMembersResponse]
(Int -> ReadS GetMembersResponse)
-> ReadS [GetMembersResponse]
-> ReadPrec GetMembersResponse
-> ReadPrec [GetMembersResponse]
-> Read GetMembersResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetMembersResponse]
$creadListPrec :: ReadPrec [GetMembersResponse]
readPrec :: ReadPrec GetMembersResponse
$creadPrec :: ReadPrec GetMembersResponse
readList :: ReadS [GetMembersResponse]
$creadList :: ReadS [GetMembersResponse]
readsPrec :: Int -> ReadS GetMembersResponse
$creadsPrec :: Int -> ReadS GetMembersResponse
Prelude.Read, Int -> GetMembersResponse -> ShowS
[GetMembersResponse] -> ShowS
GetMembersResponse -> String
(Int -> GetMembersResponse -> ShowS)
-> (GetMembersResponse -> String)
-> ([GetMembersResponse] -> ShowS)
-> Show GetMembersResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetMembersResponse] -> ShowS
$cshowList :: [GetMembersResponse] -> ShowS
show :: GetMembersResponse -> String
$cshow :: GetMembersResponse -> String
showsPrec :: Int -> GetMembersResponse -> ShowS
$cshowsPrec :: Int -> GetMembersResponse -> ShowS
Prelude.Show, (forall x. GetMembersResponse -> Rep GetMembersResponse x)
-> (forall x. Rep GetMembersResponse x -> GetMembersResponse)
-> Generic GetMembersResponse
forall x. Rep GetMembersResponse x -> GetMembersResponse
forall x. GetMembersResponse -> Rep GetMembersResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetMembersResponse x -> GetMembersResponse
$cfrom :: forall x. GetMembersResponse -> Rep GetMembersResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetMembersResponse' 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:
--
-- 'members', 'getMembersResponse_members' - The list of details about the Security Hub member accounts.
--
-- 'unprocessedAccounts', 'getMembersResponse_unprocessedAccounts' - The list of Amazon Web Services accounts that could not be processed.
-- For each account, the list includes the account ID and the email
-- address.
--
-- 'httpStatus', 'getMembersResponse_httpStatus' - The response's http status code.
newGetMembersResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetMembersResponse
newGetMembersResponse :: Int -> GetMembersResponse
newGetMembersResponse Int
pHttpStatus_ =
  GetMembersResponse' :: Maybe [Member] -> Maybe [Result] -> Int -> GetMembersResponse
GetMembersResponse'
    { $sel:members:GetMembersResponse' :: Maybe [Member]
members = Maybe [Member]
forall a. Maybe a
Prelude.Nothing,
      $sel:unprocessedAccounts:GetMembersResponse' :: Maybe [Result]
unprocessedAccounts = Maybe [Result]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetMembersResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The list of details about the Security Hub member accounts.
getMembersResponse_members :: Lens.Lens' GetMembersResponse (Prelude.Maybe [Member])
getMembersResponse_members :: (Maybe [Member] -> f (Maybe [Member]))
-> GetMembersResponse -> f GetMembersResponse
getMembersResponse_members = (GetMembersResponse -> Maybe [Member])
-> (GetMembersResponse -> Maybe [Member] -> GetMembersResponse)
-> Lens
     GetMembersResponse
     GetMembersResponse
     (Maybe [Member])
     (Maybe [Member])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetMembersResponse' {Maybe [Member]
members :: Maybe [Member]
$sel:members:GetMembersResponse' :: GetMembersResponse -> Maybe [Member]
members} -> Maybe [Member]
members) (\s :: GetMembersResponse
s@GetMembersResponse' {} Maybe [Member]
a -> GetMembersResponse
s {$sel:members:GetMembersResponse' :: Maybe [Member]
members = Maybe [Member]
a} :: GetMembersResponse) ((Maybe [Member] -> f (Maybe [Member]))
 -> GetMembersResponse -> f GetMembersResponse)
-> ((Maybe [Member] -> f (Maybe [Member]))
    -> Maybe [Member] -> f (Maybe [Member]))
-> (Maybe [Member] -> f (Maybe [Member]))
-> GetMembersResponse
-> f GetMembersResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Member] [Member] [Member] [Member]
-> Iso
     (Maybe [Member]) (Maybe [Member]) (Maybe [Member]) (Maybe [Member])
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 [Member] [Member] [Member] [Member]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The list of Amazon Web Services accounts that could not be processed.
-- For each account, the list includes the account ID and the email
-- address.
getMembersResponse_unprocessedAccounts :: Lens.Lens' GetMembersResponse (Prelude.Maybe [Result])
getMembersResponse_unprocessedAccounts :: (Maybe [Result] -> f (Maybe [Result]))
-> GetMembersResponse -> f GetMembersResponse
getMembersResponse_unprocessedAccounts = (GetMembersResponse -> Maybe [Result])
-> (GetMembersResponse -> Maybe [Result] -> GetMembersResponse)
-> Lens
     GetMembersResponse
     GetMembersResponse
     (Maybe [Result])
     (Maybe [Result])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetMembersResponse' {Maybe [Result]
unprocessedAccounts :: Maybe [Result]
$sel:unprocessedAccounts:GetMembersResponse' :: GetMembersResponse -> Maybe [Result]
unprocessedAccounts} -> Maybe [Result]
unprocessedAccounts) (\s :: GetMembersResponse
s@GetMembersResponse' {} Maybe [Result]
a -> GetMembersResponse
s {$sel:unprocessedAccounts:GetMembersResponse' :: Maybe [Result]
unprocessedAccounts = Maybe [Result]
a} :: GetMembersResponse) ((Maybe [Result] -> f (Maybe [Result]))
 -> GetMembersResponse -> f GetMembersResponse)
-> ((Maybe [Result] -> f (Maybe [Result]))
    -> Maybe [Result] -> f (Maybe [Result]))
-> (Maybe [Result] -> f (Maybe [Result]))
-> GetMembersResponse
-> f GetMembersResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Result] [Result] [Result] [Result]
-> Iso
     (Maybe [Result]) (Maybe [Result]) (Maybe [Result]) (Maybe [Result])
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 [Result] [Result] [Result] [Result]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.NFData GetMembersResponse