{-# 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.SSM.DescribeSessions -- Copyright : (c) 2013-2023 Brendan Hay -- License : Mozilla Public License, v. 2.0. -- Maintainer : Brendan Hay -- Stability : auto-generated -- Portability : non-portable (GHC extensions) -- -- Retrieves a list of all active sessions (both connected and -- disconnected) or terminated sessions from the past 30 days. -- -- This operation returns paginated results. module Amazonka.SSM.DescribeSessions ( -- * Creating a Request DescribeSessions (..), newDescribeSessions, -- * Request Lenses describeSessions_filters, describeSessions_maxResults, describeSessions_nextToken, describeSessions_state, -- * Destructuring the Response DescribeSessionsResponse (..), newDescribeSessionsResponse, -- * Response Lenses describeSessionsResponse_nextToken, describeSessionsResponse_sessions, describeSessionsResponse_httpStatus, ) where import qualified Amazonka.Core as Core import qualified Amazonka.Core.Lens.Internal as Lens import qualified Amazonka.Data as Data import qualified Amazonka.Prelude as Prelude import qualified Amazonka.Request as Request import qualified Amazonka.Response as Response import Amazonka.SSM.Types -- | /See:/ 'newDescribeSessions' smart constructor. data DescribeSessions = DescribeSessions' { -- | One or more filters to limit the type of sessions returned by the -- request. filters :: Prelude.Maybe (Prelude.NonEmpty SessionFilter), -- | The maximum number of items to return for this call. The call also -- returns a token that you can specify in a subsequent call to get the -- next set of results. maxResults :: Prelude.Maybe Prelude.Natural, -- | The token for the next set of items to return. (You received this token -- from a previous call.) nextToken :: Prelude.Maybe Prelude.Text, -- | The session status to retrieve a list of sessions for. For example, -- \"Active\". state :: SessionState } deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic) -- | -- Create a value of 'DescribeSessions' with all optional fields omitted. -- -- Use or to modify other optional fields. -- -- The following record fields are available, with the corresponding lenses provided -- for backwards compatibility: -- -- 'filters', 'describeSessions_filters' - One or more filters to limit the type of sessions returned by the -- request. -- -- 'maxResults', 'describeSessions_maxResults' - The maximum number of items to return for this call. The call also -- returns a token that you can specify in a subsequent call to get the -- next set of results. -- -- 'nextToken', 'describeSessions_nextToken' - The token for the next set of items to return. (You received this token -- from a previous call.) -- -- 'state', 'describeSessions_state' - The session status to retrieve a list of sessions for. For example, -- \"Active\". newDescribeSessions :: -- | 'state' SessionState -> DescribeSessions newDescribeSessions pState_ = DescribeSessions' { filters = Prelude.Nothing, maxResults = Prelude.Nothing, nextToken = Prelude.Nothing, state = pState_ } -- | One or more filters to limit the type of sessions returned by the -- request. describeSessions_filters :: Lens.Lens' DescribeSessions (Prelude.Maybe (Prelude.NonEmpty SessionFilter)) describeSessions_filters = Lens.lens (\DescribeSessions' {filters} -> filters) (\s@DescribeSessions' {} a -> s {filters = a} :: DescribeSessions) Prelude.. Lens.mapping Lens.coerced -- | The maximum number of items to return for this call. The call also -- returns a token that you can specify in a subsequent call to get the -- next set of results. describeSessions_maxResults :: Lens.Lens' DescribeSessions (Prelude.Maybe Prelude.Natural) describeSessions_maxResults = Lens.lens (\DescribeSessions' {maxResults} -> maxResults) (\s@DescribeSessions' {} a -> s {maxResults = a} :: DescribeSessions) -- | The token for the next set of items to return. (You received this token -- from a previous call.) describeSessions_nextToken :: Lens.Lens' DescribeSessions (Prelude.Maybe Prelude.Text) describeSessions_nextToken = Lens.lens (\DescribeSessions' {nextToken} -> nextToken) (\s@DescribeSessions' {} a -> s {nextToken = a} :: DescribeSessions) -- | The session status to retrieve a list of sessions for. For example, -- \"Active\". describeSessions_state :: Lens.Lens' DescribeSessions SessionState describeSessions_state = Lens.lens (\DescribeSessions' {state} -> state) (\s@DescribeSessions' {} a -> s {state = a} :: DescribeSessions) instance Core.AWSPager DescribeSessions where page rq rs | Core.stop ( rs Lens.^? describeSessionsResponse_nextToken Prelude.. Lens._Just ) = Prelude.Nothing | Core.stop ( rs Lens.^? describeSessionsResponse_sessions Prelude.. Lens._Just ) = Prelude.Nothing | Prelude.otherwise = Prelude.Just Prelude.$ rq Prelude.& describeSessions_nextToken Lens..~ rs Lens.^? describeSessionsResponse_nextToken Prelude.. Lens._Just instance Core.AWSRequest DescribeSessions where type AWSResponse DescribeSessions = DescribeSessionsResponse request overrides = Request.postJSON (overrides defaultService) response = Response.receiveJSON ( \s h x -> DescribeSessionsResponse' Prelude.<$> (x Data..?> "NextToken") Prelude.<*> (x Data..?> "Sessions" Core..!@ Prelude.mempty) Prelude.<*> (Prelude.pure (Prelude.fromEnum s)) ) instance Prelude.Hashable DescribeSessions where hashWithSalt _salt DescribeSessions' {..} = _salt `Prelude.hashWithSalt` filters `Prelude.hashWithSalt` maxResults `Prelude.hashWithSalt` nextToken `Prelude.hashWithSalt` state instance Prelude.NFData DescribeSessions where rnf DescribeSessions' {..} = Prelude.rnf filters `Prelude.seq` Prelude.rnf maxResults `Prelude.seq` Prelude.rnf nextToken `Prelude.seq` Prelude.rnf state instance Data.ToHeaders DescribeSessions where toHeaders = Prelude.const ( Prelude.mconcat [ "X-Amz-Target" Data.=# ("AmazonSSM.DescribeSessions" :: Prelude.ByteString), "Content-Type" Data.=# ( "application/x-amz-json-1.1" :: Prelude.ByteString ) ] ) instance Data.ToJSON DescribeSessions where toJSON DescribeSessions' {..} = Data.object ( Prelude.catMaybes [ ("Filters" Data..=) Prelude.<$> filters, ("MaxResults" Data..=) Prelude.<$> maxResults, ("NextToken" Data..=) Prelude.<$> nextToken, Prelude.Just ("State" Data..= state) ] ) instance Data.ToPath DescribeSessions where toPath = Prelude.const "/" instance Data.ToQuery DescribeSessions where toQuery = Prelude.const Prelude.mempty -- | /See:/ 'newDescribeSessionsResponse' smart constructor. data DescribeSessionsResponse = DescribeSessionsResponse' { -- | The token for the next set of items to return. (You received this token -- from a previous call.) nextToken :: Prelude.Maybe Prelude.Text, -- | A list of sessions meeting the request parameters. sessions :: Prelude.Maybe [Session], -- | The response's http status code. httpStatus :: Prelude.Int } deriving (Prelude.Eq, Prelude.Read, Prelude.Show, Prelude.Generic) -- | -- Create a value of 'DescribeSessionsResponse' with all optional fields omitted. -- -- Use or to modify other optional fields. -- -- The following record fields are available, with the corresponding lenses provided -- for backwards compatibility: -- -- 'nextToken', 'describeSessionsResponse_nextToken' - The token for the next set of items to return. (You received this token -- from a previous call.) -- -- 'sessions', 'describeSessionsResponse_sessions' - A list of sessions meeting the request parameters. -- -- 'httpStatus', 'describeSessionsResponse_httpStatus' - The response's http status code. newDescribeSessionsResponse :: -- | 'httpStatus' Prelude.Int -> DescribeSessionsResponse newDescribeSessionsResponse pHttpStatus_ = DescribeSessionsResponse' { nextToken = Prelude.Nothing, sessions = Prelude.Nothing, httpStatus = pHttpStatus_ } -- | The token for the next set of items to return. (You received this token -- from a previous call.) describeSessionsResponse_nextToken :: Lens.Lens' DescribeSessionsResponse (Prelude.Maybe Prelude.Text) describeSessionsResponse_nextToken = Lens.lens (\DescribeSessionsResponse' {nextToken} -> nextToken) (\s@DescribeSessionsResponse' {} a -> s {nextToken = a} :: DescribeSessionsResponse) -- | A list of sessions meeting the request parameters. describeSessionsResponse_sessions :: Lens.Lens' DescribeSessionsResponse (Prelude.Maybe [Session]) describeSessionsResponse_sessions = Lens.lens (\DescribeSessionsResponse' {sessions} -> sessions) (\s@DescribeSessionsResponse' {} a -> s {sessions = a} :: DescribeSessionsResponse) Prelude.. Lens.mapping Lens.coerced -- | The response's http status code. describeSessionsResponse_httpStatus :: Lens.Lens' DescribeSessionsResponse Prelude.Int describeSessionsResponse_httpStatus = Lens.lens (\DescribeSessionsResponse' {httpStatus} -> httpStatus) (\s@DescribeSessionsResponse' {} a -> s {httpStatus = a} :: DescribeSessionsResponse) instance Prelude.NFData DescribeSessionsResponse where rnf DescribeSessionsResponse' {..} = Prelude.rnf nextToken `Prelude.seq` Prelude.rnf sessions `Prelude.seq` Prelude.rnf httpStatus